Perl 如何在wordpress安装中递归搜索和替换所有文件,以删除注入php文件的一些恶意代码?

Perl 如何在wordpress安装中递归搜索和替换所有文件,以删除注入php文件的一些恶意代码?,perl,wordpress,Perl,Wordpress,如何在wordpress安装中递归搜索和替换所有文件,以删除注入php文件的一些恶意代码?黑客在我的wordpress安装中的所有.php文件中添加了一些代码(如下),这种情况在许多网站上经常发生,我花了数小时手动删除代码 今天,我尝试了许多在网上找到的技术,但由于代码段很长,而且其中有许多特殊字符会弄乱分隔符,所以没有成功。我尝试在perl中使用不同的分隔符: perl -p -i -e 's/rogue_code//g' * 到 并尝试使用反斜杠来避开代码中的斜杠,但似乎没有任何效果。我在

如何在wordpress安装中递归搜索和替换所有文件,以删除注入php文件的一些恶意代码?黑客在我的wordpress安装中的所有
.php
文件中添加了一些代码(如下),这种情况在许多网站上经常发生,我花了数小时手动删除代码

今天,我尝试了许多在网上找到的技术,但由于代码段很长,而且其中有许多特殊字符会弄乱分隔符,所以没有成功。我尝试在perl中使用不同的分隔符:

perl -p -i -e 's/rogue_code//g' *

并尝试使用反斜杠来避开代码中的斜杠,但似乎没有任何效果。我在一个共享服务器上工作,所以我不能完全访问我自己目录之外的所有目录

非常感谢……以下是代码:

< ?php /**/ eval(base64_decode("aWYoZnVuY3
... snip tons of this ...
sgIH1lbHNleyAgICB9ICB9"));? >


如果没有机会亲自查看文件,很难确定;但听起来你需要:

find -name '*.php' -exec perl -i -pe 's{<\?php /\*\*/ eval\(base64_decode\("[^"]+"\)\);\?>}{}g' '{}' ';'
find-name'*.php'-exec perl-i-pe的{i有同样的问题(Dreamhost?),首先运行这个
clean.pl
脚本:

#!/usr/bin/perl
$file0 =$ARGV[0];
open F0,$file0 or die "error opening $file0 : $!";
$t = <F0>;
$hacked = 0;
if($t =~ s#.*base64_decode.*?;\?>##) {
    $hacked=1;
}
print "# $file0: " . ($hacked ? "HACKED" : "CLEAN") . "\n";
if(! $hacked) {
        close F0;
        exit 0;
}

$file1 = $file0 . ".clean";
open F1,">$file1 " or die "error opening $file1 for write : $!";
print F1 $t;
while(<F0>) {
 print F1;
}
close F0;
close F1;
print "mv -f $file0 $file0.bak\n"; #comment this if you don't want backup files.
print "mv -f $file1 $file0\n";
然后:
find.-name'*.php'-typef-exec./可疑的\u php.sh'{}\;

当然,所有这些都不是万无一失的

这在很多网站上都很常见,我花了很多时间手动操作 正在删除代码

听起来您需要更好地清理黑客或更改主机。替换所有WP核心文件和foldere、所有插件,然后您所要做的就是搜索主题文件和WP-config.php以查找注入的脚本


请参阅和

您有备份,对吗?否则,您如何确保找到所有要删除的恶意代码?如果这种情况经常发生,则意味着您错误地配置了软件。您可能希望在使受损网站重新联机之前从中进行研究。
#!/usr/bin/perl
$file0 =$ARGV[0];
open F0,$file0 or die "error opening $file0 : $!";
$t = <F0>;
$hacked = 0;
if($t =~ s#.*base64_decode.*?;\?>##) {
    $hacked=1;
}
print "# $file0: " . ($hacked ? "HACKED" : "CLEAN") . "\n";
if(! $hacked) {
        close F0;
        exit 0;
}

$file1 = $file0 . ".clean";
open F1,">$file1 " or die "error opening $file1 for write : $!";
print F1 $t;
while(<F0>) {
 print F1;
}
close F0;
close F1;
print "mv -f $file0 $file0.bak\n"; #comment this if you don't want backup files.
print "mv -f $file1 $file0\n";
#!/bin/sh
#  prints filename if first 2 lines has more than 5000 bytes
file=$1
bytes=`head -n 2 $file | wc --bytes `
if (( bytes > 5000 ))
then
  echo $file
fi