tanishkamali14/owasp-top10-vulnerability-scanner

GitHub: tanishkamali14/owasp-top10-vulnerability-scanner

这是一个基于Python的OWASP Top 10漏洞扫描器,用于自动检测Web应用安全漏洞并提供修复建议。

Stars: 0 | Forks: 0

# OWASP Top 10 漏洞扫描器与安全代码修复 **作者:** Tanishka Ganesh Mali **项目类型:** 应用程序安全 / 漏洞评估 / 安全开发生命周期 **重点领域:** OWASP Top 10, Web 应用安全, DAST, 安全代码修复, Python 自动化 ## 项目概述 本项目是一个基于 **OWASP Top 10** 安全风险构建的 Python Web 应用漏洞扫描器。该扫描器爬行目标 Web 应用,识别表单和端点,运行多项安全检查,并生成一份 HTML 报告,其中包含检测到的漏洞、严重性等级、证据、OWASP 映射和安全的修复指导。 本项目的目标不仅是检测漏洞,还要解释如何修复它们。对于每个发现,报告都包含实用的安全编码建议,将漏洞发现与安全软件开发实践联系起来。 本项目展示了以下动手技能: - Web 应用安全测试 - OWASP Top 10 漏洞映射 - 动态应用程序安全测试概念 - 安全编码与修复 - 基于 Python 的安全自动化 - 安全发现报告生成 ## 关键功能 ### 网络爬虫 爬虫访问目标域内的页面并收集: - 内部链接 - HTML 表单 - 表单动作 - HTTP 方法 - 输入字段名称 这使得扫描器能够自动识别接受用户输入的位置。 ### 安全头扫描器 检查缺失或配置错误的 HTTP 安全头,包括: - `Content-Security-Policy` - `X-Frame-Options` - `X-Content-Type-Options` - `Strict-Transport-Security` - `Referrer-Policy` - `Permissions-Policy` 这些检查映射到: ``` OWASP A05: Security Misconfiguration ``` ### Cookie 安全扫描器 检查 Cookie 是否缺少安全属性: - `HttpOnly` - `Secure` - `SameSite` 弱 Cookie 配置会增加会话劫持、跨站脚本攻击影响和跨站请求伪造的风险。 映射到: ``` OWASP A07: Identification and Authentication Failures OWASP A02: Cryptographic Failures OWASP A01: Broken Access Control ``` ### 反射型 XSS 扫描器 使用安全的载荷测试已发现的表单是否存在反射型跨站脚本漏洞。扫描器检查提交的载荷是否在响应中被反射回来,而没有进行适当的编码。 映射到: ``` OWASP A03: Injection ``` ### SQL 注入扫描器 执行中级 SQL 注入检查,包括: - 基于错误的 SQL 注入检测 - 基于联合查询的 SQL 注入检测 - 基于时间的 SQL 注入检测 扫描器会查找常见的 SQL 错误消息和可能表明存在注入行为的异常响应延迟。 映射到: ``` OWASP A03: Injection ``` ### 目录遍历扫描器 通过提交受控的遍历载荷并检查敏感文件泄露的迹象,来测试输入字段是否存在路径遍历行为。 映射到: ``` OWASP A05: Security Misconfiguration ``` ### 开放重定向扫描器 识别通常用于重定向的参数,例如: - `url` - `redirect` - `redirect_url` - `next` - `return` - `continue` 扫描器检查应用程序是否在未经验证的情况下将用户重定向到外部域。 映射到: ``` OWASP A02: Cryptographic Failures ``` ### 失效的访问控制扫描器 尝试在不进行身份验证的情况下访问常见的管理路径,例如: - `/admin` - `/dashboard/admin` - `/api/admin` - `/api/admin/users` 映射到: ``` OWASP A01: Broken Access Control ``` ### 依赖项扫描器 扫描 `requirements.txt` 文件以查找过时或存在漏洞的依赖项。如果安装了 `pip-audit`,扫描器会尝试使用它进行依赖项漏洞检查。 映射到: ``` OWASP A06: Vulnerable and Outdated Components ``` ### HTML 报告生成器 扫描器生成一份包含以下内容的 HTML 报告: - 目标 URL - 扫描时间戳 - 按严重性汇总的发现摘要 - 漏洞标题 - OWASP 类别 - 严重性 - 受影响的 URL 或参数 - 证据 - 安全修复建议 ## 项目架构 ``` Target Web Application | v Web Crawler | v Form and Endpoint Collection | v Scanner Modules | |-- Security Header Scanner |-- Cookie Scanner |-- XSS Scanner |-- SQL Injection Scanner |-- Directory Traversal Scanner |-- Open Redirect Scanner |-- Broken Access Control Scanner |-- Dependency Scanner | v OWASP Mapping + Secure Fixes | v HTML Security Report ``` ## 文件夹结构 ``` owasp_vulnerability_scanner/ │ ├── main.py ├── requirements.txt ├── README.md │ ├── scanner/ │ ├── __init__.py │ ├── crawler.py │ ├── header_scanner.py │ ├── cookie_scanner.py │ ├── xss_scanner.py │ ├── sqli_scanner.py │ ├── dir_traversal_scanner.py │ ├── open_redirect_scanner.py │ ├── access_control_scanner.py │ ├── dependency_scanner.py │ ├── owasp_mapper.py │ └── utils.py │ ├── templates/ │ └── report_template.html │ ├── remediation/ │ ├── xss_fixes.md │ ├── sqli_fixes.md │ ├── access_control_fixes.md │ └── secure_headers.md │ └── reports/ └── generated reports ``` ## 安装说明 ### Windows PowerShell 创建虚拟环境: ``` python -m venv venv ``` 激活它: ``` .\venv\Scripts\Activate.ps1 ``` 安装依赖项: ``` pip install -r requirements.txt ``` 如果 PowerShell 阻止激活,请运行: ``` Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned ``` 然后再次激活: ``` .\venv\Scripts\Activate.ps1 ``` ### macOS / Linux 创建虚拟环境: ``` python3 -m venv venv ``` 激活它: ``` source venv/bin/activate ``` 安装依赖项: ``` pip install -r requirements.txt ``` ## 依赖要求 主要依赖项有: ``` requests beautifulsoup4 jinja2 ``` 可选依赖项: ``` pip-audit ``` 要安装 `pip-audit`: ``` pip install pip-audit ``` ## 使用方法 使用以下命令运行扫描器: ``` python main.py --url http://localhost:3000 --output reports/scan-report.html --max-pages 10 --requirements requirements.txt ``` ### 参数 ``` --url Target URL to scan. --output Path where the HTML report will be saved. --max-pages Maximum number of pages the crawler should visit. --requirements Optional requirements.txt file for dependency scanning. ``` ## 示例:扫描 OWASP Juice Shop 使用 Docker 启动 OWASP Juice Shop: ``` docker run --rm -p 3000:3000 bkimminich/juice-shop ``` 然后运行扫描器: ``` python main.py --url http://localhost:3000 --output reports/juice-shop-report.html --max-pages 10 --requirements requirements.txt ``` 打开生成的报告: ``` reports/juice-shop-report.html ``` ## 示例:扫描合法的公共测试目标 您也可以针对故意存在漏洞的训练应用进行测试,例如: ``` http://testphp.vulnweb.com ``` 运行: ``` python main.py --url http://testphp.vulnweb.com --output reports/testphp-report.html --max-pages 10 --requirements requirements.txt ``` 请仅扫描您拥有、控制或已获得明确测试许可的网站。 ## OWASP Top 10 覆盖范围 | OWASP 类别 | 扫描器覆盖范围 | |---|---| | A01:失效的访问控制 | 管理路径检查,未授权访问检测 | | A02:加密失败 | Cookie 安全检查,重定向验证相关问题 | | A03:注入 | XSS 测试,SQL 注入测试 | | A04:不安全的设计 | 安全修复指导与设计建议 | | A05:安全配置错误 | 缺失头信息,目录遍历检查 | | A06:易受攻击和过时的组件 | 依赖项扫描 | | A07:身份识别和认证失败 | Cookie/会话安全检查 | | A08:软件和数据完整性失败 | 依赖项和包风险意识 | | A09:安全日志记录和监控失败 | 未来改进领域 | | A10:服务器端请求伪造 | 未来改进领域 | ## 样本发现 ``` Title: Reflected Cross-Site Scripting OWASP Category: A03: Injection Severity: High Affected Parameter: search Evidence: Payload reflected in response Secure Fix: Sanitize and encode all user input before rendering it on the page. Implement a Content Security Policy and validate inputs on both client and server side. ``` ``` --- ## 当前限制 This project is an intermediate security scanner built for learning, demonstration, and portfolio purposes. It is not a replacement for enterprise-grade DAST tools such as Burp Suite Professional, OWASP ZAP, Invicti, Acunetix, or Snyk. Known limitations: - It does not fully render JavaScript-heavy single-page applications. - It uses a limited payload set compared to professional scanners. - It may produce false positives or false negatives. - Authentication-aware scanning is not fully implemented yet. - SSRF and advanced business logic testing are future improvements. - Dependency scanning is stronger when `pip-audit` is installed. --- ## 未来改进 Planned improvements include: - Authentication support using session cookies or bearer tokens - JSON API scanning - REST endpoint discovery - SSRF detection - CSRF detection - DOM-based XSS detection - Better severity scoring - CWE mapping - CVSS scoring - PDF report export - Streamlit dashboard - OWASP ZAP API integration - Retest mode to verify whether fixes worked - Screenshot-based report evidence - CI/CD integration for automated scans - SARIF output for GitHub Security tab compatibility --- ## 本项目展示内容 This project demonstrates my ability to: - Build a security tool from scratch using Python - Understand and apply OWASP Top 10 concepts - Automate web application vulnerability testing - Map technical findings to security risk categories - Generate professional security reports - Explain secure code fixes clearly - Think from both attacker and defender perspectives - Connect vulnerability assessment with secure software development - Communicate security findings in a developer-friendly format --- ## 伦理使用 This tool is intended only for educational use and authorized security testing. Do not use this scanner against websites, applications, or systems without permission. Unauthorized scanning may violate laws, policies, or terms of service. Recommended safe targets: - OWASP Juice Shop - DVWA - WebGoat - Mutillidae - Your own local applications - Public test applications explicitly designed for security practice --- ## 作者 **Tanishka Ganesh Mali** M.S. Cybersecurity, Penn State Application Security | Security Engineering | Vulnerability Assessment | Secure SDLC --- ## 许可证 This project is released for educational and portfolio purposes under the MIT License. ```
标签:AES-256, BeEF, Cookie安全, DAST, DOE合作, HTML报告, OWASP Top 10, Python, Web安全, XML 请求, 代码修复, 加密, 动态应用安全测试, 安全代码修复, 安全头扫描, 安全开发, 安全扫描工具, 安全测试, 安全配置, 恶意软件分析, 攻击性安全, 无后门, 漏洞扫描器, 漏洞评估, 爬虫, 网络安全, 网络调试, 自动化, 蓝队分析, 逆向工具, 隐私保护