duanliujie8639 2019-02-11 12:45
浏览 127

是否可以转义此str_replace()以进行路径遍历?

I'm testing one of our PHP web applications for security issues.
The system the code is running on runs with at least PHP7.2.

Now I found something like the following in the code (simplified for this question, but boils down to this):

$file = $_GET['file'];

$path = "/some/directory/" . $file;

$path = str_replace(['../', '..'], '', $path);

echo file_get_contents($path);  

Is it possible to modify the file parameter in a way that we can escape /some/directory, so that after the str_replace() the file_get_contents()-call looks something like: file_get_contents(/some/directory/../../etc/passwd)?

Edit:
I can't change the order of code execution. I can only define the value of $_GET['file'] with my request.
Furthermore I know how to make this more secure but for my research I intend to break it.

Basically what needs to be done is somehow tricking out the str_replace() into leaving some ../ behind.

I tried for a few hours now, with various approaches, but - luckily for our application - couldn't get it working.
Do you have any ideas?

You can fiddle around with the code here: https://3v4l.org/3ehYA

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元