PHP断言:在错误消息中显示文件内容

时间:2019-04-26 09:11:51

标签: php file assert

我正在研究Web服务器的一些漏洞,并且发现了一个可以注入一些php代码的断言。 我发现以下代码

assert(file_get_contents('file.txt') !== null)

按我的预期工作:file_get_contents()被执行,其结果在断言中传递。但是,如果我失败了

assert(file_get_contents('file.txt') === null)

file_get_contents()的结果不会被解释,因此不会显示在错误消息中。

Warning: assert(): assert(file_get_contents('file.txt') === null) failed in /Applications/MAMP/htdocs/test/assert.php on line 3 

假设我只能在断言中做到这一点,有人知道我如何获取文件内容吗?

1 个答案:

答案 0 :(得分:0)

对于那些想知道如何实现的人,我找到了解决方案。 file_get_contents()不会直接显示文件的内容,您必须echo才能显示它。

但是,功能readfile()完美地实现了它,它只是直接显示文件的内容。

因此只需调用assert即可:

assert(readfile('file.txt') === null)
相关问题