sabkari-mohamed/IntelliScan

GitHub: sabkari-mohamed/IntelliScan

结合传统特征检测与随机森林机器学习分类的 Web 漏洞扫描器,用于自动化检测 SQL 注入、XSS 和 LFI 等常见安全漏洞。

Stars: 1 | Forks: 0

# IntelliScan [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![CI](https://img.shields.io/badge/CI-passing-brightgreen.svg)]() [![ML](https://img.shields.io/badge/ML-Random%20Forest-orange.svg)]() [![OWASP](https://img.shields.io/badge/OWASP-Top%2010-red.svg)]() ## 概述 **IntelliScan** 是一款先进的 Web 应用程序漏洞扫描器,它将传统的基于特征的检测与机器学习分类器(Random Forest)相结合,以检测和验证安全漏洞。这是在盖尼特拉伊本·托法伊勒大学 (Ibn Tofail University) 攻读网络安全与 AI 硕士学位的最终学年项目的成果。 与单纯依赖静态特征的典型扫描器不同,IntelliScan 从 HTTP 响应中提取 11 个特征,并使用训练好的 Random Forest 模型对漏洞利用进行分类,在 DVWA 测试环境中实现了 100% 的 F1-Score。 ### 核心优势 - **混合检测**:基于特征 + ML 分类(深度防御) - **变异引擎**:使用 6 种技术从 24 个基础 payload 中生成 135 个以上的 payload 变体 - **模块化管道**:6 个独立的模块通过 JSON 文件连接 - **专业报告**:包含图表、证据和修复建议的 PDF 报告 - **Web 仪表板**:基于 Flask 的 UI,面向非 CLI 用户 - **并发扫描**:使用 ThreadPoolExecutor 实现 4-8 倍的加速 - **Docker 就绪**:完整的 docker-compose 堆栈及目标靶机 ## 架构 ``` +------------+ +------------+ +-------------+ +-----------+ | Crawler | --> | Injector | --> | Analyzer | --> | ML Class.| +------------+ +------------+ +-------------+ +-----------+ | | | | v v v v results.json injection_results labeled_results model.pkl | v +------------------+ | Payload Gen | | (6 mutations) | +------------------+ | v +------------------+ | Report Gen | | (PDF + Web) | +------------------+ ``` ### 6 个模块 | # | 模块 | 职责 | 输出 | |---|--------|------|--------| | 1 | **Crawler** | BFS 探索,处理 CSRF,表单/URL 发现 | `results.json` | | 2 | **Injector** | GET/POST payload 注入,响应捕获 | `injection_results.json` | | 3 | **Analyzer** | 基于特征的漏洞检测 | `labeled_results.json` | | 4 | **ML Classifier** | 包含 11 个特征的 Random Forest | `model.pkl` | | 5 | **Payload Generator** | 6 种变异技术,135 个以上的变体 | `all_payloads.json` | | 6 | **Report Generator** | 专业的 PDF + JSON 报告 | `report.pdf` | ## 功能特性 ### 核心检测能力 - **SQL 注入 (SQLi)**:基于报错、基于联合查询、布尔盲注、基于时间延迟 - **跨站脚本攻击 (XSS)**:反射型、存储型、基于 DOM 的检测 - **本地文件包含 (LFI)**:路径遍历、编码绕过、封装协议 - **可扩展**:基于插件的架构,用于添加新的漏洞类型 ### 机器学习分类器 - 算法:**Random Forest**(100 棵树,平衡的类别权重) - 特征:从 HTTP 响应中提取的 11 个数值特征 - 训练:80/20 数据集划分 + 5 折交叉验证 - **性能**:在 DVWA 测试集上达到 100% F1-Score,交叉验证平均值为 1.00 ± 0.00 - 最重要的特征:`response_len` (55%)、`vuln_type` (33.5%)、`payload_len` (11.6%) ### Payload 变异引擎 六种变异技术可生成绕过 WAF 的变体: 1. **大小写变异**:`OR` -> `oR`、`Or`、`OR` 2. **SQL 注释插入**:`OR 1=1` -> `OR/**/1=1` 3. **引号替换**:针对某些 DBMS 将 `'` 替换为 `"` 4. **URL 编码**:`'` -> `%27`,`<` -> `%3C` 5. **双重 URL 编码**:`'` -> `%2527` 6. **空白字符变异**:空格 -> 制表符 / 多个空格 结果:**33 个基础 payload -> 208 个生成的变体(+530% 覆盖率)** ### 报告 - 专业的 **PDF 报告**,包含封面页、执行摘要、漏洞详情和修复建议 - **Web 仪表板**,带有交互式图表(Flask + Chart.js) - **JSON 导出**,用于 CI/CD 集成 - 扫描期间的**彩色终端**输出 - **Discord webhook** 通知(可选) ## 快速开始 ### 安装 ``` # Clone repo git clone https://github.com/sabkari-mohamed/intelliscan.git cd intelliscan # 安装依赖 pip install -r requirements.txt # 可选:拉取 DVWA 测试目标 docker run -d -p 8080:80 --name dvwa vulnerables/web-dvwa ``` ### 基本用法 ``` # 对 DVWA 进行完整扫描 python -m intelliscan scan --target http://localhost:8080 \ --auth admin:password \ --report report.pdf # 仅 Discovery python -m intelliscan crawl --target http://localhost:8080 # 在您自己的数据集上训练 ML classifier python -m intelliscan train --dataset labeled_results.json # 生成 mutated payloads python -m intelliscan generate-payloads --base payloads/base.txt ``` ### Web 仪表板 ``` python -m intelliscan.web.app # 打开 http://localhost:5000 ``` ### Docker Compose(完整堆栈) ``` docker-compose up # IntelliScan UI: http://localhost:5000 # DVWA 目标: http://localhost:8080 ``` ## 性能基准测试 在 Docker 中运行的 DVWA(安全级别:低)上进行了测试: | 模块 | 指标 | 值 | |---|---|---| | Crawler | 发现的页面数 | 33 | | Crawler | 发现的表单数 | 16 | | Injector | 总注入次数 | 40 | | Analyzer | SQLi 检测率 | 10/10 (100%) | | Analyzer | XSS 检测率 | 20/20 (100%) | | Analyzer | LFI 检测率 | 1/10 (10%)* | | ML Classifier | 准确率 | 100% | | ML Classifier | F1-Score | 100% | | ML Classifier | CV (5-fold) | 1.00 ± 0.00 | | Payload Gen | 生成的变体数 | +111 | *LFI 的成功率受到 Docker 中 PHP 的 `realpath()` 保护机制的限制;在生产环境风格的配置中,该比率要高得多。 ## 与其他扫描器的对比 | 特性 | IntelliScan | VulnScan | SQLMap | OWASP ZAP | |---|:---:|:---:|:---:|:---:| | SQLi | 是 (100%) | 是 (基础) | 是 (黄金标准) | 是 (~85%) | | XSS | 是 (100%) | 是 (基础) | 否 | 是 (~80%) | | LFI | 是 | 是 | 否 | 部分 | | **Machine Learning** | **是 (RF)** | 否 | 否 | 否 | | **Payload mutation** | **是 (6 种技术)** | 否 | 部分 | 否 | | **PDF reports** | **是** | 否 | 否 | 是 | | **Web dashboard** | **是 (Flask)** | 否 | 否 | 是 | | **Modular pipeline** | **是 (6 个模块)** | 否 | 否 | 否 | | **Concurrent scan** | 是 | 否 | 是 | 是 | | **Docker support** | 是 | 否 | 否 | 是 | ## 项目结构 ``` intelliscan/ ├── intelliscan/ │ ├── __init__.py │ ├── __main__.py # CLI entry point │ ├── core.py # Pipeline orchestrator │ ├── config.py # Settings and constants │ ├── modules/ │ │ ├── crawler.py # Module 1: BFS + CSRF │ │ ├── injector.py # Module 2: payload injection │ │ ├── analyzer.py # Module 3: signature detection │ │ ├── classifier.py # Module 4: Random Forest ML │ │ ├── payload_gen.py # Module 5: 6 mutation techniques │ │ └── reporter.py # Module 6: PDF generation │ ├── web/ │ │ ├── app.py # Flask web dashboard │ │ ├── templates/ # Jinja2 templates │ │ └── static/ # CSS, JS, images │ └── utils/ │ ├── http_client.py # Session, retries, rate limiting │ └── notifier.py # Discord webhook ├── tests/ │ ├── test_crawler.py │ ├── test_injector.py │ ├── test_analyzer.py │ ├── test_classifier.py │ └── test_payload_gen.py ├── payloads/ │ ├── sqli.txt │ ├── xss.txt │ └── lfi.txt ├── docs/ │ ├── ARCHITECTURE.md │ └── images/ ├── examples/ │ ├── dvwa_scan.py │ └── custom_target.py ├── requirements.txt ├── setup.py ├── Dockerfile ├── docker-compose.yml ├── README.md └── LICENSE ``` ## 工作原理 ### 1. 爬取阶段 Crawler 对目标进行身份验证(处理 CSRF token),然后对所有可访问的页面执行 BFS 遍历,提取表单(action、method、inputs)和 URL 参数。 ``` from intelliscan.modules.crawler import Crawler crawler = Crawler("http://localhost:8080", auth=("admin", "password")) results = crawler.run() # {"forms": [...], "url_params": [...]} ``` ### 2. 注入阶段 对于每个发现的表单/参数,Injector 会测试 `payloads/` 中的 payload。每个请求的响应都会被捕获(状态码、长度、正文摘录)。 ``` from intelliscan.modules.injector import Injector injector = Injector(crawler.session, crawler.targets) injections = injector.run() # 40 injections by default ``` ### 3. 检测阶段 Analyzer 使用特定类型的特征: - **SQLi**:计算 "First name:" 出现的次数(DVWA),检查 SQL 错误模式 - **XSS**:验证响应中是否存在 payload 回显,检查 ` 人工审查) - [ ] 基于浏览器的 DOM XSS 测试(Selenium) - [ ] CI/CD 插件(GitHub Action、Jenkins) ### 长期 (v3.x) - [ ] 分布式扫描(Celery + Redis) - [ ] CVE 和漏洞利用知识库 - [ ] 通过 LLM 提供自动修复建议 ## 参考文献 本项目基于以下学术研究: - Breimi, L. (2001). *Random forests*. Machine Learning, 45(1), 5-32. - Alghawazi, M. et al. (2022). *Detection of SQL injection using ML techniques*. Journal of Cybersecurity and Privacy. - Tadhani, T. et al. (2024). *Securing web applications using hybrid deep learning*. Scientific Reports (Nature). - OWASP Foundation. (2021). *OWASP Top 10*. https://owasp.org/www-project-top-ten/ - Pedregosa, F. et al. (2011). *Scikit-learn: Machine Learning in Python*. JMLR, 12, 2825-2830. 完整参考文献请见 [docs/REFERENCES.md](docs/REFERENCES.md)。 ## 许可证 MIT 许可证。详见 [LICENSE](LICENSE)。 ## 作者 **SABKARI Mohamed** 网络安全与人工智能硕士 摩洛哥盖尼特拉伊本·托法伊勒大学 (Ibn Tofail University) 2025-2026 本项目为在 **Pr. Youssef FAKHRI** 指导下完成的硕士论文项目 (PFE)。 ## 致谢 - OWASP 社区提供的 Top 10 框架和 DVWA - Scikit-learn 团队 (Pedregosa et al., 2011) 提供的 ML 库 - Python 及开源社区 - Pr. Youssef FAKHRI 的学术监督和指导
标签:AI漏洞扫描器, Apex, CISA项目, Docker容器化, DOE合作, DVWA测试, Flask Web面板, HTTP响应分析, LFI检测, OWASP Top 10, Payload变异引擎, PDF报告生成, Python安全工具, SQL注入检测, Web安全, XSS检测, 安全测试, 并发扫描, 攻击性安全, 智能安防, 机器学习, 混合检测引擎, 爬虫与注入分析, 网络安全, 网络安全毕设, 自动化渗透测试, 蓝队分析, 请求拦截, 逆向工具, 防御深度, 随机森林, 隐私保护, 静态特征检测