通过 SSH 查找并删除?
我的网络服务器遭到黑客攻击(尽管安全团队告诉我没有任何问题),并且无数的文件有一行额外的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,几行 shell 脚本就可以做到。不过,我犹豫着是否要把它给你,好像出了什么问题我会因为搞乱你的网络服务器而受到指责。也就是说,解决方案可以像这样简单:
这会找到
/where/ever
下的所有*php
文件,并删除任何具有http 的行: //vietnamese.web.site
在其中。它为每个文件创建一个*.bak
副本。运行此命令并且一切看起来都不错后,您可以删除备份。您的下一个任务是找到新的提供商,因为他们不仅被黑客攻击,而且他们显然不保留备份。祝你好运。
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:
This finds all the
*php
files under/where/ever
, and removes any lines that havehttp://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 withYour 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.
首先创建一个正则表达式,匹配错误代码(并且仅匹配错误代码),然后运行
如果一切正常,请删除
echo
First create a regex, that matches the bad code (and only the bad code), then run
If everything looks right, remove the
echo
我按照以下方式进行。例如,删除与特定名称或扩展名匹配的文件。
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.
删除此文件夹中名为 cron.php.[whereveryouwant] 的所有文件
Delete all file in this folder called cron.php.[whereveryouwant]