weirdmachine64/SharkMCP
GitHub: weirdmachine64/SharkMCP
一个基于 MCP 协议的服务器,将 Wireshark 的 sharkd 接口封装为 LLM 可调用的工具集,支持用自然语言对 PCAP 文件进行深度流量分析。
Stars: 12 | Forks: 0
# SharkMCP
一个将 [sharkd](https://wiki.wireshark.org/Development/sharkd)(Wireshark 的可编程接口)作为一组 LLM 工具公开的 [MCP](https://modelcontextprotocol.io) 服务器。加载 PCAP/PCAPNG 文件并使用自然语言对其进行分析。
## 环境要求
- Python 3.10+
- Wireshark(提供 `sharkd`)
## 安装
```
git clone https://github.com/weirdmachine64/sharkmcp.git
cd sharkmcp
pip install -e .
```
或者,直接从仓库运行而无需安装:
```
uvx --from git+https://github.com/weirdmachine64/sharkmcp sharkmcp
```
## 配置
添加到您的 `.mcp.json`:
```
{
"mcpServers": {
"sharkmcp": {
"command": "uvx",
"args": ["--from", "git+https://github.com/weirdmachine64/sharkmcp", "sharkmcp"],
"env": {
"SHARKMCP_TIMEOUT": "300"
}
}
}
}
```
| 环境变量 | 默认值 | 说明 |
|---------|---------|-------------|
| `SHARKMCP_SHARKD_BIN` | `sharkd` | sharkd 二进制文件的路径 |
| `SHARKMCP_TIMEOUT` | `300` | 每次请求的超时时间(以秒为单位) |
## 工具
每个已加载的 PCAP 都会获得一个专用的 sharkd 子进程。开销较大的扫描(会话、专家信息、导出对象)的结果会被缓存在内存中,因此无需重新扫描即可处理分页的后续调用。
### 会话
| 工具 | 说明 |
|------|-------------|
| `load_pcap(path, alias?)` | 加载 PCAP/PCAPNG 文件 |
| `list_pcaps()` | 列出所有已加载的 PCAP |
| `unload_pcap(alias)` | 终止会话并释放内存 |
### 概览
| 工具 | 说明 |
|------|-------------|
| `pcap_summary(alias)` | 数据帧数、持续时间、文件大小、检测到的协议 |
| `server_info(alias)` | 所有可用的 tap 类型、追踪协议、字段类型 |
### 数据包检查
| 工具 | 说明 |
|------|-------------|
| `list_packets(alias, filter?, columns?, refs?)` | 带有显示过滤器的分页数据帧列表 |
| `packet_detail(alias, frame, include_bytes?, include_hidden?)` | 单个数据帧的完整协议树 |
| `extract_fields(alias, fields, filter?)` | 将每个数据包的任意字段提取为表格 |
### 实用工具
| 工具 | 说明 |
|------|-------------|
| `validate(alias, filter?, field?)` | 验证显示过滤器和/或字段名 |
| `complete(alias, field?, pref?)` | 根据前缀自动补全字段或首选项名称 |
| `get_preference(alias, preference?)` | 读取解析器首选项 |
| `set_preference(alias, name, value)` | 为此会话设置解析器首选项 |
| `set_frame_comment(alias, frame, comment)` | 为数据帧添加注释(作用域为当前会话) |
### 流量结构
| 工具 | 说明 |
|------|-------------|
| `protocol_hierarchy(alias, filter?)` | 带有数据帧/字节数的嵌套协议树 |
| `io_stats(alias, interval_ms?, filter?)` | 每个时间间隔的数据帧和字节数 |
| `iograph(alias, graphs, interval_ms?, filters?)` | 多线流量图;支持 `packets`、`bytes`、`bits`、`sum:`、`avg:`、`min:`、`max:`、`load:`、`frames:` |
| `follow_stream(alias, protocol, filter)` | 重组流(`tcp`、`udp`、`tls`、`http`、`http2`、`quic`、`sip`、`dccp`、`websocket`) |
### 会话与拓扑
| 工具 | 说明 |
|------|-------------|
| `conversations(alias, type?, sort_by?)` | 会话表 — 每对通信端的字节数/数据帧数 |
| `endpoints(alias, type?, sort_by?)` | 端点表 — 每个主机的发送/接收量 |
两者均支持的层类型:`tcp`、`udp`、`ip`、`ipv6`、`eth`、`sctp`、`dccp`、`mptcp`、`wifi`、`bluetooth`、`zigbee`、`fc`、`fddi`、`usb` 等。
### 协议统计
| 工具 | 说明 |
|------|-------------|
| `expert_info(alias, filter?)` | 每个数据帧的异常检测 — 错误、警告、注释、聊天 |
| `protocol_stats(alias, protocol)` | `dns`、`http`、`http_requests`、`http_server`、`sip`、`dhcp`、`h225`、`http2`、`rtsp` 的聚合统计 |
| `service_response_time(alias, protocol)` | `smb`、`smb2`、`snmp`、`ldap`、`diameter`、`rpc`、`gtp` 等的请求/响应延迟 |
| `response_time_delay(alias, protocol)` | `radius`、`h225_ras`、`megaco`、`mgcp` 的往返延迟 |
| `sequence_diagram(alias, type?)` | `tcp`、`icmp`、`icmpv6`、`any` 的流图数据 |
### 媒体与 VoIP
| 工具 | 说明 |
|------|-------------|
| `voip_calls(alias, filter?)` | 带有状态和参与者的 SIP/H.323 呼叫列表 |
| `rtp_streams(alias, stream_spec?)` | RTP 流清单;传入 `stream_spec` 以获取每个流的抖动/丢包信息 |
| `multicast_streams(alias, filter?)` | UDP 多播流统计信息 |
### 导出与对象
| 工具 | 说明 |
|------|-------------|
| `export_objects(alias, type?)` | 列出可提取的对象(`http`、`imf`、`smb`、`tftp`、`dicom`、`ftp-data`) |
| `download_object(alias, token)` | 下载对象、TLS 会话密钥(`ssl-secrets`)或 RTP 音频(`rtp:`)为 base64 格式 |
### 逃生舱
| 工具 | 说明 |
|------|-------------|
| `tap(alias, specs, filter?, skip?, limit?)` | 直接运行任何 sharkd tap — 在一次 PCAP 扫描中最多支持 16 个规范。使用 `server_info` 来发现有效的标识符。 |
## 示例
```
> load_pcap("/captures/traffic.pcap", alias="traffic")
> protocol_hierarchy("traffic")
> expert_info("traffic", limit=20)
> conversations("traffic", type="tcp", sort_by="bytes")
> extract_fields("traffic", ["dns.qry.name", "dns.a"], filter="dns")
> follow_stream("traffic", "http", "tcp.stream eq 0")
> export_objects("traffic", type="http")
> download_object("traffic", "eo:http_0")
```
## 架构
```
LLM
│ MCP (stdio)
▼
SharkMCP server
│ JSON-RPC 2.0 (stdin/stdout)
├─ sharkd [pcap-1]
├─ sharkd [pcap-2]
└─ sharkd [pcap-N]
```
每个已加载的 PCAP 对应一个 `sharkd` 子进程。会话是隔离的——在不同别名上的并发查询绝不会互相阻塞。
标签:AI安全分析, LLM集成, MCP协议, MCP服务器, PB级数据处理, PCAPNG, PCAP分析, Python, Sharkd接口, Wireshark, 句柄查看, 大语言模型工具, 安全分析平台, 安全运维, 数据包解析, 无后门, 网络协议分析, 网络安全, 网络通信分析, 逆向工具, 隐私保护