ashishranjanxyz/NetSentinel

GitHub: ashishranjanxyz/NetSentinel

NetSentinel 是一款结合 Nmap 与机器学习技术的智能网络漏洞扫描器,能够自动化扫描端口、分类风险级别并检测异常主机行为。

Stars: 1 | Forks: 0

# NetSentinel — AI 驱动的网络漏洞扫描器
![Python](https://img.shields.io/badge/Python-3.9%2B-blue?style=for-the-badge&logo=python) ![Scikit-Learn](https://img.shields.io/badge/ML-scikit--learn-orange?style=for-the-badge&logo=scikitlearn) ![Nmap](https://img.shields.io/badge/Scanner-Nmap-green?style=for-the-badge) ![License](https://img.shields.io/badge/License-MIT-purple?style=for-the-badge) **一款智能网络漏洞扫描器,结合 Nmap 与机器学习来检测风险、分类威胁级别并识别异常主机行为。**
## 什么是 NetSentinel? NetSentinel 是一款超越传统端口扫描的 **pentesting tool**。它使用 **AI/ML models** 来: - **扫描** 开放端口并枚举服务(通过 Nmap) - **分类** 风险级别(LOW / MEDIUM / HIGH),使用 **Random Forest classifier** - **检测异常** 端口配置文件,使用 **Isolation Forest**(无监督 ML) - **生成** 精美的 HTML + JSON 漏洞报告 - **显示** 丰富的、带颜色编码的终端输出 ## AI/ML 架构 | 组件 | 算法 | 用途 | |-----------|-----------|---------| | **Risk Classifier** | Random Forest (100 trees) | 分类主机风险:LOW / MEDIUM / HIGH | | **Anomaly Detector** | Isolation Forest | 标记与正常基线相比的异常端口组合 | | **Feature Engineering** | Custom | 从扫描数据中提取 6 个特征 | ### Feature Vector ``` [num_open_ports, has_critical_ports, has_db_ports, has_remote_access, has_legacy_services, risk_score] ``` ### 为什么选择 Isolation Forest? 传统扫描器仅查找已知的恶意端口。NetSentinel 更进一步——它学习 **normal server profile** 的样子,并标记任何统计上异常的内容,即使单个端口看起来正常。 ## 快速开始 ### 前置条件 - Python 3.9+ - 系统上已安装 **Nmap** - Linux: `sudo apt install nmap` - Mac: `brew install nmap` - Windows: [nmap.org/download](https://nmap.org/download.html) ### 安装 ``` git clone https://github.com/yourusername/NetSentinel.git cd NetSentinel pip install -r requirements.txt ``` ### 使用方法 ``` # 基本扫描 (端口 1-1024) sudo python main.py --target 192.168.1.1 # 全端口扫描 sudo python main.py --target 192.168.1.1 --ports 1-65535 # 激进扫描 (OS + 版本检测) sudo python main.py --target 192.168.1.0/24 --type aggressive # 自定义输出目录 sudo python main.py --target scanme.nmap.org --output results/ ``` ## 示例输出 ### 终端 (Rich CLI) ``` NetSentinel v1.0 ✓ Random Forest (100 estimators) loaded ✓ Isolation Forest loaded ✓ Trained on 21 samples Scanning 192.168.1.1 (ports 1-1024)... ─────────────── 192.168.1.1 · router.local ─────────────── Risk Level: HIGH | AI Confidence: 87.5% | OS: Linux 4.x Port Service Version Risk Reason ────────────────────────────────────────────────────── 22/tcp ssh OpenSSH 8.2 MEDIUM Brute force target 23/tcp telnet — CRITICAL Plaintext protocol 3306/tcp mysql MySQL 5.7 HIGH Direct DB exposure AI Analysis: • Found 3 open port(s) with a total risk score of 9. • Critical services detected (Telnet) • Database ports are publicly exposed. • Legacy/insecure protocols detected (Telnet). ``` ### HTML 报告 将在您的输出目录中生成一个样式化的、暗色主题的 HTML 报告,其中包含: - 带有风险徽章的完整主机摘要 - 按端口划分的风险细分表 - AI 分析说明 - 顶级威胁列表 - 异常检测状态 ## 项目结构 ``` NetSentinel/ ├── main.py # CLI entry point ├── requirements.txt ├── scanner/ │ └── scanner.py # Nmap wrapper + feature extraction ├── ml/ │ └── model.py # Random Forest + Isolation Forest ├── report/ │ └── report.py # HTML & JSON report generator └── README.md ``` ## 配置 | 标志 | 默认值 | 描述 | |------|---------|-------------| | `--target` | 必需 | IP、主机名或 CIDR | | `--ports` | `1-1024` | 要扫描的端口范围 | | `--type` | `basic` | `basic` 或 `aggressive` | | `--output` | `output/` | 报告输出目录 | ## 🔬 扩展 NetSentinel ### 添加自定义风险规则 在 `scanner/scanner.py` 中编辑 `KNOWN_RISKY_PORTS`: ``` 8888: {"service": "Jupyter", "risk": "CRITICAL", "reason": "Unauthenticated RCE via notebooks"}, ``` ### 重新训练 ML 模型 将样本添加到 `ml/model.py` 中的 `TRAINING_DATA` 和 `TRAINING_LABELS` —— 模型会在每次运行时重新训练。 ### 添加更多特征 扩展 `scanner.py` 中的 `get_feature_vector()` 并更新 `model.py` 中的 `FEATURE_NAMES`。 ## 法律免责声明 ## 许可证 MIT License — 详见 [LICENSE](LICENSE)。
标签:Apex, CISA项目, CTI, GitHub, Nmap, Python, Scikit-learn, 人工智能, 威胁分类, 孤立森林, 安全报告, 密码管理, 异常检测, 插件系统, 攻击路径可视化, 数据展示, 数据统计, 无后门, 无监督学习, 机器学习, 特征工程, 用户模式Hook绕过, 端口扫描, 端口枚举, 红队, 网络安全, 网络安全扫描器, 虚拟驱动器, 逆向工具, 随机森林, 隐私保护, 黑客工具