Ray遭利用!
摘要
專為 AI workloads 打造的 GPU cluster ,是極具吸引力的挖礦攻擊目標,因為其資源使用率原本就預期維持在高水位,而且監控機制通常受到信任。本文研究一套 Linux 工具組,其核心由 Rust Orchestrator、經修改的 NVIDIA 管理函式庫 、 ftrace Rootkit ,以及以 區塊鏈 為輔助的 Backdoor 所組成,並分析其如何消除防禦者平時仰賴的各種偵測跡象 [1] 。
1. 入侵途徑與 Threat Model
入侵是從 Orchestration Layer 開始,而非作業系統。網路可存取一個 Ray job agent ,且該 agent 接受未經認證的 Job submission,即使 Head Node 上的 Dashboard 只監聽 Loopback 介面也是如此 [1] 。由於 Jobs API 的用途就是在 cluster 上執行任意命令,因此暴露的 agent 等同於設計上就具備 Remote Code Execution 能力。Threat actor 首先執行 GPU 資訊查詢,接著啟動 Python Reverse shell,最後植入 SSH key 以維持持續性 [1] 。這帶來一項架構層面的教訓:分散式運算 Framework 的信任邊界必須透過其網路暴露範圍與認證機制來強制執行,因為主機無法區分合法 Job 與惡意 Job。
2. Control Plane:以 Tor 為基礎的 Orchestrator
Orchestrator
sansar
是一個 Rust Client,使用
Arti Library
處理
Tor
,並監督兩個公開的 Miner:用於 CPU 運算的
XMRig
,以及用於 GPU 運算的 SRBMiner-MULTI
[1]
。其設計展現了三項刻意採用的策略。
抵抗分析(Analysis resistance)。
在建立網路連線之前,它會讀取
/proc/self/status
,當
TracerPid
不為 0 時便退出;此外,若執行 1,000 次迴圈耗時達 501 ms 或更久,也會退出,藉此偵測使用
ptrace 除錯器
及執行速度較慢的 instrumentation
[1]
。Onion hostname 以 62 個編碼位元組儲存,並在執行時透過 Listing 1 所示的 routine 解碼。
- // Listing 1 - hostname decoder, applied once per stored byte
- plaintext[i] = // decoded hostname byte at index i
- ROR8(ciphertext[i], // rotate the stored byte right inside an 8-bit register
- (i % 7) + 1) // rotation distance cycles through 1..7 as the index grows
- XOR mask[i % 32]; // then XOR with a byte of the repeating 32-byte mask
具韌性的傳輸機制(Resilient transport)。 WebTunnel 與 obfs4 的 Bridge 清單讓 Client 即使在直接存取遭到過濾的環境下,仍可連線至 Tor。Direct mode 提供 60 秒的 Bootstrap 時間,而 Bridge mode 則提供 900 秒,兩者最終都會連線至相同的 Onion Service [1] 。Registration 會傳送一個 40-byte 欄位,其中包含 Timestamp,以及針對 Client ID 與 Timestamp 計算的 HMAC-SHA256 Digest,因此 Controller 能夠拒絕未經認證的 Client [1] 。
精簡的 Binary Protocol。 Frame 使用 Big-Endian 長度、Little-Endian Message Type,以及具型別的 Payload(Listing 2)。長度欄位涵蓋 Type 與 Payload,但不包含長度欄位自身 [1] 。
- // Listing 2 - C2 frame layout
- typedef struct { // begin the frame definition
- uint8_t body_length[4]; // 4-byte big-endian length of type plus payload
- uint8_t message_type_id[4]; // 4-byte little-endian command identifier (0-15)
- uint8_t payload[]; // variable payload whose layout depends on the type
- } sansar_c2_comm_frame; // name of the frame type
16 種 Command Type 涵蓋 Registration、Bridge 更新、在停用 History 的 Pseudo-terminal 中進行互動式 Bash Session、SYN 流量產生,以及 Miner 的啟動、停止與重新設定 [1] 。Miner Type 0 選擇 GPU Binary,Type 1 選擇 CPU Binary;Pool 與 Wallet 都沒有 hardcoded,因此 Operator 無須修改主機即可變更收益接收目的地 [1] 。Figure 1 彙整了典型的 Session。
3. 偽造 GPU Telemetry
大多數 GPU 監控工具,包括
nvidia-smi
,都會呼叫 User-space
NVML Library
。這套工具將
libnvidia-ml.so.1
替換成 Wrapper,Wrapper 會將每個呼叫轉送至真正的 Library,接著修改選定的結果:使用率變成 0%、溫度變成隨機的 36–46 °C,而功耗則變成隨機的 100–200 W
[1]
。真正的 Versioned Library 仍保留供 Backend 呼叫使用,並且會建立 Backup,因此這項替換能夠躲過一般檢查
[1]
。這項技術的弱點也是其限制:它只能欺騙載入 User-space NVML 的工具。機架上的電力消耗、風扇運作狀況,或 Vendor-independent Counter 等 Out-of-band 訊號仍會呈現真實資訊。
4. 使用 ftrace 進行 Kernel 層級隱藏
模組
acpi_thermal_mgr.ko
會 Hook
getdents64
、
openat
、
kill
,以及產生 TCP 和 UDP socket 清單的 routines
[1]
。相較於修改 Syscall Table,攻擊者更偏好 ftrace,因為 Kernel 已經提供 Hook Points,因此無須重新改寫 Machine Code
[2]
。該模組也會寫入 initramfs,以便在開機時重新載入
[1]
。
Listing 3 展示 Directory Filtering。當隱藏的紀錄位於最前面時,會透過移動 Buffer 將其移除;如果隱藏的紀錄位於其他位置,則會延長前一筆紀錄的長度,使 User-space Parser 跳過隱藏紀錄 [1] 。
- // Listing 3 - directory-entry filtering in hook_getdents64
- offset = 0; // start at the first record of the kernel-side copy
- prev = NULL; // no visible record has been seen yet
- while (offset < ret) { // loop until every returned byte has been examined
- cur = (void *)kdirent + offset; // point at the record at the current offset
- if (should_hide_dirent(cur->d_name, strlen(cur->d_name))) { // does the name match a hidden PID or prefix?
- if (!prev) { // the hidden record is the first in the buffer
- ret -= cur->d_reclen; // shrink the total size by this record's length
- memmove(cur, (void *)cur + cur->d_reclen, ret - offset); // slide the remaining records over it
- continue; // re-check whatever now sits at this offset
- }
- prev->d_reclen += cur->d_reclen; // otherwise let the previous record swallow this one
- } else { // the record is not hidden
- prev = cur; // remember it as the last visible record
- }
- offset += cur->d_reclen; // advance to the next record
- }
- copy_to_user(udirent, kdirent, ret); // hand the filtered buffer back to the caller
另外也會封鎖直接存取。開啟隱藏的
/proc/<pid>
Path,或最後一個元件符合
hide_prefix
的檔案時,會回傳
ENOENT
(Listing 4);PID 查詢則會回傳
ESRCH
[1]
。
- // Listing 4 - path checks in hook_openat
- fn[PATH_MAX - 1] = '\0'; // force NUL termination of the copied user path
- if (is_proc_path_hidden(fn)) { // is this a /proc entry belonging to a hidden PID?
- kfree(fn); // release the temporary path buffer
- return -ENOENT; // pretend the file does not exist
- }
- bn = strrchr(fn, '/'); // locate the last path separator
- bn = bn ? bn + 1 : fn; // take the final component, or the whole string if none
- if (is_file_hidden(bn, strlen(bn))) { // does the basename match the hidden prefix?
- kfree(fn); // release the buffer before leaving
- return -ENOENT; // report a missing file
- }
- kfree(fn); // release the buffer on the normal path
- return orig_openat(regs); // otherwise run the genuine openat
kill
Hook 中的一項例外揭露了 Operator 的設計(Listing 5):隱藏的程序會拒絕所有 Signal,除非 Signal 是由設定的 Manager Name 所送出,因此 Orchestrator 仍然可以控制已被隱藏的 Miner
[1]
。
- // Listing 5 - selective signal handling in the kill hook
- if (is_pid_hidden(pid)) { // is the target PID on the hidden list?
- /* The orchestrator must be able to manage its own child processes.
- * If the caller's command name equals hide_name, allow the signal. */
- get_task_comm(caller_comm, current); // copy the calling task's command name
- if (hide_name[0] && strncmp(caller_comm, hide_name, TASK_COMM_LEN) == 0) // is hide_name set and equal to the caller?
- return orig_kill(regs); // yes: forward the signal to the real syscall
- return -ESRCH; // no: answer as if the process does not exist
- }
- return orig_kill(regs); // non-hidden targets behave normally
5. 區塊鏈 Dead-Drop Backdoor
另一個 Backdoor
netns
避免將 Controller hardcoded。它會透過公開的 Ethereum RPC Endpoint,對內嵌的 Contract 發出
eth_call
Request,解碼回應中的 IPv4 Address,並透過 TCP Port 8080 進行連線
[1]
。Controller 會傳送
SHELL <host> <port>
,Backdoor 接著 Fork Bash,並透過新的 Outbound Connection 連線至指定目的地,該目的地可能與 Controller 本身不同
[1]
。Command Loop 沒有認證或完整性檢查
[1]
。透過更新 Contract 來輪替 Address,使得針對固定 Infrastructure 的 Takedown 無法有效奏效;而連線至公開 RPC Service 的 HTTPS 流量,則能混入一般 Application Traffic 中。
6. 防禦上的影響
這項分析提出三項防禦措施。第一,對 Job Submission Interface 實施認證並進行 Network Isolation,同時稽核有權送出 Work 的人員。第二,驗證 Monitoring Library 的完整性,例如將
libnvidia-ml.so.1
的 hash 與 Vendor Package 比對,並檢查 Loader Cache。第三,透過獨立來源交叉驗證主機呈現的資訊:即使 Kernel 在
/proc
中隱藏 Entry,仍可能被電力監測、Memory Forensics,或從 Guest 外部取得的資訊所揭露。檢查 ftrace 狀態能更容易偵測以 Hook 為基礎的隱藏技術,其他 Open-source ftrace rootkit 也提到類似觀點
[2]
。行為偵測同樣有助於防禦,因為樣本對外的 Tor 與 Bridge Traffic,以及連線至 Mining Pool 的流量,仍然能在 Network Edge 被觀察到。
7. 結論
這套工具並非依賴單一技巧,而是將未經認證的 Orchestration Entry Point、匿名化且經過認證的 Control Channel、User-space 與 Kernel-space 對資源使用量的偽造,以及去中心化的備援 Channel 組合在一起 [1] 。防禦者應將 Monitoring Output 視為不可信任的 Input,並透過主機難以偽造的訊號進行交叉驗證。