如何使用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.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