美文网首页
实验吧-拐弯抹角

实验吧-拐弯抹角

作者: V0W | 来源:发表于2018-08-07 18:33 被阅读0次

    拐弯抹角

    原题链接

    http://ctf5.shiyanbar.com/indirection/

    分析

     <?php
    // code by SEC@USTC
    
    echo '<html><head><meta http-equiv="charset" content="gbk"></head><body>';
    
    $URL = $_SERVER['REQUEST_URI'];
    //echo 'URL: '.$URL.'<br/>';
    $flag = "CTF{???}";
    
    $code = str_replace($flag, 'CTF{???}', file_get_contents('./index.php'));
    $stop = 0;
    
    //这道题目本身也有教学的目的
    //第一,我们可以构造 /indirection/a/../ /indirection/./ 等等这一类的
    //所以,第一个要求就是不得出现 ./
    if($flag && strpos($URL, './') !== FALSE){
        $flag = "";
        $stop = 1;        //Pass
    }
    
    //第二,我们可以构造 \ 来代替被过滤的 /
    //所以,第二个要求就是不得出现 ../
    if($flag && strpos($URL, '\\') !== FALSE){
        $flag = "";
        $stop = 2;        //Pass
    }
    
    //第三,有的系统大小写通用,例如 indirectioN/
    //你也可以用?和#等等的字符绕过,这需要统一解决
    //所以,第三个要求对可以用的字符做了限制,a-z / 和 .
    $matches = array();
    preg_match('/^([0-9a-z\/.]+)$/', $URL, $matches);
    if($flag && empty($matches) || $matches[1] != $URL){
        $flag = "";
        $stop = 3;        //Pass
    }
    
    //第四,多个 / 也是可以的
    //所以,第四个要求是不得出现 //
    if($flag && strpos($URL, '//') !== FALSE){
        $flag = "";
        $stop = 4;        //Pass
    }
    
    //第五,显然加上index.php或者减去index.php都是可以的
    //所以我们下一个要求就是必须包含/index.php,并且以此结尾
    if($flag && substr($URL, -10) !== '/index.php'){
        $flag = "";
        $stop = 5;        //Pass
    }
    
    //第六,我们知道在index.php后面加.也是可以的
    //所以我们禁止p后面出现.这个符号
    if($flag && strpos($URL, 'p.') !== FALSE){
        $flag = "";
        $stop = 6;        //Pass
    }
    
    //第七,现在是最关键的时刻
    //你的$URL必须与/indirection/index.php有所不同
    if($flag && $URL == '/indirection/index.php'){
        $flag = "";
        $stop = 7;        //Pass
    }
    if(!$stop) $stop = 8;
    
    echo 'Flag: '.$flag;
    echo '<hr />';
    for($i = 1; $i < $stop; $i++)
        $code = str_replace('//Pass '.$i, '//Pass', $code);
    for(; $i < 8; $i++)
        $code = str_replace('//Pass '.$i, '//Not Pass', $code);
    
    
    echo highlight_string($code, TRUE);
    
    echo '</body></html>'; 
    

    题目的意思就是通过改变URL地址栏访问index.php,但是限制了条件不能使用 ./ ../ \\ 而且只能使用小写字母,不可以在php后加点,
    关键是不能直接是http://ctf5.shiyanbar.com/indirection/index.php
    这里我们可以利用伪静态技术,使用http://ctf5.shiyanbar.com/indirection/index.php/index.php,index.php后的index.php会被当做参数处理,所以服务器只会解析第一个index.php,满足条件成功绕过。

    URL伪静态就是通过对动态网页进行URL处理(重写),从而实现看起来像是静态URL页面(而实际网页目录或路径中没有该页面)的方法,表现形式主要是去掉动态网页QUERY参数,还有可以让URL看起来更加有序条理。举个例子:

    http://www.example.com/test.php?cate=soft&page=2,这是典型的动态页面。

    经过伪静态处理,可能变成http://www.example.com/test/soft/index/2.html,如果有多个类似页面,URL看起来就会更加舒服。

    伪静态技术在Wordpress、Discuz、Z-BLOG及各种CMS中都有运用,伪静态的目的无非是看起来更加舒服,据说对搜索引擎更加友好,天缘不懂SEO就不说了。

    flag

    CTF{PSEDUO_STATIC_DO_YOU_KNOW}

    知识点

    URL 伪静态技术

    相关文章

      网友评论

          本文标题:实验吧-拐弯抹角

          本文链接:https://www.haomeiwen.com/subject/pzgavftx.html