divesh-kumar-9209/packet-sniffer

GitHub: divesh-kumar-9209/packet-sniffer

基于 Python 与 Scapy 的实时数据包嗅探和入侵检测工具,通过自定义规则引擎检测端口扫描与流量异常并生成风险报告。

Stars: 1 | Forks: 0

# 🛡️ 数据包嗅探器与入侵检测系统 一个基于 Python 的实时网络监控与入侵检测工具,能够捕获实时流量,检测可疑活动,并使用自定义的基于规则的异常检测生成警报。 ![Python](https://img.shields.io/badge/Python-3.8+-blue?style=flat-square&logo=python) ![Scapy](https://img.shields.io/badge/Scapy-2.5+-green?style=flat-square) ![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux-lightgrey?style=flat-square) ## 功能 - 使用 Scapy 进行实时数据包嗅探 - 端口扫描与流量泛洪检测 - 基于严重程度的风险评分系统 - 实时终端仪表盘 - 使用 Colorama 输出彩色警报 - 解析可疑 IP 的主机名 - 生成 JSON 报告 - 可配置的阈值与安全 IP - 支持 BPF 过滤器 ## 使用技术 Python • Scapy • Socket 编程 • 数据包分析 • Colorama • JSON 报告 • BPF 过滤器 ## 工作原理 ``` Live Traffic ↓ Packet Capture (Scapy) ↓ Packet Parsing & Statistics ↓ Anomaly Detection Engine ↓ Risk Scoring ↓ Dashboard + Alerts + JSON Report ``` ## 项目结构 ``` packet-sniffer/ │ ├── core/ ├── detection/ ├── utils/ ├── config.json ├── main.py ├── dashboard.py ├── report.py └── requirements.txt ``` ## 安装说明 ``` git clone https://github.com/divesh-kumar-9209/packet-sniffer.git cd packet-sniffer pip install -r requirements.txt ``` ### Windows 以管理员身份运行终端。 ### Linux 使用以下命令运行: ``` sudo python main.py ``` ## 使用方法 ### 列出网络接口 ``` python main.py --list ``` ### 开始嗅探 ``` python main.py -i 0 python main.py -i 0 -f tcp python main.py -i 0 -f "tcp and port 443" ``` ### 停止捕获 ``` Press CTRL + C to generate report.json ``` ## 示例输出 ``` [21:24:50] TCP | 142.250.82.252 (googleusercontent.com) -> 192.168.0.100 | Ports 443 -> 49909 | Size: 914 bytes === LIVE TRAFFIC DASHBOARD === TCP: 487 UDP: 32 ICMP: 5 [HIGH ALERT] Port scan detected from 10.0.0.5 | Risk Score: 85/100 [MEDIUM ALERT] High traffic detected from 10.0.0.9 | Risk Score: 62/100 ``` ## 配置 ``` { "threshold": 100, "port_scan_threshold": 10, "time_window": 10, "cooldown": 15, "safe_ips": ["142.250.82.252"] } ``` ## 检测逻辑 - 基于唯一目标端口的端口扫描检测 - 使用数据包阈值的流量泛洪检测 - 针对突然流量激增的突发异常检测 - 具有 LOW / MEDIUM / HIGH 严重程度的风险评分系统 - 冷却系统以减少重复警报 ## BPF 过滤器示例 ``` tcp udp port 80 port 443 tcp and port 22 host 192.168.1.1 ``` ## 局限性 - 基于阈值的检测可能会产生误报 - 无深度数据包检测 - 专为受控和教育环境设计 - Windows 需要 Npcap 才能进行数据包捕获 ## 计划改进 - 机器学习异常检测 - GeoIP 集成 - Flask Web 仪表盘 - 离线 PCAP 分析 - 电子邮件/webhook 警报 ## 测试环境 - Windows 10 和 11(使用 Npcap) - scanme.nmap.org ## 作者 **Divesh Kumar** 计算机科学与工程 (CSE) 本科生 | 网络安全爱好者 GitHub: https://github.com/divesh-kumar-9209/packet-sniffer ## 免责声明 本项目仅供教育和合乎道德的网络安全研究目的使用。
标签:GitHub搜索工具, Homebrew安装, Python, Scapy, 入侵检测系统, 安全数据湖, 插件系统, 无后门, 网络安全, 网络流量分析, 逆向工具, 配置错误, 隐私保护