用于从服务器上的所有index.php文件中删除某些文本的Shell脚本

用于从服务器上的所有index.php文件中删除某些文本的Shell脚本,shell,text,Shell,Text,似乎有一些恶意脚本进入了我保存网页的服务器。我有几个账户,它们都被“感染”(不确定这个词是否正确) 无论如何。所有index.php文件的前面都包含以下代码: <marquee style="position: absolute; width: 0px;"> <a href="http://istanbulescort-ilan.com/" title="escort bayan">escort bayan</a> <a href="http://ist

似乎有一些恶意脚本进入了我保存网页的服务器。我有几个账户,它们都被“感染”(不确定这个词是否正确)

无论如何。所有index.php文件的前面都包含以下代码:

<marquee style="position: absolute; width: 0px;">
<a href="http://istanbulescort-ilan.com/" title="escort bayan">escort bayan</a>
<a href="http://istanbulescort-ilan.com/" title="bayan escort">bayan escort</a>
<a href="http://ankaraescortlari.org/" title="ankara escort">ankara escort</a>
<a href="http://ankaraescortlari.org/" title="ankara escort bayan">ankara escort bayan</a>
<a href="http://ankaraescortlari.org/" title="escort ankara">escort ankara</a>
...
<a href="http://hurhaberci.com" title="son haberler">son haberler</a>
</marquee>
[编辑]

好的,所以我设法把它拼凑起来。有人能确认一下它是否有效,或者就应该改变什么给出一些建议吗

read -d '' hacked <<"EOF"
<marquee style="position: absolute; width: 0px;">
<a href="http://istanbulescort-ilan.com/" title="escort bayan">escort bayan</a>
...
<a href="http://gidasayfasi.com" title="gida">gida</a></marquee>
EOF
find -name \*.php | xargs replace ${hacked} ""  --
read-d''黑客攻击删除带前缀的文本(假设带前缀的文本中没有有用的内容):

上面的diff命令仅显示引用恶意代码与文件$1内容之间的差异。差分逐行计算,并在行前显示标记字符“<”(请参见
man diff
)。 请先尝试此命令

您可以调用脚本(先执行
chmod u+x process.sh
以使其可执行)并将结果重定向到另一个脚本中,例如:

process.sh index.php > new_index.php
因此,要更正大量文件,请执行以下脚本:

#/bin/bash
find . -name "*.php" | while read pathfile
do
   file=${pathfile##*/} # remove the path from the fullpath to the file
   pathonly=${pathfile%/*} # keep only the path
   cp $pathfile ${pathonly}/${file}.org # copy original file to save it, in case of...
   process.sh  ${pathonly}/${file}.org > ${pathfile} # apply correction
done

顺便说一下,如果这有助于文件夹结构,我将centos与cpanel一起使用。从备份中还原这些文件。你不能假设没有其他变化。如果您没有备份,您应该手动检查所有这些文件是否存在恶意代码。我在所有网站上都有相同的结构(我使用的是joomla),并且我已经彻底检查了所有可能包含恶意代码的文件。问题是我每周都有备份,而且所有的网站都非常活跃。下一次备份是明天,我已经删除了本周的旧文件,但恢复这些文件将破坏到现在为止积累的所有内容。我希望有更详细的内容。我经过进一步研究后得出了这个结论。(因为我不想删除任何可以在字幕标签中找到的“无辜”内容)
read-d''hacked@Jinx:我试图提出一个解决方案,这样恶意标签中正确的代码就无法阻止删除恶意标签。它基于恶意文件的引用副本和php文件之间的差异检测。请在测试文件(受感染文件的副本)上运行它,如果运行它,请保存受感染文件的副本(就像我在find命令的while循环中所做的那样)。
#/bin/bash
diff --suppress-common-lines $1 tobedeleted.txt | grep -e '^<' | sed 's/^< //'
process.sh index.php > new_index.php
#/bin/bash
find . -name "*.php" | while read pathfile
do
   file=${pathfile##*/} # remove the path from the fullpath to the file
   pathonly=${pathfile%/*} # keep only the path
   cp $pathfile ${pathonly}/${file}.org # copy original file to save it, in case of...
   process.sh  ${pathonly}/${file}.org > ${pathfile} # apply correction
done