个性化阅读
专注于IT技术分析

在我的WordPress主题文件中不断发现注入垃圾的PHP

点击下载

我为客户的网站构建了一个自定义主题, 并且该主题不断被黑客入侵。我发现每个主题文件和插件的顶部都有一堆乱码。它们都是超级压缩的, 而且不太容易阅读, 但是看起来就像一堆数字。它不会在网站本身上输出任何内容。我知道它正在发生的唯一原因是因为向插件添加代码会破坏插件, 而WP会自动禁用它。这已经发生了5到6次。

在第二次之后, 我意识到默认设置无法解决问题。因此, 我安装了WordFence, 并在一个月内完美运行。 WordFence开始描绘在任何给定时刻试图对站点进行多少次攻击的情况。太疯狂了我还更改了所有密码(用户, FTP等), 更改了表前缀, 阻止了wp-admin并使用了不同的URL来访问破折号, 并且在Harding WordPress文章中几乎跟踪了每一项。在这里也听了一些帖子的建议。

虽然看起来一无所有。经过一个月的成功, 该插件和我的措施停止了工作。无用的字符串开始出现在主题文件的顶部。但奇怪的是, 没有插件文件。我清除了所有内容并尝试使用iThemes安全套件而不是WordFence。不!醒来后发现该网站再次遭到黑客入侵。

除上述内容外, 我还缩小了插件列表的范围, 以选择值得信任的少数几个在其他站点上证明无害的插件:强大和高级自定义字段。我担心自己以某种方式弄乱了主题, 但是我编码了大约十二个, 而在任何这些站点上都从未遇到过此问题。

我不知所措。我觉得如果我了解” hack”的功能, 我将能够更好地应对它, 但是我很茫然。这些东西很难用谷歌搜索。任何指导将不胜感激。

这是注入代码的链接


#1


我曾经在服务器中发现此问题, 最后我制作了一个bash脚本, 寻找该代码, 仅从每个受感染的PHP文件中删除了顶行。它解决了问题。

我放在这里是为了让你可以使用它来摆脱恶意代码, 但请记住尝试查找服务器被黑客攻击的方式, 以免再次遭到黑客攻击。

在bash shell中使用非常简单:

测试是否有被感染的文件

./remove_malware.sh /var/www/wp_path/

清除受感染的文件

./remove_malware.sh /var/www/wp_path/ clean

脚本(remove_malware.sh):

#!/bin/bash
#
# This script remove malware of PHP files.
#
# In this case it will remove some malicious code
# from all WordPress PHP files that is at top of
#  every PHP file.
#
# The string at the top of every file is:
#
# <?php if(!isset($GLOBALS["\x61\156\x75\156\x61"])) { $ua=strtolower($_SERVER["\x48\124\x54\120\x5f\125\x53\105\x52\137\x41\107\x45\116\x54"]); if ((! strstr($ua, "\x6d\163\x69\145")) and (! strstr($ua, "\x72\166\x3a\61\x31"))) $GLOBALS["\x61\156\x$
#
# This script tries to find the string inside $_SERVER
# of the above line at the top of the files to determine
# if the file is infected. If you run the script and
# nothing seems to be infected but you suspect and you 
# want to be sure, just open any PHP of WordPress and 
# check if the malicious line code is present. If is 
# present but the script did not detect, it is because 
# the content inside $_SERVER may be diferent.
# In these cases, just replace in this script the string
# in the -e parameter of grep line with the content of 
# $_SERVER found in your PHP (remember to escape 
# the \ with \\\\) and run again this removal script.
#
#
# JavocSoft 2014
#

if [[ -z "$1" ]]; then
  echo "Directory where to find is required."
else
  grep -rnwl $1 --include \*.php -e "\\\\x48\\\\124\\\\x54\\\\120\\\\x5f\\\\125\\\\x53\\\\105\\\\x52\\\\137\\\\x41\\\\107\\\\x45\\\\116\\\\x54" | while read -r filename ; do

    if [[ ! -z "$2" ]]; then
       echo "Found file $filename. Cleaning..."
       awk 'BEGIN {matches=0} matches < 1 && /1/ { sub(/^.*<?php/, "<?php"); matches++ } { print $0 }' $filename > $filename.purged
       mv $filename $filename.bck
       mv $filename.purged $filename
    else
      echo "Found file $filename."
    fi

  done
  echo "Done."
fi

#2


缩小其范围的一种方法是从你的pastebin中获取print_r(我相信其hex_values):

$ _SERVER [” \ x48 \ 124 \ x54 \ 120 \ x5f \ 125 \ x53 \ 105 \ x52 \ 137 \ x41 \ 107 \ x45 \ 116 \ x54″]

print_r(\x48\124\x54\120\x5f\125\x53\105\x52\137\x41\107\x45\116\x54);

输出如下:

$_SERVER["HTTP_USER_AGENT"];

该代码的一小部分记录在官方手册中:

‘HTTP_USER_AGENT’用户代理的内容:当前请求中的标头(如果有)。这是一个字符串, 表示正在访问页面的用户代理。一个典型的例子是:Mozilla / 4.5 [en](X11; U; Linux 2.2.9 i586)。除其他外, 你可以将此值与get_browser()结合使用, 以根据用户代理的功能来调整页面的输出。

遍历整个代码将花费一些时间, 因为某些”乱码”已嵌入其他功能中。

有点警告, 我既不是安全专家, 也不是php向导, 在测试任何代码时, 请尝试在线使用沙箱, 例如http://sandbox.onlinephpfunctions.com/

赞(0)
未经允许不得转载:srcmini » 在我的WordPress主题文件中不断发现注入垃圾的PHP

评论 抢沙发

评论前必须登录!