# 惡意程式分析 (ColdLock) ###### tags: `malware analysis` `reverse` ## 結論 :::info - 這是一隻ColdLock變種的勒索軟體 - 他會檢查自己是否在win10系統,並關閉通知及Windows Defender - 只會在每天的11點11分後發作 - 利用檢查`%System Root%\ProgramData\readme.tmp`判斷是否系統已被感染 - 勒索訊息寫在`How To Unlock Files.txt`,包含personalID,會在多個路徑下產生 - `<all drive path>\` - `%System Root%\Users\<user>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup` - `%System Root%\Users\<user>\Desktop` - 加密方式採用AES CBC模式,利用AESkey加上寫死的salt取得使用Rijndael演算法需要的key及IV - padding方式針對檔案大小區分為PKSC#7及補0 - COLDLOCK會中止資料庫及OUTLOOK服務的執行 - 最後會修改桌布(存在`%System Root%\ProgramData\<10_rand str>.jpg` (透過修改登錄檔及用RUNDLL.exe即時刷新) ::: ## 分析 - Hash - `MD5: 8ca3560f9561da2263a860889318bed9` - 將hash丟進virustotal中分數51/71, 且可以被偵測為`ColdLock`勒索軟體的變種 ![](https://i.imgur.com/D8AhJJ5.png) - 使用`pestudio`初步分析 ![](https://i.imgur.com/ercrS0q.png) - 可以看到Compiler-stamp跟debugger-stamp的時間很明顯有問題 - 是一隻Microsoft .Net編譯的32bit PE格式執行檔 - 使用`PEiD`查殼 - 該樣本沒有加殼 ![](https://i.imgur.com/SpCA16G.png) - 因為是.net編譯的C#程式,使用`dnspy`進行逆向分析 - 因為沒有混淆,可以先看method可以大致了解惡意程式做的事情 :::info 1. `CheckRunOnced`: 會檢查自己是否有感染過系統 2. `CheckWindowsVersion`: 會檢查自己所在的Windows版本 3. `DisableWindowsNotifycation`及`DisableWindowsDefender`: 樣本會嘗試關閉推播通知及Windows Defender 4. `CollectPathes`: 因為是勒索軟體,需要收集要加密的路徑 5. `RSA...`及`AES...`: 使用RSA及AES加密 6. `WaitForExecuteTime`: 表示該樣本可能有特定的發作時間 7. `TerminateDatabaseService`: 中止Database功能,用於停止備份功能 ![](https://i.imgur.com/sPoGdpL.png =300x) ::: - `Main()`執行`StartAction()` (Part I) ![](https://i.imgur.com/OqMp9pb.png =500x) 1. 使用`CheckWindowsVersion()`函式檢查版本是否是Windows10, 如果是就設定`IsWindows10` flag ![](https://i.imgur.com/jQrcJK4.png =400x) 2. `DisableWindowsNotifycation()`及`DisableWindowsDefender()`會檢查`IsWindows10` flag, 如果是True, 就會分別關閉Windows通知推播通知及Windows Defender - 透過將登錄檔`Software\\Microsoft\\Windows\\CurrentVersion\\PushNotifications`中的`ToastEnabled`欄位改成0來關閉通知 ![](https://i.imgur.com/6BZ9dUE.png =400x) - 以及使用shell命令來關閉Windows Defender ![](https://i.imgur.com/Mh37fq1.png =400x) 3. `method_9()`將所有`HKEY_USERS`中沒有`class`字串且長度大於20的Subkey加入`PathesRegistry`這個list中 4. `CollectPaths()`將 - `%System Root%\\Program Files` - `%System Root%\\Program Files(x86)` - `%System Root%\\ProgramData` 加入`PathesNoLock` list中, 並搜尋其子目錄中含有 `sql`、`mariadb`、`oracle`等資料庫相關字串的路徑,加入`PathsDatabase` 5. `method_10()`將 - `HKEY_CURRENT_USER\Volatile Environment`中的`USERPROFILE`也加入`PathesDatabase`中(其值類似`"C:\Users\<username>"`) - `%System Root%\Users\<username>\\appdata` 加入`PathesNoLock` 6. 之後將一個長度32的randomstring用RSA加密,作為`PersonalID` 7. 產生`LockedMessage`, 其中包含`PersonalID` 8. `WaitForExecuteTime`中,他會檢查當前時間與當日上午11:11比較 - 會不斷的`sleep(15000)` (等待15秒鐘)直到時間超過當日上午11:11 ![](https://i.imgur.com/eRJo20N.png =400x) 9. `CheckRunOnced()`會檢查`%System Root%\ProgramData\read.tmp`這個檔案是否存在,如果存在就exit,不存在就創建這個檔案並在其中寫入`LockedMessage` ![](https://i.imgur.com/5SA7qME.png =400x) - `StartAction()` (Part II) ![](https://i.imgur.com/45RjDRY.png =500x) 10. `GetDrives()`將"固定式磁碟機(fixed)"、"網路磁碟機(network)"及"抽取式存放裝置(Removable)"的路徑(ex. `D:\`)存入回傳的array ![](https://i.imgur.com/lpXMCrT.png =300x) - 將`<drive_path>`下的`\Sytem Volume Information`及`\$recycle.bin`加入`PathesNoLock` - 至此`PathDatabase`中包含 1. `sql` in `%System Root%\ProgramData` 、`%System Root%\Program Files`、`%System Root%\Program Files(x86)` 2. `mariadb` in `%System Root%\ProgramData` 、`%System Root%\Program Files`、`%System Root%\Program Files(x86)` 3. `oracle` in `%System Root%\ProgramData` 、`%System Root%\Program Files`、`%System Root%\Program Files(x86)` 4. `%System Root%\\ProgramData\\Microsoft\\Windows\\Start Menu` 5. `%System Root%\\Program Files\\Microsoft\\Exchange Server` 6. `%System Root%\\Program Files(x86)\\Microsoft\\Exchange Server` 7. `%System Root%\\Users\<username>` - 至此`PathesNoLock` (不會被加密的)中包含 1. `%System Root%\\Program Files` 2. `%System Root%\\Program Files(x86)` 3. `%System Root%\\ProgramData` 4. `%System Root%\\Users\\all users` 5. `%System Root%\\Users\\default` 6. `%System Root%\\Windows\System32` 7. `%System Root%\\Users` 8. `%System Root%\\Users\\<username>\AppData\Local\Temp\` 9. `%System Root%\\Users\\<username>\\appdata` 10. `<all_drive_path>\System Volume Information` 11. `<all_drive_path>\$recycle.bin` - 加密條件 - 遍歷所有Drive Path - 若`PathNoLock`中有Drive Path(要一模一樣), return ![](https://i.imgur.com/hcDeT1O.png =300x) - 針對所有Drive Path底下的檔案及資料夾路徑, 若以下三點皆成立 ![](https://i.imgur.com/oWFLUJ6.png =400x) 1. 底下的file數量小於`MaxFileCount`(100) 2. 路徑中不包含`PathesToLock`中字串如下 ![](https://i.imgur.com/pRvqvhs.png =400x) 3. 資料夾`lastWriteTime`大於2018年1月1號 - 則加密除了下列副檔名(`ExtensionNoEncrypt`)以外的所有檔案 1. `.dll` 2. `.ocx` 3. `.msi` 4. `.iso` 5. `.mkv` 6. `.mov` 7. `.avi` 8. `.wmv` 9. `.m2ts` 10. `.mp3` 11. `.tmp` 12. `.gif` 13. `.人民法槌` (是已被加密的檔案的副檔名) 14. 沒有副檔名 - 若不符合上述三點條件(即 檔案數大於100 或 路徑包含`PathesToLock` 或 `lastWriteTime`在2018年之前),則只加密所有路徑下副檔名包含在`ExtensionsToEncrypt`的檔案 ![](https://i.imgur.com/LLlLaqj.png) - 加密方式 - `EncryptDirectory`使用之前長度32的random string用UTF8 encode之後取SHA256的Hash值作為AES-256加密的key ![](https://i.imgur.com/bbL7XgT.png =300x) - 若檔案大小小於`FileMaxSize`(10000000) ![](https://i.imgur.com/sLbcQoJ.png =300x) - 直接整個內容拿去AES加密,padding方式為PKCS#7 - 若檔案大小大於等於`FileMaxSize` ![](https://i.imgur.com/G22nLQ8.png =300x) - 每次讀取`BLOCK_SIZE=1000000`個byte進行AES加密, padding方式為補0 ㄌ - `AESEncrypt()`加密採用CBC模式, 並使用傳入的AESkey以及寫死的salt做1000次的iteration取得Rijndael進行AES加密所需要的key(32byte)及IV(16byte) ![](https://i.imgur.com/iIpc93i.png =150x) ![](https://i.imgur.com/dwx0VJL.png =400x) - 經過加密後的檔案檔名會被重新命名為`<原檔名>.人民法槌` ![](https://i.imgur.com/v78gg1K.png =300x) ![](https://i.imgur.com/Q0D0YTf.png =300x) 11. 在所有Drive Path下都寫入一個`How To Unlock Files.txt`檔案, 並在其中寫入包含`PersonalID`的`LockedMessage` 12. 之後還會再加密`%System Root%\Users\<username>`底下的檔案包含`%System Root%\Users\<username>\appdata`下的檔案 13. `WriteMessage()`原本會在`USER_PROFILE`下的`\\Appdata\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp\\`及`\\Desktop\\`中在各寫入一個`How To Unlock Files.txt`, ![](https://i.imgur.com/D0ATbyP.png =400x) 15. `TerminateDataBaseService()`終止所有正在run的資料庫服務 - mysql - mariadb - mssql - msexchageis - oracleservice ![](https://i.imgur.com/agO779R.png =400x) 以及會終止OUTLOOK程序的執行 ![](https://i.imgur.com/rtrDTO1.png =320x) 16. 最後ColdLock會修改感染系統的桌布 - 新桌布: 在`%System Root%\\programdata\\`下創建一個長度10的隨機字串作為`jpg`檔的檔名,並在其中寫入圖片內容(使用base64加密寫死在程式碼中) - `SetWallPaper`透過設定在登錄檔`\HKEY_USERS\<.DEFAULT/SID>\Control Panel\Desktop`的 - `Wallpaper`為剛剛存下的wall paper路徑(`%System Root%\\programdata\\<rand_str>.jpg`) - `WallpaperStyle`設定為2 - 並開啟一個`cmd` Process,執行"`RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True`"來即時刷新桌面 ![](https://i.imgur.com/u3O7AWX.png =450x) ## 在虛擬機執行 - 在dnSpy中想要用`edit Method` 將`AESEncryptFile()`中的程式碼全部patch掉,只留下修改附檔名的部分, 並且`file` > `Save Module`儲存patch - 這樣執行後檔案不會被加密,而`How To Unlock File.txt`被創建在下面三個路徑下 - `C:\` - `C:\Users\IEUser\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup` - `C:\Users\IEUser\Desktop` - 並且在`C:\ProgramData`中產生了`AzrCjNwREI.jpg`檔案及`readme.tmp` ![](https://i.imgur.com/TLM473F.png =350x) ![](https://i.imgur.com/PThN4qH.png =350x) ![](https://i.imgur.com/ES6qbso.png =350x) - 登錄檔中的`Wallpaper`及`WallpaperStyle`也被修改 ![](https://i.imgur.com/V01qMrF.png)