0

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

反正。所有 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>

此代码弄乱了标题,网页呈现不佳。更不用说我的所有网页上都有一些护送服务链接。

我找到了这个脚本,但我不确定如何正确修改它以从服务器上每个帐户的所有 index.php 文件中删除所有上述代码。我不想运行它然后发现我必须恢复 hudge 备份。

for i in /directory/*.java
do
   # echo 'Working on $i file'
   copy $i tempfil.txt
   sed   -e '/\} catch/,/^\}/d' tempfil.txt > $i
done

[编辑]

好的,所以我设法将其拼凑在一起。有人可以确认它会起作用或就应该更改的内容提供任何建议吗?

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} ""  --
4

1 回答 1

1

删除前置文本(假设前置文本中没有有用的内容):

sed '/<marquee/,/marquee>/ d' index.php

/EXP1/, /EXP2/ d表示 sed 匹配表达式 EXP1 和表达式 EXP2 之间的行,然后应用操作“d”(即“删除”)。

希望这可以帮助。

---- 根据下面的评论进行编辑 --- ---- 恶意代码中可能有正确的代码 ---- 您可以想象复制/粘贴要删除的文本部分到文本文件名 'tobedeleted 。文本文件'。然后编写以下脚本 process.sh (其中 $1 是要清理的文件)

#/bin/bash
diff --suppress-common-lines $1 tobedeleted.txt | grep -e '^<' | sed 's/^< //'

上面的 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
于 2012-09-28T20:51:59.220 回答