Linux Reverse Shell Payloads and One-Liners
When you have command execution on a target: through a web vulnerability, a service exploit, a cron job injection, or any other vector: these payloads turn that execution into a shell. All examples use $LHOST and $LPORT as your attacker IP and listener port.
Start your listener before sending any payload:
After catching the shell, stabilize it before doing anything else. See Shell Stabilization and TTY Upgrade.
Reverse shells
The most reliable option when bash is the executing shell. Try /dev/tcp first: it is built into bash and leaves no extra process.
If that fails due to restricted bash or shell interpretation issues, use the read/write file descriptor form:
When the payload runs inside a context that strips special characters (HTML forms, JSON fields, XML), wrap it:
Works on nearly every modern Linux system. Python 3 first, fall back to Python 2 if needed.
Perl is present on most Linux distributions even when Python is not.
Use when you have execution through a web application context or a PHP file.
If exec is disabled, try shell_exec or system:
Works when a netcat binary with -e support is present. Many modern installs ship OpenBSD netcat which drops -e.
For OpenBSD netcat or any netcat without -e, use the mkfifo pipe method instead.
Works with any netcat variant. Reliable fallback when bash /dev/tcp and -e are both unavailable.
The pipe name /tmp/f is arbitrary. Change it if /tmp is noisy or monitored.
Produces a cleaner shell than netcat. Requires socat on the target. If it is not installed, transfer a static binary.
This gives a near-fully interactive shell without the stty raw steps needed for other methods.
Useful when the execution context only allows AWK: common in restricted command injection scenarios.
Choosing the Right Payload
Most command injection and RCE scenarios on Linux resolve with the bash /dev/tcp one-liner or the Python socket payload. Use the mkfifo method when neither works. Use socat when you want the cleanest shell and can transfer the binary.
Quick selection guide:
- Bash
/dev/tcp: best default, no dependencies, works in most shells - Python socket: reliable fallback, available on nearly every modern distro
- mkfifo + netcat: works with any netcat variant when bash and Python are unavailable
- Socat: cleanest interactive shell, requires binary on target
- Perl/Ruby/PHP/Lua: niche cases where only that interpreter is present
If the execution context URL-encodes or strips characters, encode the payload in base64 and decode it on execution:
Then execute it on the target:
This avoids issues with &, >, and / being interpreted or stripped by intermediary systems.