@@ -857,7 +857,47 @@ into lsass, the dll must export SpLsaModeInitialize.
857
857
858
858
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Lsa - Name ' Security Packages' - Value $SecurityPackages
859
859
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
+ }
861
901
}
862
902
863
903
function Get-SecurityPackages
0 commit comments