URL参数到文件


URL parameters to file

如何使用url参数创建和写入文件

例如

:web.com/index.php name =用法?输入= halloworld

文件名必须为test.txt,内容必须为halloworld.

这是我目前看到的

if(isset($_GET['name']))
{
    $File = $_GET['name']; 
    $Handle = fopen($File, 'w');
    $Data =  $_GET['input']; 
    fwrite($Handle, $Data);
    fclose($Handle); 
}

file output = test.txt?输入=halloworld错误

谢谢。

你的错误是在使用?而不是&在你的url,它应该是web.com/index.php?name=test.txt&input=halloworld

也就是说,你不应该做这样的事情,因为这是非常危险的。这样,您将服务器暴露于任何类型的攻击或损坏。攻击者可以很容易地在你的web服务器上编写php文件并控制它。

记住这一点。

编辑:我在问题评论中写了它,但我在这里重写了它,如果攻击者用以下参数调用您的脚本怎么办:

web.com/index.php?name=evil.php&input=<?php exec('rm -rf /');
然后请求url
web.com/evil.php

您的文件系统将被清除(如果用户有这样做的权限)。其他类型的攻击可能更微妙,可以在服务器中注入php shell,等等。

web.com/index.php?name=test.txt?input=halloworld不是正确的查询字符串。考虑:

web.com/index.php?name=test.txt&input=halloworld