Posted on Leave a comment

Beginners guide to Socat

Hello, aspiring ethical hackers. In our previous blogpost, you learnt how to use netcat for various purposes in ethical hacking. In this blogpost, you will learn about another such tool named Socat.

Socat, shortcut for SOcket CAT is a command line utility that enables bidirectional data transfer between two independent data channels. Actually, it can provide multiple functions. It supports many protocols like TCP, UDP, SOCKS4 and OpenSSL.

Bind and Reverse shells

The use of socat tool comes after you completed gaining access to target network or device. Here, it helps you in maintaining access as channel for communication.

Let’s see how to create bind shells with socat (learn about different types of shells). For this, we will be using Metasploitable2 as target system in our virtual hacking lab. Note that socat should be installed on both target and attacker systems for this to work. To create a bind shell, run this command on the target system as shown below.

Socat 2

Then on the attacker system, we need to run this command.

Socat 3

Here’s our bind shell.

Socat 4

To create reverse shell, the above commands should be run on attacker and target system respectively.

Socat 5
Socat 6

Here’s our reverse shell.

Socat 7

Encrypted bind and reverse shell with socat

The above shells, although they are good, the data between them is transferred in plain text and is susceptible to sniffing and detection. No problems though. Socat can create an encrypted shell using OpenSSL.

To create an encrypted shell, first, we need to create a SSL key as shown below. Two files with extensions “.crt” and “.key” are created as shown below.

Socat 8
Socat 9

Then, we need to join this two files into one file with “.pem” file as shown below.

Socat 10
Socat 11
Socat 12

Now this file should be on the system on which we start our listener. For example, to create a bind shell, the “ssl.pem” should be on the target system. Then we need to run command as shown below.

Socat 13

Then, on attacker system we should run this command shown below.

Socat 14

Here’s the shell.

Socat 15

Similarly, we can also create a reverse shell.

Socat 16
Socat 17
Socat 18

File transfer

Socat can also be used to transfer files between two machines. For example, to transfer that SSL certificate we created above from attacker system to target system, the command to be run on the attacker system is shown below.

Socat 19

Then on the target system, we should run this command.

Socat 20
Socat 21
Socat 22

Follow Us
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.