azemoning/senior-pcap-engineer
GitHub: azemoning/senior-pcap-engineer
spe 是一款 Kubernetes 多 Pod 自动化数据包捕获 CLI 工具,解决分布式环境下手动逐 Pod 抓包效率低、难以统一分析的问题。
Stars: 0 | Forks: 0
# spe — 资深 PCAP 工程师
为 Kubernetes 提供的自动化多 Pod 数据包捕获工具。
## 为什么叫“资深 PCAP 工程师”?
如果你曾经在 Slack 炸锅的时候,用 bash 单行命令在多个 Pod 之间循环运行 ksniff,那么这款工具就是为你准备的。
Kubernetes 生态系统几乎为所有东西都提供了认证,但从来没有人去认证那个在凌晨 3 点(当数据包开始丢失且无人知道原因时)真正去阅读 pcap 文件的人。那个人就是“资深 PCAP 工程师”。这款 CLI 工具的存在就是为了让这项工作稍微轻松一点。
它可以并行捕获来自多个 Pod 的流量,将 pcap 合并为一个统一的时间线,并可选地生成你可以直接导入 SIEM 的 JSON 流量日志。没有 DaemonSet,没有 operator,没有 sidecar。只有一个与 K8s API 通信并为你运行 tcpdump 的二进制文件。
## 安装
### 二进制版本
从 [GitHub Releases](https://github.com/azemoning/senior-pcap-engineer/releases) 下载适用于 Linux、macOS 和 Windows 的版本。
```
# Linux amd64
curl -LO https://github.com/azemoning/senior-pcap-engineer/releases/latest/download/spe-linux-amd64
chmod +x spe-linux-amd64
sudo mv spe-linux-amd64 /usr/local/bin/spe
```
### Go install
```
go install github.com/azemoning/senior-pcap-engineer@latest
```
### 容器镜像
```
docker pull ghcr.io/azemoning/senior-pcap-engineer:latest
# 在集群内运行
kubectl run spe --rm -it \
--image=ghcr.io/azemoning/senior-pcap-engineer:latest \
--restart=Never \
--overrides='{
"spec": {
"serviceAccountName": "spe",
"containers": [{
"name": "spe",
"image": "ghcr.io/azemoning/senior-pcap-engineer:latest",
"command": ["spe", "start", "--namespace", "prod", "--label", "app=api", "--duration", "2m"]
}]
}
}'
```
### 从源码构建
```
git clone https://github.com/azemoning/senior-pcap-engineer.git
cd senior-pcap-engineer
make build
```
## 使用方法
```
# 从匹配 label 的 pods 中抓包
spe start --namespace prod --label "app=api" --duration 2m
# 从匹配 glob pattern 的 pods 中抓包
spe start --namespace prod --pod "web-*" --filter "port 8080"
# 从 service 后的所有 pods 中抓包
spe start --namespace prod --service api-gateway --duration 5m
# 合并抓包结果为单个 pcap
spe start --namespace prod --label "app=payment" --mode merge --duration 10m
# 生成 JSON flow logs
spe start --namespace prod --label "app=api" --format both --duration 2m
# 上传至 S3
spe start --namespace prod --label "app=api" --duration 2m --upload s3://forensics/case-42
# 列出 sessions
spe list
# 导出 session
spe export spe-20260711-a3f2 --upload s3://forensics/
```
## 工作原理
1. 通过 label、名称模式或 service 解析目标 Pod
2. 创建临时 debug 容器(或在较旧的 K8s 版本上使用直接 exec)
3. 在所有目标上并行运行 tcpdump
4. 可选:按时间戳合并 pcap 文件
5. 可选:生成 JSON 流量日志
6. 可选:上传至 S3
## 前置要求
- Go 1.24+
- 配置好具有集群访问权限的 kubectl
- Kubernetes 1.23+(用于 ephemeral containers)
- 目标 Pod 中需包含 tcpdump(针对 K8s < 1.23 的回退方案)
标签:EVTX分析, Go, Ruby工具, 日志审计, 漏洞探索, 网络抓包, 请求拦截, 运维工具, 防御绕过