[BJDCTF2020]Mark loves cat
浏览 613 | 评论 0 | 字数 1054
硝基苯
2024年01月05日
  • 考点:Git文件泄露、变量覆盖

    路径扫描,发现存在git文件泄露
    04871-od4wopgcmwb.png
    用工具将源码脱下来,发现关键代码

    
    <?php
    include 'flag.php';
    $yds = "dog";
    $is = "cat";
    $handsome = 'yds';
    foreach($_POST as $x => $y){
        $$x = $y;
    }
    foreach($_GET as $x => $y){
        $$x = $$y;
    }
    foreach($_GET as $x => $y){
        if($_GET['flag'] === $x && $x !== 'flag'){
            exit($handsome);
        }
    }
    
    //满足不GET和POST个flag
    if(!isset($_GET['flag']) && !isset($_POST['flag'])){
        exit($yds);
    }
    
    //满足GET或POST个flag
    if($_POST['flag'] === 'flag'  || $_GET['flag'] === 'flag'){
        exit($is);
    }
    echo "the flag is: ".$flag;
    

    能确定就是需要我们输出$flag,可以从代码中发现,如果我们不做些什么,那么将会exit
    存在多种解:

    • 第一种:将$handsome覆盖为$flag
      利用第二个foreach$handsome = $flag ,然后去满足if($_GET['flag'] === $x && $x !== 'flag')$x=handsome即可

    最终形成poc:?handsome=flag&flag=handsome

    • 第二种:将$yds替换为$flag
      要满足不能GETPOST个flag,并且要让$yds=$flag

    最终poc:?yds=flag

    • 第三种:$is替换为$flag

    最终poc:GET ?is=flag POST flag=flag

    本文作者:硝基苯
    本文链接:https://www.c6sec.com/index.php/archives/951/
    最后修改时间:2024-01-05 17:27:42
    本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!
    评论已关闭
    评论列表
    暂无评论