p4fix/vuln_scanner

GitHub: p4fix/vuln_scanner

一款全栈 Web 漏洞扫描应用,提供网站可访问性检查、端口扫描和 Banner 抓取功能,面向授权的安全测试与网络侦察场景。

Stars: 1 | Forks: 1

# 漏洞扫描器 一个全栈 Web 应用程序,用于执行安全扫描,包括网站可访问性检查、端口扫描和 banner grabbing。 ## 功能 - **网站检查**:验证网站是否可访问并获取响应详细信息 - **端口扫描器**:检查目标主机上的特定端口是否打开 - **Banner Grabber**:尝试从打开的端口检索 banner 信息 - **安全的 API**:具有身份验证和速率限制的 API - **现代化 UI**:基于 React 的前端,使用 Tailwind CSS ## 快速开始 ### 选项 1:使用提供的批处理文件 (Windows) 1. **一次性启动所有服务:** start_all.bat 2. **或者分别启动:** start_api.bat # 启动 API 服务器 start_frontend.bat # 启动前端 ### 选项 2:手动设置 #### 前置条件 - Python 3.7+ - Node.js 14+ - npm #### 后端设置 1. 安装 Python 依赖项: pip install -r requirements.txt 2. 启动 API 服务器: cd vuln_scanner_api python app.py ## 验证 API 是否正在运行 启动 API 服务器后,您可以通过向根端点或健康检查端点发送测试请求来验证其是否正在运行: ``` curl http://localhost:5000/ # 或 curl http://localhost:5000/health ``` 成功的响应表明 API 已启动并正在运行。 ## 更改 API 的主机和端口 您可以通过编辑 `vuln_scanner_api/config.py` 或在启动服务器前设置环境变量来更改 API 的主机和端口: - **在 `config.py` 中:** - `HOST` (默认: `0.0.0.0`) - `PORT` (默认: `5000`) - **使用环境变量:** set HOST=127.0.0.1 set PORT=8080 python app.py (在 Windows 上,使用 `set`。在 Linux/macOS 上,使用 `export`。) 然后,API 将在您指定的新主机和端口上可用。 #### 前端设置 1. 安装 Node.js 依赖项: cd vuln-scanner-frontend npm install 2. 启动前端: npm start 前端将在 `http://localhost:3000` 上可用 ## API 配置 前端预配置为: - **API 基础 URL**:`http://localhost:5000` - **API 密钥**:`your-secret-api-key-here` 您可以在前端的配置面板中更改这些设置。 ## API 端点 - `GET /` - API 信息 - `GET /health` - 健康检查 - `POST /check_website` - 检查网站可访问性 - `POST /check_port` - 检查端口状态 - `POST /banner_grab` - 获取 banner 信息 所有 POST 端点都需要 `X-API-Key` 请求头。 ## 安全提示 此工具仅用于教育和授权的安全测试目的。在扫描任何不属于您的系统之前,请务必确保您已获得明确的许可。 ## 故障排除 ### API 连接问题 1. **检查 API 服务器是否正在运行:** curl http://localhost:5000/health 2. **验证 API 密钥:** - 默认的 API 密钥是 `your-secret-api-key-here` - 您可以在 `vuln_scanner_api/config.py` 中更改它 3. **检查 CORS 设置:** - API 允许来自 `localhost` 和 `127.0.0.1` 的请求 - 如果需要,请在配置中更新 `ALLOWED_HOSTS` ### 前端问题 1. **检查前端是否正在运行:** - 在浏览器中打开 `http://localhost:3000` 2. **清除浏览器缓存**(如果您看到过时数据) 3. **检查浏览器控制台**是否有任何 JavaScript 错误 ## 项目结构 ``` Vuln Scanner/ ├── vuln_scanner_api/ # Flask API backend │ ├── app.py # Main API application │ ├── config.py # Configuration settings │ ├── scanner.py # Core scanning functions │ ├── input_validators.py # Input validation │ └── middleware.py # Security middleware ├── vuln-scanner-frontend/ # React frontend │ ├── src/ │ │ ├── components/ # React components │ │ ├── services/ # API service layer │ │ └── types/ # TypeScript types │ └── package.json ├── requirements.txt # Python dependencies ├── start_api.bat # API startup script ├── start_frontend.bat # Frontend startup script └── start_all.bat # Full stack startup script ``` ## 使用的技术 - **React 18** - 使用 hooks 的现代 React - **TypeScript** - 类型安全和更好的开发体验 - **Tailwind CSS** - 实用优先的 CSS 框架 - **Axios** - 用于 API 调用的 HTTP 客户端 - **Lucide React** - 精美的图标 - **React Router** - 客户端路由(如果需要) ## API 集成 前端与漏洞扫描器 API 端点集成: - `POST /check_website` - 网站可访问性检查 - `POST /check_port` - 端口扫描 - `POST /banner_grab` - banner grabbing - `GET /health` - API 健康检查 ## 安全功能 - **输入验证**:对所有输入进行客户端验证 - **错误处理**:全面的错误消息 - **安全警告**:关于负责任使用的内置通知 - **API 密钥管理**:安全的 API 密钥配置 - **CORS 支持**:为本地开发配置 ## 开发 ### 可用脚本 - `npm start` - 启动开发服务器 - `npm build` - 为生产环境构建 - `npm test` - 运行测试 - `npm eject` - 从 Create React App 中弹出 # 漏洞扫描器 API 一个安全的基于 Flask 的 API,用于执行基本的漏洞扫描操作,包括网站可访问性检查、端口扫描和 banner grabbing。 ## 功能 - **网站可访问性检查**:检查网站是否可访问并返回状态码 - **端口扫描**:检查目标主机上的特定端口是否打开 - **Banner Grabbing**:尝试从打开的端口检索 banner 信息 - **安全功能**:API 密钥身份验证、速率限制、输入验证 - **SSRF 防护**:防止访问 localhost 和内部网络 - **全面的日志记录**:用于安全监控的详细日志 ## 安全改进 ✅ **输入验证**:所有输入都经过格式和安全约束验证 ✅ **API 密钥身份验证**:所有端点都需要有效的 API 密钥 ✅ **速率限制**:可配置的速率限制以防止滥用 ✅ **SSRF 防护**:阻止访问 localhost 和内部网络 ✅ **安全标头**:所有响应上的全面安全标头 ✅ **错误处理**:无信息泄漏的正确错误处理 ✅ **日志记录**:用于安全监控的详细日志 ✅ **CORS 配置**:受限制的 CORS 设置 ## 安装 1. **克隆仓库**: git clone cd vuln_scanner_api 2. **安装依赖项**: pip install -r requirements.txt 3. **配置 API**: - 编辑 `config.py` 以设置您的 API 密钥和其他设置 - 对于生产环境,请设置环境变量: export API_KEY=your-secret-api-key-here export DEBUG=False 4. **运行应用程序**: python app.py ## API 文档 ### 身份验证 所有端点都需要在请求头中包含 API 密钥: ``` X-API-Key: your-secret-api-key-here ``` ### 端点 #### 1. 首页 (`GET /`) 返回 API 信息和可用端点。 **响应**: ``` { "message": "Vulnerability Scanner API is running.", "version": "1.0.0", "endpoints": { "/check_website": "POST - Check website accessibility", "/check_port": "POST - Check port status", "/banner_grab": "POST - Grab banner information" }, "authentication": "Requires X-API-Key header" } ``` #### 2. 检查网站 (`POST /check_website`) 检查网站是否可访问。 **请求**: ``` { "url": "https://example.com" } ``` **响应**: ``` { "url": "https://example.com", "status_code": 200, "message": "Online", "error": null } ``` #### 3. 检查端口 (`POST /check_port`) 检查主机上的某个端口是否打开。 **请求**: ``` { "host": "example.com", "port": 80 } ``` **响应**: ``` { "host": "example.com", "port": 80, "status": "Open", "error": null } ``` #### 4. 获取 Banner (`POST /banner_grab`) 尝试从某个端口获取 banner 信息。 **请求**: ``` { "host": "example.com", "port": 80 } ``` **响应**: ``` { "host": "example.com", "port": 80, "banner": "HTTP/1.1 200 OK\r\nServer: nginx/1.18.0\r\n...", "error": null } ``` #### 5. 健康检查 (`GET /health`) 用于监控的健康检查端点。 **响应**: ``` { "status": "healthy", "timestamp": "2024-01-01T00:00:00Z" } ``` ## 配置 编辑 `config.py` 以自定义 API 设置: - `API_KEY`:您的秘密 API 密钥 - `DEBUG`:启用/禁用调试模式 - `HOST`:服务器绑定的主机 - `PORT`:服务器运行的端口 - `ALLOWED_HOSTS`:允许的 CORS 来源的逗号分隔列表 - `MAX_REQUESTS_PER_MINUTE`:速率限制配置 - `REQUEST_TIMEOUT`:请求超时时间(以秒为单位) ## 安全功能 ### 输入验证 - URL 格式验证 - 主机名格式验证 - 端口范围验证 (1-65535) - SSRF 防护(阻止 localhost/内部网络) ### 身份验证 - 所有端点都需要 API 密钥 - 记录无效的 API 密钥尝试 ### 速率限制 - 每个 IP 地址的可配置速率限制 - 默认:每分钟 60 个请求 ### 安全标头 - X-Content-Type-Options: nosniff - X-Frame-Options: DENY - X-XSS-Protection: 1; mode=block - Strict-Transport-Security: max-age=31536000; includeSubDomains - Content-Security-Policy: default-src 'self' ### 错误处理 - 全面的错误处理 - 无敏感信息泄漏 - 用于安全监控的详细日志记录 ## 使用示例 ### 使用 curl ``` # 检查 website curl -X POST http://localhost:5000/check_website \ -H "Content-Type: application/json" \ -H "X-API-Key: your-secret-api-key-here" \ -d '{"url": "https://example.com"}' # 检查 port curl -X POST http://localhost:5000/check_port \ -H "Content-Type: application/json" \ -H "X-API-Key: your-secret-api-key-here" \ -d '{"host": "example.com", "port": 80}' # Banner 抓取 curl -X POST http://localhost:5000/banner_grab \ -H "Content-Type: application/json" \ -H "X-API-Key: your-secret-api-key-here" \ -d '{"host": "example.com", "port": 80}' ``` ### 使用 Python requests ``` import requests headers = { 'Content-Type': 'application/json', 'X-API-Key': 'your-secret-api-key-here' } # 检查 website response = requests.post( 'http://localhost:5000/check_website', headers=headers, json={'url': 'https://example.com'} ) print(response.json()) # 检查 port response = requests.post( 'http://localhost:5000/check_port', headers=headers, json={'host': 'example.com', 'port': 80} ) print(response.json()) ``` ## 错误代码 - `400 Bad Request`:无效的输入数据 - `401 Unauthorized`:缺少或无效的 API 密钥 - `404 Not Found`:找不到端点 - `429 Too Many Requests`:超出速率限制 - `500 Internal Server Error`:服务器错误 ## 日志记录 API 提供全面的日志记录: - 带有 IP 地址的请求日志记录 - 安全事件日志记录(无效的 API 密钥、验证失败) - 带有堆栈跟踪的错误日志记录 - 用于审计跟踪的操作日志记录 ## 开发 ### 项目结构 ``` vuln_scanner_api/ ├── app.py # Main Flask application ├── scanner.py # Core scanning functions ├── input_validators.py # Input validation functions ├── middleware.py # Authentication and security middleware ├── config.py # Configuration settings ├── requirements.txt # Python dependencies └── README.md # This file ``` ### 添加新端点 1. 将端点添加到 `app.py` 2. 应用 `@require_api_key` 装饰器 3. 应用 `@limiter.limit()` 装饰器 4. 添加输入验证 5. 添加适当的错误处理 6. 添加日志记录 ## 安全注意事项 ⚠️ **重要**:此 API 仅用于教育和授权测试目的。 - 在生产环境中始终使用 HTTPS - 定期轮换 API 密钥 - 监控日志以发现可疑活动 - 保持依赖项更新 - 使用强 API 密钥 - 考虑为生产环境使用其他身份验证方法 ## 许可证 本项目用于教育目的。请负责任地使用,并仅在您拥有或获得明确许可进行测试的系统上使用。
标签:Python, React, Syscalls, 主机安全, 安全测试, 插件系统, 攻击性安全, 数据统计, 无后门, 端口扫描, 自动化攻击, 逆向工具