PHP代码注入。我们有安全风险吗?

发布于 2024-11-15 08:56:07 字数 236 浏览 4 评论 0原文

我们有一个简单的 php 文件来捕获电子邮件。它将这些电子邮件放入 csv 文件(该文件不能由 php 执行)。最近有人成功入侵了我们的网站,这似乎是入口点之一,但我不明白这是怎么可能的。这是脚本:

$fh = fopen('cap.csv', 'a+');
fwrite($fh, "\r".$_GET['email']);
fclose($fh);

非常基本,对吧?你能想到利用这个吗?

We have a simple php file that captures emails. It drops these emails into a csv file (which is not executable by php). We recently had someone who managed to hack our site and this seemed like one of the entry points, but I don't see how it's possible. Here's the script:

$fh = fopen('cap.csv', 'a+');
fwrite($fh, "\r".$_GET['email']);
fclose($fh);

Pretty basic right? Is there anyway you can think of to exploit this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

澜川若宁 2024-11-22 08:56:07

是的,但可能不是您正在寻找的。

我唯一能做的就是:

  1. 将任何内容添加到您的文件中,仅附加。
  2. (可选/奖励)如果您没有保护文件并窃取所有电子邮件地址,请直接打开该文件。

它不允许我执行任何操作,或访问任何内容。 (除非你处理它并在其他地方造成泄漏)。但仍然要确保安全!

Yes, but probably not what you are looking for.

The only things I could do are:

  1. Add anything to your file, append only.
  2. (optional/bonus) Open the file directly if you haven't secured it and steal all e-mail addresses.

It won't allow me to execute anything, or gain access to anything though. (Unless you process it and cause an leak somewhere else). But still - make this secure!

忆梦 2024-11-22 08:56:07

您向我们展示的代码只能用于将任何内容放入 csv 文件中(我假设您没有验证/验证 $_GET['email'] 变量),但您不能以这种方式注入并执行 PHP 代码。

也许您有一个可以处理被利用的 csv 文件的脚本。

The code you have shown us can only be used to put anything in the csv file (I assume you don't verify/validate the $_GET['email'] variable), but you can't inject and execute PHP code that way.

Maybe you have a script that works on the csv file which got exploited.

喜爱纠缠 2024-11-22 08:56:07

对于给定的代码,我现在唯一能想到的是 NullByte 攻击向量(尽管我不确定它们是否适用于当前版本的 PHP 或什至适用于您的代码)。由于您使用的是 $_GET,因此通过电子邮件参数进行的任何攻击都应该在服务器的日志文件中可见。

检查您的日志文件中是否有任何可疑的电子邮件字符串,例如类似

http://example.com?email=foo\0somethingmalicious

的内容。

The only thing I can think of right now for the given code is a NullByte attack vector (though I'm not sure they work in current versions of PHP anymore or even apply to your code). Since you are using $_GET, any attack via the eMail param should be visible in your server's log files.

Check your Log files for any suspicious email strings, e.g. something like

http://example.com?email=foo\0somethingmalicious

and similar things.

忘东忘西忘不掉你 2024-11-22 08:56:07

您发布的代码表明您没有对输入数据进行太多清理。因此,您可能在软件的其他部分也遇到类似的问题。

除此之外,即使您不在应用程序中执行 csv 文件,也可以在其中注入 PHP 代码。

因此,如果应用程序中存在另一个漏洞,无法正确检查输入数据,并且可能会被利用来包含服务器上的文件,然后包含有问题的 csv 文件,则可以执行远程代码。

The code you posted suggests that you do not much sanitization on the input data. So it's likely that you have similar issues in other parts of the software.

Next to that even if you don't execute the csv file within your application, it is possible to inject PHP code therein.

So if there is another hole in the application that does not properly check input data and that could be exploited to include files on the server and then include that csv file in question, remote code execution is possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文