通过 SSH 查找并删除?

发布于 2025-01-06 10:37:38 字数 182 浏览 0 评论 0原文

我的网络服务器遭到黑客攻击(尽管安全团队告诉我没有任何问题),并且无数的文件有一行额外的 PHP 代码,生成指向某个越南网站的链接。

鉴于我的服务器上有数以万计的文件,有没有办法可以使用 SSH 并从找到的每个文件中删除该行代码?

请具体回答,我只使用 SSH 几次来完成一些非常基本的任务,并且不想最终删除一堆文件!

My web server got hacked (Despite the security team telling me nothing was compromised) and an uncountable number of files have an extra line of PHP code generating a link to some Vietnamese website.

Given there are tens of thousands of files across my server, is there a way I can go in with SSH and remove that line of code from every file it's found in?

Please be specific in your answer, I have only used SSH a few times for some very basic tasks and don't want to end up deleting a bunch of my files!

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

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

发布评论

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

评论(4

晚雾 2025-01-13 10:37:38

是的,几行 shell 脚本就可以做到。不过,我犹豫着是否要把它给你,好像出了什么问题我会因为搞乱你的网络服务器而受到指责。也就是说,解决方案可以像这样简单:

for i in `find /where/ever -name '*.php'`; do
    mv $i $i.bak
    grep -v "http://vietnamese.web.site" $i.bak >> $i
done

这会找到 /where/ever 下的所有 *php 文件,并删除任何具有 http 的行: //vietnamese.web.site 在其中。它为每个文件创建一个 *.bak 副本。运行此命令并且一切看起来都不错后,您可以删除备份。

find . -name '*.php.bak' -exec rm \{\} \;

您的下一个任务是找到新的提供商,因为他们不仅被黑客攻击,而且他们显然不保留备份。祝你好运。

Yes, a few lines of shell script would do it. I hesitate to give it to you, though, as if something goes wrong I'll get blamed for messing up your web server. That said, the solution could be as simple as this:

for i in `find /where/ever -name '*.php'`; do
    mv $i $i.bak
    grep -v "http://vietnamese.web.site" $i.bak >> $i
done

This finds all the *php files under /where/ever, and removes any lines that have http://vietnamese.web.site in them. It makes a *.bak copy of every file. After you run this and all seems good, you could delete the backups with

find . -name '*.php.bak' -exec rm \{\} \;

Your next task would be to find a new provider, as not only did they get hacked, but they apparently don't keep backups. Good luck.

软糯酥胸 2025-01-13 10:37:38

首先创建一个正则表达式,匹配错误代码(并且仅匹配错误代码),然后运行

find /path/to/webroot -name \*.php -exec echo sed -i -e 's/your-regex-here//' {} \;

如果一切正常,请删除 echo

First create a regex, that matches the bad code (and only the bad code), then run

find /path/to/webroot -name \*.php -exec echo sed -i -e 's/your-regex-here//' {} \;

If everything looks right, remove the echo

沫离伤花 2025-01-13 10:37:38

我按照以下方式进行。例如,删除与特定名称或扩展名匹配的文件。

rm -rf * cron.php。 *

rm -rf * match_string *

其中 match_string 可以是任何字符串。确保 * 和字符串名称之间没有空格。

I do it following way. E.g. to delete files matching particular name or extension.

rm -rf * cron.php. *

rm -rf * match_string *

where match_string will be any string. Make sure there will be no space between * and string name.

内心旳酸楚 2025-01-13 10:37:38
rm -f cron.php.*

删除此文件夹中名为 cron.php.[whereveryouwant] 的所有文件

rm -f cron.php.*

Delete all file in this folder called cron.php.[whereveryouwant]

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