Skip to content

Commit ca8fec3

Browse files
committed
fix ambigous match in Invoke-TokenManipulation; see #4
1 parent bf09d23 commit ca8fec3

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

Exfiltration/Invoke-TokenManipulation.ps1

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,30 @@ Blog on this script: http://clymb3r.wordpress.com/2013/11/03/powershell-and-toke
284284
$Procedure
285285
)
286286

287-
# Get a reference to System.dll in the GAC
288-
$SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() |
289-
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') }
290-
$UnsafeNativeMethods = $SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods')
291-
# Get a reference to the GetModuleHandle and GetProcAddress methods
292-
$GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle')
293-
$GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress')
294-
# Get a handle to the module specified
295-
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))
296-
$tmpPtr = New-Object IntPtr
297-
$HandleRef = New-Object System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle)
298-
299-
# Return the address of the function
300-
Write-Output $GetProcAddress.Invoke($null, @([System.Runtime.InteropServices.HandleRef]$HandleRef, $Procedure))
287+
# Get a reference to System.dll in the GAC
288+
$SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() |
289+
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') }
290+
$UnsafeNativeMethods = $SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods')
291+
292+
# Get a reference to the GetModuleHandle and GetProcAddress methods
293+
$GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle')
294+
$GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress', [Type[]]@([System.Runtime.InteropServices.HandleRef], [String]))
295+
296+
# Get a handle to the module specified
297+
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))
298+
299+
# Return the address of the function
300+
try
301+
{
302+
$tmpPtr = New-Object IntPtr
303+
$HandleRef = New-Object System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle)
304+
Write-Output $GetProcAddress.Invoke($null, @([System.Runtime.InteropServices.HandleRef]$HandleRef, $Procedure))
305+
}
306+
catch
307+
{
308+
# Windows 10 v1803 needs $Kern32Handle as a System.IntPtr instead of System.Runtime.InteropServices.HandleRef
309+
Write-Output $GetProcAddress.Invoke($null, @($Kern32Handle, $Procedure))
310+
}
301311
}
302312

303313
###############################

0 commit comments

Comments
 (0)