2

temp.php给定当前用户目录中的脚本~

#!/usr/bin/php
<?php
$p=$argv[$argc-1];
$a=file_exists($p);
echo "File exists?". $a ."\n";
include $p
?>

使用上面的脚本,可以将文件名作为参数传递并检索其文本内容。除了说明我的问题之外,我认为它没有任何实际用途。但是,一些 CTF 解决方案利用格式错误的路径字符串来包含任何文件。看来不管字符串'?/../'前面是什么,或者它是否存在,后面的内容都会被当作从当前目录开始的路径。

cd ~
# Make the script executable
chmod +x temp.php
# Create a temporary file
echo empty > empty

./temp.php empty # Output "File exists?1" and "empty". It's fine and expected.
./temp.php 'test?/../empty' # Ouput 'empty' and a newline
./temp.php 'test?/../../../../../etc/hosts' # Output contents in /etc/hosts

我在 include 语句的PHP 页面上找不到相关信息。有没有人有这个话题的知识?

2020/04/18 21:06 更新。我的 PHP 版本是 Ubuntu 18.04 上的 7.2.24。

2020/04/18 21:20 更新。Orz 也许我发现这是..导致问题的原因,而不是问号?。PHPinclude似乎连续崩溃了..s。我仍然想知道这种行为是否在某处被正确记录?

ubuntu@VM-0-5-ubuntu:~$ ./temp.php 'test/../empty'
File exists?
empty
ubuntu@VM-0-5-ubuntu:~$ ./temp.php 'test/../../ubuntu/empty'
File exists?
empty
ubuntu@VM-0-5-ubuntu:~$ 
4

0 回答 0