gpt4 book ai didi

bash - 使用 bash 在我的网络服务器上查找恶意脚本

转载 作者:行者123 更新时间:2023-11-29 09:09:10 27 4
gpt4 key购买 nike

我在网络服务器上遇到问题。有人用泄露的 wordpress 感染了它。问题如下,文件中某处存在一些恶意 phpscript。恶意脚本将 iframe 放入网络服务器 (/home) 上的每个文件中但问题是我不知道脚本在哪里,我在/home 中有数千个 Web 文件,它可能在任何地方。我知道如何删除所有 iframe,但我的想法是删除触发器。所以我在徘徊如何修复它,我可能有一个解决方案,但我需要你的建议

我注意到脚本会不时执行但完全随机(大约每周一次)现在假设我使用以下 shell 命令(目前我每 30 分钟运行一次)清除了所有恶意 iframe

find /home -type f | xargs sed -i 's$<iframe src="[^"]*" width="2" height="2" frameborder="0"></iframe>$ $g'

现在我所有的 php 文件都没有 iframe,我的想法是当 iframe 再次出现时提醒我。像这样,如果我有 iframe 出现的大致时间,那么我可以查看 apache 日志以查看调用了哪个 webscript。

所以我创建了另一个 bash shell,我想听听您的建议,以了解它是否可以。我会在服务器上每 30 分钟运行一次,直到我收到一封邮件。

然后我会查看 apache 日志以检查最近 30 分钟的日志。

所以这是我正在考虑的 bash:

#!/bin/bash     
find /home -type f | xargs grep -q '<iframe src="[^"]*" width="2" height="2" frameborder="0"></iframe>' #Find the string in all file on my all directory
if [ $? -eq 0 ] #if the result is not equal to zero
then
echo "At the following time : " $(date +%H-%M-%S) | mail -s "[Serveur Leaked] Bad iframe has been found " me@mymail #we send a mail with the date
find /home -type f | xargs sed -i 's$<iframe src="[^"]*" width="2" height="2" frameborder="0"></iframe>$ $g' #we replace the iframe with a whitespace
else
exit 1
fi

exit 0

我真的需要找到一个解决方案,因为正如我所说,我每 30 分钟运行一次查找和替换 shell 命令,这需要很多过程。

但我不能让 iframe 在我的服务器上停留太久,以至于我的网站会被谷歌列入黑名单,我不能承受这个。

非常感谢您的 future 建议。

安塞尔姆

最佳答案

一旦找到要监控的 iframe 文件,可能是 inotify 的 shell 脚本版本,inotifywait , 将是最简单的解决方案。在你的脚本中使用它是这样的:

#!/bin/sh
while inotifywait -e modify /var/log/messages; do
if tail -n1 /var/log/messages | grep httpd; then
kdialog --msgbox "Apache needs love!"
fi
done

一般来说,有比较好的文件监控工具,比如auditd其中包括预建的实用程序,专为安全和审计而设计。

此外,还有 fanotify提供用户信息并可以有效地监控整个卷。查看出色的示例工具:fatrace .

inotify 存在几个重大问题:它无法可靠地监控新创建的文件夹,并且无法识别文件更改的来源 (PID)。这些都不在此处,但直接使用 inotify 需要一些编码。

关于bash - 使用 bash 在我的网络服务器上查找恶意脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17601509/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com