Fontailll/NetSentinel

GitHub: Fontailll/NetSentinel

NetSentinel 是一款用 C++17 编写的跨平台网络事件响应工具,通过扫描活动 TCP/UDP 连接、关联进程信息并基于安全启发式规则计算风险评分,帮助安全分析师快速发现和拦截可疑网络活动。

Stars: 1 | Forks: 0

# NetSentinel **网络事件响应工具** — 扫描活动的 TCP/UDP 连接,计算风险评分,导出为 JSON,并通过防火墙进行拦截。 跨平台(Linux + Windows),C++17。 [![构建](https://github.com/Fontailll/NetSentinel/actions/workflows/build.yml/badge.svg)](https://github.com/Fontailll/NetSentinel/actions/workflows/build.yml) [![发布](https://img.shields.io/github/v/release/Fontailll/NetSentinel)](https://github.com/Fontailll/NetSentinel/releases/latest) [![许可证](https://img.shields.io/github/license/Fontailll/NetSentinel)](LICENSE) [![平台](https://img.shields.io/badge/platform-Linux%20%7C%20Windows-blue)]() [![C++](https://img.shields.io/badge/C%2B%2B-17-informational)]() [![下载量](https://img.shields.io/github/downloads/Fontailll/NetSentinel/total)](https://github.com/Fontailll/NetSentinel/releases/latest) [![PRs](https://img.shields.io/badge/PRs-welcome-brightgreen)]() ## 快速开始(单行命令) ### Linux ``` # 自动检测发行版,下载预编译二进制文件或从源码构建 curl -sL https://raw.githubusercontent.com/Fontailll/NetSentinel/main/install.sh | sudo bash # 启用所有功能进行扫描 sudo netsentinel --all ``` ### Windows(以管理员身份运行 PowerShell) ``` # 1. 从 https://www.msys2.org 下载并安装 MSYS2 # 2. 从开始菜单打开“MSYS2 UCRT64” # 3. 更新包: pacman -Syu # 4. 安装 GCC、CMake 和 Ninja(pacman 是 MSYS2 的包管理器): pacman -S mingw-w64-ucrt-x86_64-gcc cmake ninja # 5. 构建: cd /c/Users/ereno/Desktop/netsentinel mkdir build && cd build cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release ninja # 6. 运行: ./netsentinel.exe --all ``` ## Linux 安装说明 ### 方式 1 — 自动安装(推荐) ``` curl -sL https://raw.githubusercontent.com/Fontailll/NetSentinel/main/install.sh | sudo bash sudo netsentinel --all ``` 该脚本将: 1. 尝试从 GitHub Releases 下载**完全静态的预编译二进制文件** 2. 如果失败,则检测您的发行版,安装依赖项并从源码编译 3. 安装至 `/usr/local/bin/netsentinel` ### 方式 2 — 预编译二进制文件 ``` curl -sL https://github.com/Fontailll/NetSentinel/releases/latest/download/netsentinel-linux-x86_64 -o netsentinel chmod +x netsentinel sudo ./netsentinel --all ``` 该二进制文件是**静态链接**的 —— 无需任何依赖即可在任何 Linux 发行版上运行。 ### 方式 3 — 从源码编译 ``` # 依赖项 # Debian/Ubuntu: sudo apt install build-essential cmake # Fedora: sudo dnf install gcc-c++ cmake make # Arch: sudo pacman -S gcc cmake make # Alpine: sudo apk add g++ cmake make # openSUSE: sudo zypper install gcc-c++ cmake make git clone https://github.com/Fontailll/NetSentinel.git cd NetSentinel mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) sudo ./netsentinel --all ``` ### 安装为系统服务 #### systemd(Fedora、Debian 8+、Ubuntu 16+、Arch) ``` sudo ./netsentinel --install-service systemd > /etc/systemd/system/netsentinel.service sudo systemctl daemon-reload sudo systemctl enable --now netsentinel sudo systemctl status netsentinel ``` #### runit(Void Linux、Artix) ``` sudo mkdir -p /etc/sv/netsentinel sudo ./netsentinel --install-service runit > /etc/sv/netsentinel/run sudo chmod +x /etc/sv/netsentinel/run sudo ln -s /etc/sv/netsentinel /var/service/ ``` #### OpenRC(Gentoo、Alpine) ``` sudo ./netsentinel --install-service openrc > /etc/init.d/netsentinel sudo chmod +x /etc/init.d/netsentinel sudo rc-update add netsentinel default sudo rc-service netsentinel start ``` #### 自动检测 ``` sudo ./netsentinel --install-service auto ``` ### 守护进程模式 ``` sudo ./netsentinel --watch --daemon --pidfile /run/netsentinel.pid --logfile /var/log/netsentinel.log ``` ## Windows 安装说明 ### 前置条件 安装 [MSYS2](https://www.msys2.org)(推荐使用 UCRT64 版本)。 ### 编译 打开 **MSYS2 UCRT64** 终端并运行: ``` # 首次设置(如果尚未完成) pacman -Syu # Update package database pacman -S mingw-w64-ucrt-x86_64-gcc cmake ninja # Install toolchain # 构建 cd /c/Users/ereno/Desktop/netsentinel # Use /c/ for C:\ mkdir build && cd build cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release ninja ``` ### 运行 ``` netsentinel.exe # Colored table output netsentinel.exe --all # All features (signature + detail) netsentinel.exe --json # JSON output (pipe-friendly) netsentinel.exe --export report.json netsentinel.exe --watch # Real-time monitoring ``` **注意事项:** - 需以**管理员身份**运行才能获得完整的连接可见性 - 签名验证使用 WinVerifyTrust (Authenticode) - 二进制文件为静态链接 —— 无需 MSYS2 DLL - 扫描完成后按 Enter 键退出(双击运行时会保持窗口打开状态) ## 使用方法 ``` Usage: netsentinel [OPTIONS] Options: --export Export connections to JSON file --json Print connections as JSON to stdout --detail Show detailed info for high-risk connections --verify-sig Enable digital signature verification --geoip Enable GeoIP country lookup --geoip-db Path to GeoIP CSV database (implies --geoip) --watch Real-time monitoring mode --watch-interval Watch polling interval (default: 5) --all Enable all features (--verify-sig --geoip --detail) --daemon Run as daemon (Linux, requires --watch) --pidfile PID file path (for --daemon) --logfile Log file path (for --daemon) --install-service Print service template (systemd/runit/openrc/auto) --version Show version and platform info --help, -h Show this help ``` ## 风险评分引擎 | 规则 | 分值 | 描述 | |------|-------|-------------| | 未签名的可执行文件 | +30 | 进程未签名(需要 `--verify-sig`) | | Temp 文件夹 | +25 | 从 Temp 或 AppData\Local\Temp 运行 | | 恶意软件端口 | +20 | 连接到已知的 C2/恶意软件端口 | | 未知发布者 | +15 | 已签名的二进制文件但没有发布者名称 | | 可疑进程名 | +15 | powershell、cmd、curl、wget 等 | | 隐藏进程 | +10 | PID 存在但名称为空 | | 异常监听端口 | +10 | 监听在非标准的低位端口 | | 外部连接 | +5 | 远程 IP 不在私有地址范围内(需要 `--geoip`) | **风险等级:** 低 (0-29) · 中等 (30-59) · 高 (60-79) · 严重 (80+) ## 项目结构 ``` netsentinel/ ├── include/ # Common headers (interfaces) │ ├── scanner.h IScanner interface (scan_tcp, scan_udp) │ ├── connection.h Connection struct + enums │ ├── risk.h RiskEngine (modular rules) │ ├── output.h Table, detail, help, version output │ ├── json_export.h Minimal JSON writer │ ├── firewall.h IFirewall interface │ ├── process.h ProcessInfo struct │ ├── geoip.h GeoIP lookup module │ ├── daemon.h Daemonize + service templates │ └── utils.h String helpers ├── src/ # Cross-platform implementation │ ├── main.cpp CLI parser, scan pipeline │ ├── scanner.cpp IScanner::scan() + factory │ ├── risk.cpp 8 modular risk rules │ ├── output.cpp Colored table, detail cards, help │ ├── json_export.cpp │ ├── geoip.cpp │ ├── daemon.cpp fork/setsid + systemd/runit/openrc │ ├── firewall.cpp IFirewall factory │ └── utils.cpp ├── platform/ │ ├── windows/ Win32 API (GetExtendedTcpTable, WinVerifyTrust, COM) │ └── linux/ /proc/net, iptables/nftables ├── tests/ Catch2 unit tests (21 tests) └── install.sh One-liner Linux installer ``` ## 许可证 MIT
标签:Bash脚本, C++17, HTTP头分析, Linux, Mr. Robot, WSL, 库, 应急响应, 防火墙