Add support for Windows 10 v1803 to Invoke-ReflectivePEInjection
This commit is contained in:
parent
be932ce2be
commit
c722f89a29
|
|
@ -997,17 +997,27 @@ $RemoteScriptBlock = {
|
||||||
$SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() |
|
$SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() |
|
||||||
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') }
|
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') }
|
||||||
$UnsafeNativeMethods = $SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods')
|
$UnsafeNativeMethods = $SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods')
|
||||||
|
|
||||||
# Get a reference to the GetModuleHandle and GetProcAddress methods
|
# Get a reference to the GetModuleHandle and GetProcAddress methods
|
||||||
$GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle')
|
$GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle')
|
||||||
$GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress')
|
$GetProcAddress = $UnsafeNativeMethods.GetMethods() | Where {$_.Name -eq "GetProcAddress"} | Select-Object -first 1
|
||||||
|
|
||||||
# Get a handle to the module specified
|
# Get a handle to the module specified
|
||||||
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))
|
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))
|
||||||
$tmpPtr = New-Object IntPtr
|
|
||||||
$HandleRef = New-Object System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle)
|
|
||||||
|
|
||||||
# Return the address of the function
|
# Return the address of the function
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$tmpPtr = New-Object IntPtr
|
||||||
|
$HandleRef = New-Object System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle)
|
||||||
Write-Output $GetProcAddress.Invoke($null, @([System.Runtime.InteropServices.HandleRef]$HandleRef, $Procedure))
|
Write-Output $GetProcAddress.Invoke($null, @([System.Runtime.InteropServices.HandleRef]$HandleRef, $Procedure))
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
# Windows 10 v1803 needs $Kern32Handle as a System.IntPtr instead of System.Runtime.InteropServices.HandleRef
|
||||||
|
Write-Output $GetProcAddress.Invoke($null, @($Kern32Handle, $Procedure))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Function Enable-SeDebugPrivilege
|
Function Enable-SeDebugPrivilege
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue