MarcusESTC/elastic-sqli-demo

GitHub: MarcusESTC/elastic-sqli-demo

基于 Elastic Security 的 SQL 注入实时检测演示项目,包含漏洞应用、检测规则和自动化部署脚本,用于完整展示从攻击到告警的 SIEM 检测流程。

Stars: 0 | Forks: 0

# Elastic Security — SQL 注入检测演示 这是一个完整且独立的演示,展示了 Elastic Security 如何实时检测 SQL 注入攻击——从故意设计为存在漏洞的登录应用,通过 Elastic Agent 的原生日志传输,到在 SOC 中触发高严重性警报,只需大约 **60 秒**。 ## 包含内容 ``` elastic-sqli-demo/ ├── index.html # Vulnerable login form ├── login.php # Vulnerable PHP handler (SQLite) — the demo target ├── ship_accesslog.py # OPTIONAL fallback log shipper (when no Agent on host) ├── presentation.html # Self-contained slide deck explaining the demo ├── elastic/ # ALL Elastic-side configuration (reproducible) │ ├── README.md # Deep-dive on the detection design + how to deploy │ ├── ingest-pipeline-logs-custom.json │ ├── detection-rule.json │ ├── fleet-custom-logs-integration.json │ ├── deploy.sh # Idempotent: creates pipeline + rule + integration │ └── teardown.sh └── docs/ └── demo-runbook.md # Step-by-step script for running the demo live ``` 运行时生成的文件(`access.log`、`demo.db`)会在首次使用时创建,并且已被 git 忽略。 ## 漏洞原理 `login.php` 通过字符串拼接来构建其 SQL 语句——用户输入直接变成了查询逻辑: ``` $sql = "SELECT id, username, display_name FROM users WHERE username = '$username' AND password = '$password'"; ``` 提交用户名 `admin' --` 会将查询重写为以 `admin` 身份进行身份验证,并注释掉密码校验 → **无需凭据即可绕过登录**。 ## 检测工作原理 ``` login.php → access.log → Elastic Agent (Custom Logs) → logs@default-pipeline → logs@custom (adds sqli.raw keyword) → logs-sqli_demo.access-default → ES|QL detection rule (every 60s) → High alert in Security ``` 该规则会匹配原始行(`sqli.raw`)的 **keyword** 副本,因此 SQL 标点符号会被保留,且正常的登录绝不会触发误报。完整的设计原理和 ES|QL 查询请参阅 [`elastic/README.md`](elastic/README.md)。 这是 **SIEM 检测**(日志分析),而不是端点拦截——SQLi payload 属于应用层,因此主机上的 Elastic Defend 只能看到进程/文件活动,而看不到恶意的 SQL。其核心概念是“跨越端点 + SIEM 的统一平台”。 ## 快速开始 ### 1. 运行应用 ``` php -S 127.0.0.1:8080 # 打开 http://127.0.0.1:8080/index.html # 有效的登录:admin / Password123! ``` ### 2. 部署 Elastic 配置 ``` cd elastic export ELASTIC_API_KEY='' export ES_URL='https://.es..gcp.elastic.cloud' export AGENT_POLICY_ID='' # enables native Agent shipping export ACCESS_LOG_PATH="$HOME/elastic-sqli-demo/access.log" ./deploy.sh ``` 主机上没有 Elastic Agent?可以省略 `AGENT_POLICY_ID` 并使用备用的日志传输器: ``` export ES_URL='https://.es..gcp.elastic.cloud' export ES_API_KEY='' python3 ship_accesslog.py --follow # live; or --backfill for existing lines ``` ### 3. 攻击与检测 在表单中提交 `Username: admin' --`,`Password: anything`,然后打开 **Security → Alerts** 并按标签 `SQL Injection` 进行过滤。大约 60 秒内就会出现一个高级别(High)警报。 完整的演示者操作脚本请参阅 [`docs/demo-runbook.md`](docs/demo-runbook.md)。 ## 攻击 Payload(均可触发规则) | Payload(Username 字段) | 演示内容 | |--------------------------|--------------| | `admin' --` | 针对性的管理员账户绕过 | | `' OR 1=1 --` | 通用的恒真绕过 | | `' OR '1'='1' -- ` | 经典重言式(结尾包含空格) | | `' UNION SELECT 1, username, password FROM users -- ` | 凭据提取 | ## 凭据 预置的合法账户为 `admin` / `Password123!`(在首次尝试登录时自动创建)。 ## 安全提示 - 没有提交任何密钥。API key 仅通过环境变量提供。 - `login.php` 中存在漏洞的查询模式是故意的——**请勿**将其复制到真实代码中。 - 演示结束后,请使用 `elastic/teardown.sh` 清理所有环境。
标签:CISA项目, Elastic Security, OpenVAS, PHP, 后端开发, 安全检测规则, 应用安全, 逆向工具