PHP assert : 在错误信息中显示文件内容
PHP assert : display file content in error message
我正在研究 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
假设我只能在断言中获取文件内容,有人知道我如何获取文件内容吗?
对于想知道如何做到这一点的人,我找到了解决方案。 file_get_contents()
不会直接显示文件的内容,你必须 echo
才能显示它。
然而,函数readfile()
做得很完美,它只是直接显示文件的内容。
所以只需像这样调用断言:
assert(readfile('file.txt') === null)
我正在研究 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
假设我只能在断言中获取文件内容,有人知道我如何获取文件内容吗?
对于想知道如何做到这一点的人,我找到了解决方案。 file_get_contents()
不会直接显示文件的内容,你必须 echo
才能显示它。
然而,函数readfile()
做得很完美,它只是直接显示文件的内容。
所以只需像这样调用断言:
assert(readfile('file.txt') === null)