zoukankan      html  css  js  c++  java
  • NCTF2018_easy_audit->coding_breaks

    easy_audit

    题目源码

    <?php
    highlight_file(__FILE__);
    error_reporting(0);
    if($_REQUEST){
        foreach ($_REQUEST as $key => $value) {
            if(preg_match('/[a-zA-Z]/i', $value))   die('waf..');
        }
    }
    
    if($_SERVER){
        if(preg_match('/yulige|flag|nctf/i', $_SERVER['QUERY_STRING']))  die('waf..');
    }
    
    if(isset($_GET['yulige'])){
        if(!(substr($_GET['yulige'], 32) === md5($_GET['yulige']))){         //日爆md5!!!!!!
            die('waf..');
        }else{
            if(preg_match('/nctfisfun$/', $_GET['nctf']) && $_GET['nctf'] !== 'nctfisfun'){
                $getflag = file_get_contents($_GET['flag']);
            }
            if(isset($getflag) && $getflag === 'ccc_liubi'){
                include 'flag.php';
                echo $flag;
            }else die('waf..');
        }
    }  

    修改下,更加适合本地调试

    <?php
    highlight_file(__FILE__);
    error_reporting(0);
    if($_REQUEST){
        foreach ($_REQUEST as $key => $value) {
            if(preg_match('/[a-zA-Z]/i', $value))   die('111111');
        }
    }
    
    if($_SERVER){
        if(preg_match('/yulige|flag|nctf/i', $_SERVER['QUERY_STRING']))  die('2222222');
    }
    
    if(isset($_GET['yulige'])){
        if(!(substr($_GET['yulige'], 32) === md5($_GET['yulige']))){         //日爆md5!!!!!!
            die('33333333');
        }else{
            if(preg_match('/nctfisfun$/', $_GET['nctf']) && $_GET['nctf'] !== 'nctfisfun'){
                $getflag = file_get_contents($_GET['flag']);
            }else die('55555555');
            if(isset($getflag) && $getflag === 'ccc_liubi'){
                include 'flag.php';
                echo $flag;
            }else die('4444444');
        }
    }
    
    ?> 
    来自:https://blog.csdn.net/perfect0066/article/details/84663657  

    第一层

    $_REQUEST 变量虽然说是包含 $_GET,$_POST,$_COOKIE 这些,但实际上却存在一个覆盖的问题,就是当 get 和 post 中有一个同名变量 data 时,在 request变量数组 中只会有一个名为 data 的变量,并且获取的是 post 的值。通过这样的覆盖,从而绕过对 get 变量的值的过滤。

    这里不能用数组绕过,因为下面需要获得值,这里我可以利用$_REQUEST的变量覆盖,用post覆盖get的同名变量,达到绕过。

    第二层

    $_SERVER['QUERY_STRING'] 这里的bypass,这个点应该是比较常见的了,$_SERVER['QUERY_STRING'] 获取的值是未经urldecode的,所以直接编码一下就好了

    $_SERVER['QUERY_STRING']

    这个全局变量中的QUERY_STRING是获取url中?后面的部分

    http://localhost/aaa/index.php?p=222&q=333
    结果: $_SERVER['QUERY_STRING'] = "p=222&q=333"; $_SERVER['REQUEST_URI'] = "/aaa/index.php?p=222&q=333"; $_SERVER['SCRIPT_NAME'] = "/aaa/index.php"; $_SERVER['PHP_SELF'] = "/aaa/index.php";

    我们把url编码下n为%6E,对于如下

    第三层

    数组这里,fuzz一下,很容易发现数组是可绕的(参见同类型的漏洞也容易想到)

    这里的话涉及php md5相关问题,md5函数无法处理数组,直接传入空数组,截取字符串为空,md5函数处理后也为空,因此相等绕过。

    第四层

    file_get_contents 这里要用伪协议其实很容易想到,但很多人似乎就想着用 php://input ,这里因为要去覆盖 $_REQUEST ,所以假如是用 post 去覆盖的话,就不能用php://input 了。最简单的,用 data:// 协议就好了。

    这里就像github上写的一样,可以用php://input来读取,但是因为需要用post覆盖get绕过第一层,所以无法在post上动手。但是可以用伪协议data://读取想要的字符串

    preg_match('/nctfisfun$/', $_GET['nctf']) && $_GET['nctf'] !== 'nctfisfun' 这个点,可能做起来的时候会觉得很奇怪,这里有什么好绕的?实际上,是因为出题人又双叒叕写错正则了。本来是想写 preg_match('/^nctfisfun$/', $_GET['nctf']) && $_GET['nctf'] !== 'nctfisfun',然后让去看后面那个 $ 符的。。。

    本来应该再多一层的,我自己本地尝试绕过,发现无法绕过。本来想通过换行是否可以,但发现不行。有知道的师傅,麻烦点拨一下。

    完整payload

    get:

    ?yulige[]=&nctf=Nnctfisfun&flag=data://text/plain;charset=unicode,ccc_liubi
    或者
    ?%79ulige[]=&nct%66=Nnct%66isfun&%66lag=data://text/plain;base64,Y2NjX2xpdWJp
    或者
    ?%79ulige[]=&nct%66=Nnct%66isfun&%66lag=data://text/plain,ccc_liubi

    post:

    nctf=123&flag=1

    学习文章:

    https://blog.csdn.net/perfect0066/article/details/84663657

    https://github.com/NJUPT-coding-gay/NCTF2018/blob/master/Web/Easy_Audit/WriteUp.md

    https://www.sqlsec.com/2018/11/nctf2018.html#toc-heading-5

      

  • 相关阅读:
    python写入csv文件中文乱码解决方案
    高质量代码有三要素:可读性、可维护性、可变更性
    CFile
    BMP格式图像的显示
    SAP BW 学习笔记(一)
    SAP BW 学习笔记(五)
    SAP BW 学习笔记(二)
    SAP BW 学习笔记(三)
    SAP BW 学习笔记(四)
    CRM 5.0 Marketing – BW integrated topics summary
  • 原文地址:https://www.cnblogs.com/BOHB-yunying/p/11754336.html
Copyright © 2011-2022 走看看