neatlabs-ai/packet-capture-2.0

GitHub: neatlabs-ai/packet-capture-2.0

一款零依赖的单文件网络取证分析器,支持离线 pcap 与实时捕获,提供深度检测、MITRE 映射与交互式报告。

Stars: 11 | Forks: 8

NEATLABS™ Packet Capture Analyzer

Version Python 3.8+ Zero Dependencies License Lines of Code Protocols

企业级PCAP取证分析工具,支持实时捕获、深度数据包检查、威胁情报和MITRE ATT&CK映射。
纯Python实现 — 零外部依赖。

## 概述 **NEATLABS™ Packet Capture Analyzer** 是一款单文件、企业级网络取证工具,能够在数据包捕获(pcap/pcapng)文件或直接从网络接口执行深度数据包检查、行为威胁检测和自动IOC提取。它以单个Python文件分发,**零必需依赖**(完全使用标准库),并可选择性利用 `scapy` 增强跨平台实时捕获能力。 专为网络安全专业人士、SOC分析师、事件响应人员设计,适用于无需安装完整Wireshark/Zeek堆栈即可快速分类网络流量。 ### 核心差异化 - **单文件、零依赖** — 仅需Python 3.8+即可运行 - **实时捕获 + 离线分析** — 可直接嗅探网卡或分析pcap/pcapng文件 - **真实威胁检测** — 不仅是协议解析;基于统计模型的行为分析 - **MITRE ATT&CK 映射** — 每个发现均映射到具体技术ID - **JA3/JA3S 指纹识别** — 内置恶意软件哈希数据库 - **Wireshark风格显示过滤器** — 布尔逻辑、CIDR匹配、字段比较、协议快捷方式 - **隧道解封装** — 递归解析GRE和VXLAN数据包以暴露内部流量 - **专业报告** — 深色主题交互式HTML,含内嵌图表 ## 快速启动 ``` # 启动图形界面 python3 packet_capture_analyzer.py # 分析 pcap 文件(命令行) python3 packet_capture_analyzer.py capture.pcap # 生成并分析示例捕获 python3 packet_capture_analyzer.py --demo # 从网络接口实时捕获(需要 root 权限) sudo python3 packet_capture_analyzer.py --live eth0 # 列出可用接口 python3 packet_capture_analyzer.py --live-list ``` 无需 `pip install`。直接运行即可。 ## 功能 ### 协议解析(30+ 协议) | 层 | 协议 | |-------|-----------| | **链路层** | Ethernet、VLAN (802.1Q/QinQ)、MPLS、LLDP | | **网络层** | IPv4、IPv6(扩展头)、ARP、ICMP、ICMPv6、IGMP | | **传输层** | TCP(完整状态机)、UDP、SCTP、ESP、AH | | **隧道层** | GRE(递归内层解封装)、VXLAN(完整解封装与VNI)、MPLS | | **应用层** | DNS、HTTP、TLS/SSL、SSH、SMTP、FTP、MySQL、RDP、SMB、DHCP、NTP、SNMP、SIP | ### 威胁检测引擎 分析器超越简单协议解析,采用行为分析与统计模型检测: | 威胁 | 检测方法 | MITRE ATT&CK | |--------|-----------------|---------------| | **端口扫描** | 纵向(多端口 → 单主机)与横向(单端口 → 多主机) | T1046 | | **C2 信道** | 基于系数变异(CV < 0.15 = 高置信度)的统计抖动分析 | T1071 | | **DGA 域名** | 9信号评分:熵、韵母比、数字密度、辅音连缀、双字可发音性、长度、数字字母交替、TLD信誉、一致性 | T1568.002 | | **DNS 隧道** | 子域名长度分析(>60 字符)、查询量、熵评分 | T1071.004 | | **ARP 欺骗** | 每IP多MAC检测 | T1557.002 | | **数据外泄** | 流量不对称分析(>85% 出向,>10MB 阈值) | T1048 | | **横向移动** | 内部管理端口扫描(SSH、RDP、SMB、WinRM) | T1021 | | **明文凭证** | 正则匹配密码、API密钥、Basic Auth | T1552.001 | | **暴力破解** | 认证服务连接频率分析 | T1110 | | **加密C2** | 高熵载荷检测(Shannon熵 > 7.5) | T1573 | | **Tor 流量** | 已知Tor端口检测(9001、9030、9050、9051、9150) | T1090 | | **可疑端口** | 常见恶意/后门端口(4444、1337、31337 等) | T1571 | 每个发现均分配严重等级(CRITICAL / HIGH / MEDIUM / LOW / INFO)、置信度分数,并贡献加权 **威胁评分**(0–100)。 ### TLS 智能 - **JA3/JA3S 指纹识别** — 计算客户端与服务端指纹哈希 - **恶意哈希数据库** — 对标已知C2指纹(CobaltStrike、Emotet、Trickbot、QakBot、Metasploit、AsyncRAT、Dridex、BitRAT、IcedID、Tofsee) - **SNI 提取** — Client Hello 中的服务器名称指示 - **版本追踪** — 标记已弃用的 SSL 3.0、TLS 1.0、TLS 1.1 - **密码套件分析** — 识别弱或异常选择 ### 实时数据包捕获 通过三种自动检测的后端直接从网卡捕获: | 后端 | 平台 | 要求 | |---------|----------|-------------| | **scapy** | 跨平台 | `pip install scapy` | | **原始套接字** | Linux | Root 或 `CAP_NET_RAW` 权限 | | **tcpdump** | Linux/macOS | 已安装 `tcpdump` | 特性: - 自动列出网卡(含IP/MAC/速度/流量计数器) - BPF 过滤器支持(`tcp port 80`、`host 192.168.1.100`、`not port 22` 等) - 可配置数据包限制与持续时间 - 混杂模式开关 - 实时数据包日志与协议解析 - 捕获后一键全量威胁分析 - 保存为标准PCAP格式 ### 流分析 - 完整 **TCP 状态机** 跟踪(SYN → ESTABLISHED → FIN/RST → CLOSED) - 双向流归一化 - 重传与乱序检测 - 每流载荷 **熵采样** 用于识别加密流量 - 统计:包数、字节数、持续时间、吞吐量(bps/pps)、不对称比 ### IOC 提取 自动提取妥协指标: - 外部IP(非RFC1918) - 域名(DNS查询 + TLS SNI) - URL(从HTTP重建) - 用户代理 - JA3 指纹哈希 ### IP 增强 对每个观察IP内置分类: - **RFC1918** 私有范围 - **云服务商**:AWS、Azure、GCP、Cloudflare、DigitalOcean(主要CIDR块) - 环回、组播、链路本地、伪地址检测 ## 安装 ### 最小(零依赖) ``` # 只需复制文件。仅此而已。 curl -O https://raw.githubusercontent.com/YOUR_REPO/packet_capture_analyzer.py python3 packet_capture_analyzer.py ``` ### 推荐(用于实时捕获) ``` pip install scapy # Cross-platform live capture pip install psutil # Enhanced interface detection ``` ### 实时捕获权限 ``` # 选项 A:以 root 身份运行 sudo python3 packet_capture_analyzer.py --live eth0 # 选项 B:设置权限(持久化,无需 sudo) sudo setcap cap_net_raw+ep $(which python3) python3 packet_capture_analyzer.py --live eth0 # 选项 C:Windows — 以管理员身份运行(已安装 Npcap) ``` ## 用法 ### GUI 模式 ``` # 启动图形界面(未提供参数时默认) python3 packet_capture_analyzer.py ``` GUI 提供 8 个标签页: | 标签页 | 内容 | |-----|----------| | **Overview** | 捕获摘要、协议分布条、严重等级分布 | | **Live Capture** | 接口选择、BPF 过滤器、实时数据包日志、启动/停止/分析 | | **Packets** | Wireshark风格数据包表(显示过滤器栏:布尔逻辑、CIDR、字段比较),点击检查并导出十六进制转储 | | **Flows** | 双向流表(含熵、持续时间、字节计数) | | **⚠ Threats** | 颜色标记的威胁评分、异常表与MITRE映射 | | **DNS** | 查询统计、顶级域名、DGA嫌疑 | | **TLS / JA3** | 握手计数、JA3哈希、SNI列表、恶意匹配 | | **Raw JSON** | 完整分析结果作为JSON | ### CLI 模式 ``` # 使用 HTML 报告进行基本分析 python3 packet_capture_analyzer.py capture.pcap # 自定义报告路径 python3 packet_capture_analyzer.py capture.pcap -r my_report.html # 将 JSON 输出到标准输出 python3 packet_capture_analyzer.py capture.pcap --json # CSV 导出 python3 packet_capture_analyzer.py capture.pcap --csv ./output/ # STIX 2.1 IOC 导出 python3 packet_capture_analyzer.py capture.pcap --stix iocs.json # 生成示例捕获并分析 python3 packet_capture_analyzer.py --demo ``` ### 实时捕获(CLI) ``` # 列出接口 python3 packet_capture_analyzer.py --live-list # 捕获 60 秒 sudo python3 packet_capture_analyzer.py --live eth0 --live-duration 60 # 使用 BPF 过滤器捕获 10,000 个数据包 sudo python3 packet_capture_analyzer.py --live eth0 --live-count 10000 --live-filter "tcp port 443" # 将捕获保存到指定路径 sudo python3 packet_capture_analyzer.py --live eth0 --live-output /tmp/capture.pcap # 组合选项 sudo python3 packet_capture_analyzer.py --live wlan0 \ --live-duration 120 \ --live-count 50000 \ --live-filter "not port 22" \ --live-output investigation.pcap \ -r investigation_report.html ``` ### BPF 过滤器示例 ``` tcp port 80 # HTTP traffic tcp port 443 # HTTPS traffic host 192.168.1.100 # Specific host net 10.0.0.0/8 # Subnet udp port 53 # DNS not port 22 # Exclude SSH src host 10.0.0.5 # Source only dst port 3389 # RDP destination icmp # Ping traffic tcp and port 80 # Combined ``` ### 显示过滤器(Wireshark风格) 数据包表支持完整的Wireshark风格表达式引擎,包含布尔逻辑、字段比较、CIDR匹配与协议快捷方式: ``` tcp # Protocol match udp or icmp # Boolean OR ip.src == 192.168.1.100 # Source IP ip.dst == 8.8.8.8 # Destination IP ip.src == 10.0.0.0/8 # CIDR subnet match tcp.dstport == 443 # Destination port tcp.port == 80 # Either src or dst port tcp.flags.syn == 1 # SYN packets frame.len >= 1000 # Packet length dns.qname contains google # DNS query substring tls.sni contains github # TLS SNI match http.host contains example # HTTP host header not arp # Negation tcp and ip.dst == 8.8.8.8 # Boolean AND (tcp or udp) and not dns # Parenthesized logic eth.addr == aa:bb:cc:dd:ee:ff # MAC address ``` 支持字段:`ip.src`、`ip.dst`、`ip.addr`、`ip.ttl`、`ip.proto`、`tcp.port`、`tcp.srcport`、`tcp.dstport`、`tcp.flags.*`、`tcp.seq`、`tcp.ack`、`tcp.window`、`udp.port`、`udp.srcport`、`udp.dstport`、`frame.len`、`frame.number`、`eth.src`、`eth.dst`、`eth.addr`、`dns.qname`、`http.host`、`http.method`、`http.uri`、`tls.sni`、`data.len` 比较操作符:`==`、`!=`、`>`、`<`、`>=`、`<=`、`contains` ## CLI 参考 ``` usage: neatlabs-pcap-analyzer [-h] [-r REPORT] [--json] [--csv CSV] [--stix STIX] [--demo] [--live IFACE] [--live-list] [--live-duration N] [--live-count N] [--live-filter BPF] [--live-output PATH] [--version] [file] positional arguments: file Path to PCAP/PCAPNG file options: -r, --report PATH Output HTML report path --json JSON output to stdout --csv DIR CSV export directory (packets, anomalies, flows, DNS) --stix PATH STIX 2.1 IOC export path --demo Generate and analyze demo PCAP --live IFACE Live capture from interface (e.g. eth0) --live-list List available network interfaces --live-duration N Capture duration in seconds (default: 30) --live-count N Max packets to capture (0=unlimited) --live-filter BPF BPF filter expression --live-output PATH Save live capture PCAP to path --version Show version ``` ## 输出格式 ### HTML 报告 深色主题交互式报告,包含: - 带颜色编码严重等级的风险评分环 - 协议分布图表 - 可折叠的异常、流、TLS、DNS、HTTP、IOC 章节 - 响应式设计 - 内嵌 — 单一自包含HTML文件,零外部依赖 ### CSV 导出 三个文件: - `packets.csv` — 完整数据包表 - `anomalies.csv` — 所有检测到的威胁 - `flows.csv` — 双向流记录 - `dns.csv` — DNS查询日志 ### PCAP 导出 导出完整捕获或过滤子集为标准PCAP格式。GUI中应用显示过滤器后点击“PCAP导出”仅保存匹配包;代码中: ``` from packet_capture_analyzer import PcapWriter, DisplayFilter # 写入所有数据包 PcapWriter.write(packets, "output.pcap") # 写入过滤后的子集 PcapWriter.write_filtered(packets, "syn_only.pcap", "tcp.flags.syn == 1") ``` ### JSON 输出 通过 `--json` 输出完整结构化结果,适用于SIEM/SOAR平台或进一步脚本处理。 ### STIX 2.1 IOC以STIX 2.1捆绑格式导出,用于威胁情报共享。 ## 架构 ``` packet_capture_analyzer.py (5,391 lines, single file) │ ├── PcapParser # Binary PCAP/PCAPNG parser with mmap I/O │ ├── PCAP (LE/BE, µs/ns) │ ├── PCAPNG (SHB, IDB, EPB) │ └── Gzip transparent decompression │ ├── ProtocolDissector # Multi-layer protocol dissection │ ├── Link: Ethernet, VLAN, MPLS, LLDP │ ├── Network: IPv4, IPv6, ARP, ICMP │ ├── Transport: TCP, UDP, SCTP, ESP │ ├── Tunnel: GRE (recursive decap), VXLAN (full decap w/ VNI) │ └── Application: DNS, HTTP, TLS, SSH, SMTP, FTP, etc. │ ├── DisplayFilter # Wireshark-style expression engine │ ├── Recursive descent parser (AND/OR/NOT/parentheses) │ ├── Field comparisons (==, !=, >, <, >=, <=, contains) │ ├── CIDR matching (ip.src == 10.0.0.0/8) │ ├── Protocol shortcuts (tcp, udp, dns, arp, etc.) │ └── TCP flag inspection (tcp.flags.syn == 1) │ ├── PcapWriter # PCAP file output │ ├── Standard LE µs format writer │ └── Filtered export (write_filtered with display filter) │ ├── ThreatEngine # Behavioral threat detection │ ├── Port scan detection (vertical + horizontal) │ ├── C2 beaconing (coefficient of variation) │ ├── DGA scoring (9-signal: entropy, vowels, bigrams, concordance) │ ├── DNS tunneling detection │ ├── ARP spoof detection │ ├── Credential exposure │ ├── Brute force detection │ └── MITRE ATT&CK mapping │ ├── TLSAnalyzer # TLS/SSL intelligence │ ├── JA3/JA3S fingerprinting │ ├── Malware hash database (10 families) │ ├── SNI extraction │ └── Version/cipher analysis │ ├── FlowAnalyzer # Bidirectional flow tracking │ ├── TCP state machine │ ├── Retransmission detection │ └── Payload entropy sampling │ ├── LiveCapture # Real-time packet capture │ ├── scapy backend │ ├── Linux raw socket backend │ ├── tcpdump backend │ └── Interface auto-detection │ ├── DemoPcapGenerator # Realistic demo traffic generator │ └── 10+ scenarios (HTTP, TLS, scans, C2, DGA, etc.) │ ├── HTMLReportGenerator # Interactive HTML report builder ├── CSVExporter # Tabular export (packets, anomalies, flows, DNS) ├── STIXExporter # STIX 2.1 IOC bundle export │ └── GUI (tkinter) # Desktop application ├── 8 tabs with high-contrast dark theme ├── Live capture controls with BPF filters ├── Wireshark-style display filter bar ├── PCAP export (full or filtered subset) ├── Real-time packet log └── Threat score visualization ``` ## 支持的文件格式 | 格式 | 读 | 写 | |--------|------|-------| | PCAP(小端,µs) | ✅ | ✅(完整 + 过滤导出) | | PCAP(大端) | ✅ | — | | PCAP(纳秒) | ✅ | — | | PCAPNG | ✅ | — | | Gzip压缩(.pcap.gz) | ✅ | — | | 实时捕获 | ✅ | ✅ | 支持链路类型:Ethernet (1)、Raw IP (101)、Linux SLL (113)、Linux SLL2 (276)、Loopback (0)。 ## 演示模式 生成并分析一个包含500+数据包的现实多场景捕获: ``` python3 packet_capture_analyzer.py --demo ``` 演示包含: - 含用户代理的HTTP浏览 - 带有SNI(google.com、github.com、reddit.com)的TLS握手 - 已弃用的SSL 3.0连接 - 纵向端口扫描(335+端口) - 通过长子域名查询的DNS隧道 - 定时C2信道 - ARP欺骗(重复MAC) - HTTP POST中的明文凭证 - SSH暴力破解尝试 - DGA域名查询 - 与Tor相关的端口流量 - 可疑后门端口(4444、31337) 预期输出:**威胁评分 100/100(严重)**,8类共12个异常,涉及8个MITRE ATT&CK技术。 ## 要求 ### 最小 - **Python 3.8+** - **零外部包** — 核心分析器、GUI及所有导出仅使用标准库 ### 可选 | 包 | 用途 | 安装 | |---------|---------|---------| | `scapy` | 跨平台实时捕获 | `pip install scapy` | | `psutil` | 增强接口检测 | `pip install psutil` | ### 平台支持 | 平台 | PCAP分析 | GUI | 实时捕获 | |----------|:------------:|:---:|:------------:| | Linux | ✅ | ✅ | ✅(原始套接字 / scapy / tcpdump) | | Windows | ✅ | ✅ | ✅(scapy + Npcap) | | macOS | ✅ | ✅ | ✅(scapy / tcpdump) | ## 安全声明 本工具仅用于**授权的网络安全分析**。捕获网络流量可能需要适当授权,并可能受司法管辖区法律限制。始终确保在捕获或分析网络流量前获得适当授权。 实时捕获需要提升权限(root/管理员),因为原始套接字访问在所有主流操作系统上均为特权操作。 ## 关于 NEATLABS™ **NEATLABS™** 是一家退伍军人拥有的小型企业(VOSB),专注于为国防承包商和联邦机构提供网络安全、合规性和情报解决方案。

使用 ◆ 构建 — NEATLABS™ — 现代威胁态势的网络安全解决方案

标签:AMSI绕过, Cloudflare, DInvoke, DNS枚举, IOC提取, MITRE ATT&CK, PCAP分析, Python 3.8, Python网络工具, SOC工具, 企业级取证, 协议分析, 单文件工具, 威胁情报, 威胁检测, 实时捕获, 开发者工具, 数字取证, 权限提升, 深度包检测, 漏洞发现, 离线分析, 网络安全, 网络安全分析, 网络安全工具, 网络流量分析, 自动化脚本, 逆向工具, 隐私保护, 零依赖工具