php - PHP 断言:在错误消息中显示文件内容
问题描述
我正在研究一些 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
有没有人知道我如何获取文件内容,假设我只能在 assert 中做到这一点?
解决方案
对于想知道如何做到这一点的人,我找到了一个解决方案。file_get_contents()
不直接显示文件的内容,您必须将echo
其显示出来。
但是,该功能readfile()
做得很好,它只是直接显示文件的内容。
所以只需像这样调用断言:
assert(readfile('file.txt') === null)
推荐阅读
- java - 如何使用 ArrayList 中的索引添加多个对象
- php - Laravel 迁移不适用于 MySQL (InnoDB)
- javascript - 根据 php 脚本中的作业订单安排 cron 作业的更好方法
- cytoscape.js - 如果添加子节点,Dagre 中的布局不显示层次结构
- reactjs - 无法使用 redux 工具包从 API 获取数据
- godot - 收到此错误“add_child:参数“p_child”为空”并且似乎无法追踪它
- python - 使用自定义方法修补方法时如何在测试中检索类属性?
- c# - Gridview中的JQuery如何在文本框在同一行更改时检查复选框
- sql - 如何在动态查询中使用整数变量
- memory-management - 将设备内存和内核分配的内存映射到同一个 vma