1. 程式人生 > 實用技巧 >記一題反序列化

記一題反序列化


<?php
error_reporting(0);
$file = $_GET["file"];
$p = $_GET["p"];
if (isset($file)) {
    echo 'NONONO' . '<br>';

    if (preg_match("/flag/", $file)) {
        die('HACKER GOGOGO!!!');
    }
    @include($file);

    if (isset($p)) {
        $p = unserialize($p);
    } else {
        echo "NONONO";
    }
}
?>
<!-- You can try ?file=xxxx, and check the code in try.php -->

try.php

<?php
class Seri{
    public $alize;
    public function __construct($alize) {
        $this->alize = $alize;
    }
    public function __destruct(){
        $this->alize->getFlag();
    }
}

class Flag{
    public $f;
    public $t1;
    public $t2;

    function __construct($file){
        echo "Another construction!!";
        $this->f = $file;
        $this->t1 = $this->t2 = md5(rand(1,10000));
    }

    public function getFlag(){
        $this->t2 = md5(rand(1,10000));
        echo $this->t1;
        echo $this->t2;
        if($this->t1 === $this->t2)
        {
            if(isset($this->f)){
                echo @highlight_file($this->f,true);
            }
        }
    }
}

?>

這個是12屆信安大賽justsoso的簡化版。

這裡要呼叫$alize的getflag(),說明$alize必須是flag類。

這裡唯一要考慮的問題是如何讓t1和t2相等,兩個都是隨機的.

PHP和C不同的是引用

這裡是指向同一個變數,讓兩個變數名指向同一個地址了,那麼這必相等