Thebul500/netsentry

GitHub: Thebul500/netsentry

一款纯 Python 编写的网络安全扫描器,将端口扫描、服务指纹识别、TLS 证书监控与变更检测整合在一起,提供持久化历史记录和持续监控告警能力。

Stars: 0 | Forks: 0

# NetSentry [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/7a842e24ad035729.svg)](https://github.com/Thebul500/netsentry/actions) [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://python.org) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Coverage: 91%](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)]() 具备端口扫描、服务指纹识别和 TLS 证书监控功能的网络安全扫描器。 将端口扫描、服务识别和证书检查整合到一个工具中,并提供持久化历史记录和变更检测功能。纯 Python 编写,零原生依赖,无需 root 权限。 ## 快速开始 ``` # 安装 pip install -e . # 扫描主机 netsentry scan 10.0.2.1 # 使用 TLS 证书扫描子网,保存结果 netsentry scan 10.0.2.0/24 --certs --save --diff # 检查证书 netsentry certs 10.0.2.0/24 # 带告警的持续监控 netsentry watch 10.0.2.0/24 -i 3600 --webhook https://hooks.example.com/alert ``` ## 安装 ``` pip install -e . ``` ## 使用方法 ### 扫描主机或网络 ``` # 扫描单个主机 netsentry scan 10.0.2.1 # 扫描子网 netsentry scan 10.0.2.0/24 # 扫描特定端口 netsentry scan 10.0.2.1 -p 22,80,443,8080-8090 # 包含 TLS 证书检查 netsentry scan 10.0.2.0/24 --certs # 保存结果并与上次扫描进行比较 netsentry scan 10.0.2.0/24 --save --diff # 输出为 JSON 或 CSV netsentry scan 10.0.2.0/24 -f json netsentry scan 10.0.2.0/24 -f csv ``` ### 检查 TLS 证书 ``` # 检查网络上的证书 netsentry certs 10.0.2.0/24 # 自定义端口和告警阈值 netsentry certs example.com -p 8443 -w 60 # 用于自动化的 JSON 输出 netsentry certs 10.0.2.0/24 -f json ``` 退出码:0 = 一切正常,1 = 警告(即将过期),2 = 证书已过期。 ### 查看扫描历史 ``` netsentry history netsentry history --target 10.0.2.0/24 netsentry show 42 # Show details of scan #42 ``` ### 检测变更 ``` # 比较目标的两次最近扫描 netsentry diff 10.0.2.0/24 # 与特定扫描进行比较 netsentry diff 10.0.2.0/24 --since-id 15 ``` ### 持续监控 ``` # 每小时监控,通过 webhook 告警 netsentry watch 10.0.2.0/24 -i 3600 --webhook https://hooks.example.com/alert # 使用 Signal 告警进行监控 export SIGNAL_API_URL=http://127.0.0.1:8082 export SIGNAL_SENDER="+1234567890" export SIGNAL_RECIPIENT="+0987654321" netsentry watch 10.0.2.0/24 --signal ``` ### 维护 ``` netsentry prune --keep 50 # Keep 50 most recent scans per target ``` ### REST API NetSentry 包含一个可选的 REST API,用于仪表板集成和远程扫描。 ``` # 安装服务器依赖 pip install -e ".[server]" # 启动 API 服务器 export NETSENTRY_API_KEY="your-secret-key" netsentry serve --host 127.0.0.1 --port 8390 ``` 所有 `/api/` 端点都需要通过 `NETSENTRY_API_KEY` 环境变量进行 Bearer token 认证。 | Method | Endpoint | Auth | Description | |--------|----------|------|-------------| | GET | `/health` | No | 健康检查 | | POST | `/api/scan` | Yes | 开始扫描(在后台运行) | | GET | `/api/scan/{scan_id}` | Yes | 获取后台扫描状态/结果 | | GET | `/api/scans` | Yes | 列出扫描历史 | | GET | `/api/scans/{scan_id}` | Yes | 获取已保存的扫描详情 | | POST | `/api/certs` | Yes | 检查 TLS 证书 | | GET | `/api/diff/{target}` | Yes | 对比目标的最后 2 次扫描 | | DELETE | `/api/scans/prune?keep=N` | Yes | 清理旧的扫描记录 | 使用 curl 的示例: ``` # 健康检查(无身份验证) curl http://localhost:8390/health # 开始扫描 curl -X POST http://localhost:8390/api/scan \ -H "Authorization: Bearer $NETSENTRY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"target": "10.0.2.0/24", "ports": "22,80,443", "certs": true}' # 列出扫描历史 curl http://localhost:8390/api/scans?limit=10 \ -H "Authorization: Bearer $NETSENTRY_API_KEY" # 检查证书 curl -X POST http://localhost:8390/api/certs \ -H "Authorization: Bearer $NETSENTRY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"target": "example.com", "warn_days": 30}' # 比较最近扫描 curl http://localhost:8390/api/diff/10.0.2.0%2F24 \ -H "Authorization: Bearer $NETSENTRY_API_KEY" ``` ## 功能特性 - **端口扫描** — 异步 TCP 连接扫描,支持自定义并发数 - **服务指纹识别** — 抓取 Banner 并匹配 20 多种服务模式 - **TLS 证书** — 扫描、过期检查,通过 `cryptography` 库支持自签名证书 - **变更检测** — 对比扫描结果间的差异:新增/消失的主机、打开/关闭的端口、证书轮换 - **持久化历史** — 启用 WAL 模式的 SQLite,可查询过去的扫描记录 - **多种输出格式** — table、JSON、CSV - **持续监控** — 监视模式,支持 webhook 和 Signal 告警 - **REST API** — FastAPI 服务器,使用 Bearer token 认证,支持后台扫描,提供 `/docs` 下的 OpenAPI 文档 - **零原生依赖** — 纯 Python + cryptography(pip 安装即可,不需要 libpcap) ## 配置 数据存储在 `~/.netsentry/` 中。可通过 `NETSENTRY_DATA` 环境变量覆盖路径。 Signal 告警需要配置:`SIGNAL_API_URL`、`SIGNAL_SENDER`、`SIGNAL_RECIPIENT`。 ## 许可证 MIT
标签:Linux安全, Python, Scrypt密钥派生, TLS证书监控, Webhook告警, 二进制发布, 企业安全, 信息技术, 变更检测, 合规监控, 子网扫描, 密码管理, 开源工具, 持续监控, 插件系统, 数字取证, 数据统计, 无后门, 服务指纹识别, 端口扫描, 网络安全, 网络扫描器, 网络测绘, 网络资产管理, 自动化脚本, 计算机取证, 证书过期检测, 逆向工具, 隐私保护, 零依赖