Payload Obfuscation Reference
PowerShell, .NET, VBA, JavaScript, and shellcode obfuscation techniques — each with AMSI/AV bypass notes and detection signatures for defenders.
PowerShell Obfuscation Techniques
Encode PowerShell commands in Base64 and pass via -EncodedCommand (-enc). Bypasses simple string matching on command line.
Split malicious strings across variables or concatenation to avoid signature matching, then execute with Invoke-Expression (IEX).
Use .NET reflection to call methods without using obvious PowerShell cmdlets. Avoids PowerShell-specific detection.
Compress payload, Base64-encode, and decompress in-memory at runtime. Combines two bypass layers.
Use SecureString encryption to hide string content from static analysis. Bypass Constrained Language Mode (CLM) via various techniques.
.NET / C# Obfuscation & Evasion
PE Reflective Loading
Load a .NET assembly (EXE/DLL) directly into memory from a byte array — no file on disk. Bypasses hash-based detection and file monitoring.
Process Injection — Classic CreateRemoteThread
Detection: .NET Obfuscation
Assembly.Load from byte arrays triggers ETW (Event Tracing for Windows) events. EDR hooks — NtAllocateVirtualMemory, NtWriteVirtualMemory, NtCreateThreadEx. AMSI integration for .NET 4.8+ scans assembly before load. Memory scanners (Moneta, pe-sieve) detect injected PE regions.
VBA / Office Macro Obfuscation
Chr() Array Reconstruction
WScript.Shell via COM — Shell without Shell command
VBA Stomping
Replace VBA source code in the docm file with dummy/empty code while keeping the compiled p-code (which runs) unchanged. Most analysis tools show the decoy code, not what actually executes. Detected by olevba with --deobf flag and by Cobalt Strike's VBA stomping detection tool.
Detection: Office Macros
Office spawning cmd.exe/powershell.exe (high-confidence indicator — EID 4688, Sysmon EID 1). olevba analysis of documents in email security gateway. AMSI for Office 365 — macros scanned before execution. ASR (Attack Surface Reduction) rules: Block Office applications from creating child processes. WMI event subscriptions from Office. Network connections from Office applications.
JavaScript / HTA / WSH Obfuscation
eval() with String Splitting
JScript in SCT (Scriptlets)
Detection: JS/HTA/WSH
mshta.exe, wscript.exe, cscript.exe spawning cmd.exe or powershell.exe. Network connections from script hosts. Sysmon EID 1: parent process = mshta.exe. regsvr32.exe making network connections (EID 3). AppLocker/SRP rules blocking script hosts. AMSI for JScript/VBScript (Windows 10+).
AMSI — What It Is and Bypass Techniques
AMSI (Antimalware Scan Interface) allows AV products to scan content at runtime — PowerShell scripts before execution, .NET assemblies before load, JScript/VBScript before execution. Content is passed to registered AV providers. If flagged, execution is blocked.
Memory Patch — AmsiScanBuffer
Patch the AmsiScanBuffer function in amsi.dll in the current process to always return AMSI_RESULT_CLEAN. Requires no elevated privileges — modifies memory in current process only.
AMSI Context Zeroing
AMSI Detection for Defenders
EID 4104 (Script Block Logging): look for AMSI-related strings (AmsiScanBuffer, amsi.dll, amsiInitFailed). Memory: hook monitoring will detect writes to amsi.dll text section. EDR: AMSI provider telemetry — AV products log AMSI scan calls including blocked content. PowerShell Transcription logging captures all output regardless of AMSI.