Leger-Gerard/professional-tcp-scanner

GitHub: Leger-Gerard/professional-tcp-scanner

基于 Python 构建的专业 TCP 端口扫描器,支持多线程并发、隐身模式、服务检测和 JSON 报告导出,适用于授权安全评估与网络诊断。

Stars: 0 | Forks: 0

# TCP 端口扫描器 一款使用 Python Typer 和 Rich 构建的专业 TCP 端口扫描器,适用于安全评估和网络诊断。 ## 功能 - 🔍 **专业 CLI**:基于 Typer 构建,提供直观的命令行界面 - 🎨 **Rich 输出**:带有进度条和表格的精美、多彩终端输出 - ⚡ **并发扫描**:支持配置线程池的多线程扫描 - 📊 **多种输出格式**:支持易读的表格和 JSON 导出,并提供灵活的文件输出 - 🔍 **增强的服务检测**:基于知名端口号识别服务 - 💾 **专业报告导出**:将 JSON 报告导出至自定义路径,并自动创建目录 - 🛡️ **专注安全**:包含输入验证、隐身模式以及完善的错误处理 - 📝 **专业日志记录**:支持不同详细程度的轮转日志 - 🧪 **完善测试**:包含覆盖率超过 80% 的全面单元测试 - 🐳 **容器就绪**:提供 Dockerfile 以便轻松部署 - 🔧 **DevOps 友好**:包含 Makefile 和 GitHub Actions CI 配置 ## 安装 ``` # Clone 仓库 git clone cd tp-cyber # 以开发模式安装 pip install -e . # 安装 development dependencies pip install -e ".[dev]" ``` ## 使用说明 ### 基础扫描 ``` # 扫描 localhost 的常见端口 port-scanner scan --host 127.0.0.1 # 扫描指定端口 port-scanner scan --host example.com --ports 80,443,8080 # 扫描端口范围 port-scanner scan --host 192.168.1.1 --ports 1-1000 ``` ### 高级选项 ``` # 调整超时和线程 port-scanner scan --host target.com --ports 80,443 --timeout 2.0 --threads 50 # 启用 JSON 输出以便与其他工具集成 port-scanner scan --host target.com --json-output --output results.json # 在 reports/ 目录中生成带有自动生成文件名的 JSON 输出 port-scanner scan --host target.com --json-output # 使用 stealth 模式进行安全评估(速度较慢,不易被检测) port-scanner scan --host target.com --stealth --threads 30 # 启用详细日志记录以进行调试 port-scanner scan --host target.com --verbose # 禁用 banner(适用于脚本编写) port-scanner scan --host target.com --no-banner ``` ### 示例 ``` # Web 端口快速扫描 port-scanner scan --host scanme.nmap.org --ports 80,443,8080,8443 # 等效于完整 TCP SYN 扫描(知名端口) port-scanner scan --host 10.0.0.1 --ports 1-1024 --timeout 1.0 # 带有 JSON 输出的综合扫描,用于后续分析 port-scanner scan --host 192.168.1.100 --ports 1-65535 --json-output --output full-scan.json --threads 200 # 用于 red team 操作的 stealth 扫描 port-scanner scan --host target.internal --stealth --threads 20 --timeout 5.0 # 带服务检测的扫描(在输出中显示服务名称) port-scanner scan --host 127.0.0.1 --ports 22,80,443,3306 ``` ## 架构 ``` src/ └── scanner/ ├── cli/ # Command-line interface (Typer + Rich) ├── core/ # Core scanning logic ├── services/ # Service detection and enrichment ├── utils/ # Utility functions ├── models/ # Data models and schemas ├── config/ # Configuration management └── reports/ # Report generation and export ``` ## 安全注意事项 - **输入验证**:严格验证所有用户输入 - **无 Shell 注入**:采用纯 Python 实现,不包含 subprocess 调用 - **错误处理**:全面的异常处理可防止信息泄露 - **速率限制**:可配置的线程数和超时可防止网络泛洪 - **日志安全**:日志经过净化并安全存储 - **DNS 安全**:针对 DNS 解析采取了妥善的超时处理 ## 开发 ### 运行测试 ``` # 运行所有测试 python -m pytest # 运行带有 coverage 的测试 python -m pytest --cov=src --cov-report=term-missing # 运行特定的 test suites python -m pytest tests/unit/ ``` ### 代码质量 ``` # 检查代码风格 ruff check src # 修复代码风格问题 ruff check --fix src # 类型检查 mypy src ``` ### 构建 ``` # 构建可分发的 package python -m build # 检查已构建的 package twine check dist/* ``` ## Docker 使用 ``` # 构建 Docker 镜像 docker build -t port-scanner . # 运行扫描 docker run --rm port-scanner scan --host 127.0.0.1 --ports 80,443 # 使用 JSON 输出扫描并保存到宿主机 docker run --rm -v $(pwd)/results:/app/results port-scanner scan \ --host example.com --json-output --output /app/results/scan.json ``` ## 限制 - **TCP Connect 扫描**:使用 TCP connect() 扫描,而非原始数据包 SYN 扫描(SYN 扫描需要 root 权限) - **不支持 UDP**:目前仅支持 TCP(计划在未来版本中支持 UDP 扫描) - **基础服务检测**:服务检测仅基于端口号 - **规避限制**:隐身模式提供基本的时序随机化,但并不等同于高级规避技术 ## 许可证 本项目基于 MIT 许可证授权 - 详情请参阅 LICENSE 文件。 ## 免责声明 本工具仅供授权的安全测试和教育目的使用。 在扫描任何网络或系统之前,用户必须获得适当的授权。 未经授权的扫描在您所在的司法管辖区可能属于违法行为。 对于因滥用本软件而造成的任何损害,作者不承担任何责任。
标签:DevSecOps, DNS查询工具, Python, 上游代理, 安全规则引擎, 插件系统, 无后门, 端口扫描器, 网络安全, 请求拦截, 逆向工具, 隐私保护