fox-it/pcap-broker
GitHub: fox-it/pcap-broker
一个用Go语言编写的PCAP-over-IP服务器,能够将捕获的网络流量实时分发给多个客户端,主要用于低延迟场景下的网络流量分析与安全监控。
Stars: 45 | Forks: 7
# pcap-broker
`pcap-broker` 是一个用于捕获网络流量并通过 PCAP-over-IP 将其提供给一个或多个客户端的工具。
在低延迟是首要考虑因素的情况下,例如在 Attack and Defend CTF 期间,PCAP-over-IP 会非常有用。
可以在以下链接找到有关 PCAP-over-IP 的更多信息:
* https://www.netresec.com/?page=Blog&month=2022-08&post=What-is-PCAP-over-IP
`pcap-broker` 支持以下功能:
* 将数据包数据分发给一个或多个 PCAP-over-IP 客户端
* 执行捕获流量的命令,通常是 `tcpdump`(期望标准输出为 pcap 数据)
* 如果捕获命令退出,`pcap-broker` 也会随之退出
## 构建
构建 `pcap-broker` 需要 `libpcap` 开发头文件,在 Debian 上你可以使用以下命令进行安装:
```
$ apt install libpcap-dev
```
要从源代码构建,请克隆此代码仓库并运行:
```
$ go build .
$ ./pcap-broker --help
```
或者,你可以构建 Docker 容器:
```
$ docker build -t pcap-broker .
$ docker run -it pcap-broker --help
```
或者,直接使用 `go` 进行安装:
```
$ go install github.com/fox-it/pcap-broker@latest
$ pcap-broker --help
```
## 运行
```
$ ./pcap-broker --help
Usage of ./pcap-broker:
-cmd string
command to execute for pcap data (eg: tcpdump -i eth0 -n --immediate-mode -s 65535 -U -w -)
-debug
enable debug logging
-json
enable json logging
-listen string
listen address for pcap-over-ip (eg: localhost:4242)
-n disable reverse lookup of connecting PCAP-over-IP client IP address
```
可以通过命令行传递参数:
```
$ ./pcap-broker -cmd "sudo tcpdump -i eth0 -n --immediate-mode -s 65535 -U -w -"
```
或者通过环境变量传递:
```
LISTEN_ADDRESS=:4242 PCAP_COMMAND='sudo tcpdump -i eth0 -n --immediate-mode -s 65535 -U -w -' ./pcap-broker
```
在 Docker 环境中使用 `pcap-broker` 时,使用环境变量会非常方便。
现在你可以通过 TCP 连接到它,并使用 `nc` 和 `tcpdump` 流式传输 PCAP 数据:
```
$ nc -v localhost 4242 | tcpdump -nr -
```
或者使用原生支持 PCAP-over-IP 的工具,例如 `tshark`:
```
$ tshark -i TCP@localhost:4242
```
# 通过 SSH 获取 PCAP 数据
一个应用场景是通过 SSH 从远程机器获取 PCAP 数据,并通过 PCAP-over-IP 将其提供出来。
这种用例(包括用于引导此操作的 SSH 示例命令)已在 `docker-compose.yml.example` 文件中进行了说明:
```
services:
pcap-broker-remote-host:
image: pcap-broker:latest
container_name: pcap-broker-remote-host
restart: always
volumes:
# Mount the private key into container that wil be used for SSH
# Ensure that on the `remote-host` the public key is in the /root/.ssh/authorized_keys file.
- ~/.ssh/id_ed25519:/root/.ssh/id_ed25519:ro
environment:
# Command that will be executed by pcap-broker to read PCAP data.
# Which is to SSH into `remote-host` and run tcpdump on eth0 and write PCAP data to stdout.
# The `not port 22` BPF is necessary to avoid any traffic loops as the PCAP data is transferred over SSH.
PCAP_COMMAND: |-
ssh root@remote-host -oStrictHostKeyChecking=no
tcpdump -U --immediate-mode -ni eth0 -s 65535 -w - not port 22
# Bind on 0.0.0.0 port 4242. From within the same Docker network you can reach it using the `container_name`
# For example in another Docker service you can reach this pcap-broker using `pcap-broker-remote-host:4242`
LISTEN_ADDRESS: "0.0.0.0:4242"
ports:
# This is optional, but makes the PCAP-over-IP port also available locally on the Docker host on port 4200.
# Handy for debugging, for example: `nc -v localhost 4200 | tcpdump -nr -`
- 127.0.0.1:4200:4242
```
## 背景
该工具最初是为 Attack & Defend CTF 目的而编写的,但在其他需要低延迟或需要简单实用的 PCAP-over-IP 服务器的场景中也非常有用。在 Fox-IT 参与的 CTF 中,`pcap-broker` 允许蓝队捕获一次网络数据,并将其分发给其他原生支持 PCAP-over-IP 的工具,例如:
* [Arkime](https://arkime.com/) ([文档](https://arkime.com/settings#reader-poi))
* [Tulip](https://github.com/OpenAttackDefenseTools/tulip) ([#24](https://github.com/OpenAttackDefenseTools/tulip/pull/24))
* [Shovel](https://github.com/FCSC-FR/shovel)
* [Pkappa2](https://github.com/spq/pkappa2)
* WireShark 的 [dumpcap](https://www.wireshark.org/docs/man-pages/dumpcap.html) 和 [tshark](https://www.wireshark.org/docs/man-pages/tshark.html) (`-i TCP@:`)
* Zeek 的 [zeek-pcapovertcp-plugin](https://github.com/emnahum/zeek-pcapovertcp-plugin)
标签:Docker, EVTX分析, Golang, PCAP-over-IP, TCP流, TGT, 二进制发布, 低延迟, 安全编程, 安全防御评估, 开源工具, 抓包代理, 抓包工具, 攻防演练, 日志审计, 服务器, 服务管理, 流量转发, 网络安全, 网络数据分发, 请求拦截, 防御绕过, 隐私保护