Socat

13 Jun 2022, 12:29 p.m.
01:16 minutes

In today's article, we will look at Socat. Socat is a network utility similar to Netcat. Socat supports IPv6 and SSL and is available for both Windows and Linux. The first thing you will notice with this tool is that it has a different syntax than what you are used to with Netcat or other standard Unix tools.

    Socat

    socat [options] <address> <address>
    

    You have to provide both addresses for it to work, each address will be made up like this

    protocol:ip:port
    

    Examples showing the same functionality as Netcat

    nc localhost 80
    socat - TCP4:localhost:80 
    OR 
    socat STDIN TCP4:localhost:80
    
    nc -lp localhost 700
    socat TCP4-LISTEN:700 STDOUT
    
    nc -lp localhost 700 -e /bin/bash
    socat TCP4-LISTEN:700 EXEC:/bin/bash
    

    We can go beyond Netcat with some SSL examples, but first, we need to generate an SSL cert for the server. Generate an SSL cert

    openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.key
    

    SSL server

    socat OPENSSL-LISTEN:443,cert=/cert.pem -
    

    SSL client

    socat - OPENSSL:localhost:443
    

    Both addresses don’t have to use the same protocol, so you can do ssl server -> non-ssl server. You should also check out the options that you can apply, for example you can use fork to tell socat to listen and handle multiple clients.

    socat TCP4-LISTEN:5000,fork OPENSSL:localhost:443
    

    Finally if you are tunnelling a connection between servers using socat you can use the -v option to print all the traffic to stdout.

    Captcha: What's the standard TCP port of the following service?

    captcha

    0 comments