Skip to content

Commit

Permalink
Fix 'ambigous match' in Invoke-TokenManipulation; see #4
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianVollmer committed Sep 23, 2019
1 parent 5d8cd60 commit b741544
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions Exfiltration/Invoke-TokenManipulation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,26 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
$SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') }
$UnsafeNativeMethods = $SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods')
# Get a reference to the GetModuleHandle and GetProcAddress methods
$GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle')
$GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress')
# Get a handle to the module specified
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))
$tmpPtr = New-Object IntPtr
$HandleRef = New-Object System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle)

# Return the address of the function
Write-Output $GetProcAddress.Invoke($null, @([System.Runtime.InteropServices.HandleRef]$HandleRef, $Procedure))

# Get a reference to the GetModuleHandle and GetProcAddress methods
$GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle')
$GetProcAddress = $UnsafeNativeMethods.GetMethods() | Where {$_.Name -eq "GetProcAddress"} | Select-Object -first 1

# Get a handle to the module specified
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))

# 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))
}
catch
{
# Windows 10 v1803 needs $Kern32Handle as a System.IntPtr instead of System.Runtime.InteropServices.HandleRef
Write-Output $GetProcAddress.Invoke($null, @($Kern32Handle, $Procedure))
}
}

###############################
Expand Down

0 comments on commit b741544

Please sign in to comment.