摘要

現代對外提供 Web 服務的地理空間伺服器,通常會公開功能豐富的圖徵查詢介面,整合檔案系統存取、XML 重新解析、以 Cookie 為基礎的驗證機制,以及可插拔的 JDBC 身分識別儲存服務。這份報告分析一條已有文件記錄的漏洞利用鏈,其中五個個別嚴重程度僅屬低至中等的缺陷——儲存資源識別碼缺少長度檢查、服務名稱比對方式不一致、XML 重新序列化錯誤導致已跳脫的標記重新生效、不依賴密碼驗證的 Cookie 簽章,以及不安全的 JDBC 物件讀取——最終串連成無須驗證即可執行遠端命令的攻擊途徑 [1] 。這份分析並未將每個缺陷視為獨立問題,而是追蹤前一個步驟的輸出如何成為下一個步驟的前置條件,並從中歸納多元件伺服器端系統設計者應注意的通用安全原則。
GeoServer驗證前RCE!JDBC反序列化如何成為入侵突破口? | 資訊安全新聞

1. 簡介

允許匿名用戶端將伺服器端「已儲存查詢」保存下來的圖徵查詢服務,是 Web Feature Service(WFS) 規範中相當便利的擴充功能,但同時也大幅擴大了登入前的攻擊面:每一條在登入前即可存取的程式路徑,都必須各自抵禦 Path Traversal、標記注入及型別混淆攻擊。這起案例顯示,單一資源命名函式、單一服務分派捷徑,以及單一 JDBC 便利方法,即使各自獨立來看都有其合理性,仍可能被組合利用,完全繞過驗證機制,最終達成任意命令執行 [1] 。以下將依照攻擊者實際利用的順序,逐一檢視五個根本原因,透過逐行註解重現相關程式碼,並將每項缺陷歸納至既有的 Web 安全及反序列化漏洞類別中 [4][5] 。

2. 攻擊流程概述

在檢視個別程式路徑之前,先了解五個階段之間的控制流程與資料流向相當重要,因為單一漏洞本身並不足以完成整個攻擊。下圖分析將五個階段建模為匿名用戶端與伺服器內部子系統之間的訊息交換 [1] 。

sequenceDiagram participant Client as Anonymous Client participant WFS as WFS Dispatcher participant FS as Filesystem Resource Store participant Parser as Stored-Query Reload Parser participant Auth as Remember-Me Auth participant REST as REST / JDBC Service participant DB as HSQLDB Driver Client->>FS: GetFeature storedQuery_id (oversized) FS-->>Client: Exception text reveals data directory path Client->>WFS: service=x/WFS CreateStoredQuery (escaped xi:include) WFS-->>Client: Query accepted, access rule not matched Client->>Parser: DescribeStoredQueries (public, anonymous) Parser-->>Client: Reparsed xi:include returns config.xml and users.xml Client->>Auth: Cookie signed from leaked key and password digest Auth-->>Client: Administrator session accepted Client->>REST: Upload HSQLDB file, register JDBC user service REST->>DB: User-property lookup (getObject on OTHER column) DB-->>REST: ObjectInputStream.readObject executes attacker graph REST-->>Client: Shell command output returned

3. 程式碼層級分析

3.1 檔名建構時未限制識別碼長度(CVE-2026-129244)

第一個階段將一般的讀取錯誤轉變為資訊洩漏。已儲存查詢的識別碼會直接轉換成檔名,過程中沒有設定長度限制,因此攻擊者可以刻意觸發底層檔案系統呼叫失敗,而產生的例外訊息(包括完整路徑)則會被序列化後回傳給用戶端 [1] 。

  1. // toFilename(): builds the on-disk filename from the untrusted query name
  2. String toFilename(String name) {
  3. // Strips characters that are not word characters (not a defense against length),
  4. // then appends a fixed extension. No upper bound is enforced on "name" here,
  5. // so an attacker can submit thousands of characters.
  6. return name.replaceAll("\\W", "") + ".xml";
  7. }
  8. // getType(): queries filesystem metadata for the constructed path
  9. public Type getType() {
  10. try {
  11. // Over-long paths cause the OS/JVM to throw an IOException such as
  12. // "File name too long" rather than a simple "not found" result.
  13. BasicFileAttributes attributes =
  14. java.nio.file.Files.readAttributes(file.toPath(), BasicFileAttributes.class);
  15. // ... normal branch when the path resolves successfully (omitted)
  16. } catch (NoSuchFileException e) {
  17. // A genuinely missing file is handled quietly.
  18. return Type.UNDEFINED;
  19. } catch (IOException e) {
  20. // Any other I/O failure, including "name too long", is wrapped and
  21. // rethrown so the original message (and therefore the full path) survives.
  22. throw new IllegalStateException(e);
  23. }
  24. }
  25. // dumpExceptionMessages(): collects every nested exception message for the response
  26. OwsUtils.dumpExceptionMessages(exception, sb, true);
  27. // Walking the full cause chain means the filesystem's own error string,
  28. // which names the absolute path it tried to open, is concatenated into "sb".
  29. e.getExceptionText().add(sb.toString());
  30. // That string is then placed into the public OWS exception response body,
  31. // disclosing the server's data directory to an unauthenticated caller.

這是典型的 詳細錯誤處理 問題:程式碼為了保留診斷資訊(保留原始錯誤原因),卻犧牲了機密性,因為例外訊息未經過濾,就直接傳送給匿名網路呼叫者。

3.2 移除前綴後才進行服務名稱比對(CVE-2026-129243)

設定檔中的存取控制規則會透過完全相同的名稱比對服務識別碼,但負責解析應呼叫哪個實作的分派器,卻允許識別碼帶有斜線前綴;另一方面,負責執行存取控制的元件仍然使用未修改、帶有前綴的原始字串進行比對 [1] 。

  1. // findService(): resolves which backend service implementation handles the request
  2. Service findService(String id, String ver, String namespace) throws ServiceException {
  3. if (id.contains("/")) {
  4. // Treats everything before the slash as path/workspace context and
  5. // discards it, so "x/WFS" and "WFS" resolve to the same implementation.
  6. id = id.substring(id.indexOf("/") + 1);
  7. }
  8. for (Service sBean : services) {
  9. // Case-insensitive match against the now-stripped id finds the real WFS service.
  10. if (sBean.getId().equalsIgnoreCase(id)) {
  11. matches.add(sBean);
  12. }
  13. }
  14. // ... selection among matches omitted
  15. }
  16. // operationDispatched(): the security callback that should block anonymous writes
  17. public Operation operationDispatched(Request request, Operation operation) {
  18. // request.getService() still returns the ORIGINAL, unstripped value ("x/WFS"),
  19. // because only the internal service-resolution step normalized it.
  20. String service = request.getService();
  21. String method = request.getRequest();
  22. for (ServiceAccessRule rule : rules) {
  23. // The configured rule's service name is "wfs" (lower-case, no prefix),
  24. // so a case-insensitive comparison against "x/WFS" never matches.
  25. if (rule.getService().equals(ServiceAccessRule.ANY)
  26. || rule.getService().equalsIgnoreCase(service)) {
  27. if (rule.getMethod().equals(ServiceAccessRule.ANY)
  28. || rule.getMethod().equalsIgnoreCase(method)) {
  29. bestMatch = rule;
  30. }
  31. }
  32. }
  33. // With no match found, the role requirement attached to the rule is
  34. // never applied, so the operation proceeds without an authorization check.
  35. if (bestMatch != null) {
  36. // ... role enforcement, skipped entirely when bestMatch is null
  37. }
  38. }

這是典型的 「解析器差異」(parser differential) :兩個元件對同一個輸入推導出不同的標準化形式,但安全判斷卻使用了錯誤的形式。

3.3 對已跳脫標記進行解碼後重新解析(CVE-2026-120705)

XInclude 原本是 XML 用於將外部子資源(sub-resource)組合進文件中的合法功能;然而,一旦用戶端提供的跳脫標記內容先被解除跳脫並儲存,之後又被當成可信任的 XML 結構重新解析,XInclude 處理便可能成為攻擊途徑 [1] [4] 。

  1. // characters(): SAX callback invoked while parsing the incoming request body
  2. public void characters(char[] ch, int start, int length) throws SAXException {
  3. // The XML parser has already converted "<xi:include .../>" text in the
  4. // request into a literal "<xi:include .../>" character sequence. This
  5. // handler appends that decoded text verbatim into an internal buffer,
  6. // with no re-escaping before the value is persisted.
  7. buffer.append(ch, start, length);
  8. }
  9. // encode(): runs when the accepted stored query is written to disk
  10. SAXParser saxp = XMLUtils.newSAXParserFactory(null).newSAXParser();
  11. // The buffered text (now containing a literal "<xi:include>") is fed back
  12. // into a SAX parser as if it were markup rather than character data,
  13. // so the previously inert text becomes a live, executable XML construct.
  14. saxp.parse(new InputSource(new StringReader(qe.getValue())), h);
  15. Document d = h.getDocument();
  16. e.appendChild(document.importNode(d.getDocumentElement(), true));
  17. // setXIncludeAware(): configures the parser used when the stored file is reloaded
  18. factory.setXIncludeAware(!supportDTD);
  19. // DTD support is disabled for safety, but this line ties XInclude processing
  20. // directly to that same flag, so disabling DTDs inadvertently enables XInclude,
  21. // letting the previously injected <xi:include href="file:///..."> resolve
  22. // local files such as the security configuration and user-credential store.

「解碼一次、儲存,然後重新解析」是已知的 Double-Decode 漏洞來源;在這起案例中,由於重新載入時使用的實體解析控制比第一次解析更寬鬆,因此原本的標記注入能力進一步轉變成讀取本機檔案的能力。

3.4 不依賴密碼驗證的 Cookie 簽章(CVE-2026-129245)

從前一個階段取得的偽造認證資料,已足以產生有效的驗證 Cookie,完全不需要透過登入表單驗證這些資料。原因在於簽章演算法將儲存的密碼摘要視為一般輸入位元組字串,而不是必須透過比對程序驗證的秘密資訊 [1] 。

  1. // makeTokenSignature(): computes the HMAC-like signature embedded in the cookie
  2. protected String makeTokenSignature(long tokenExpiryTime, String username,
  3. String password, RememberMeTokenAlgorithm algorithm) {
  4. // The signature input concatenates the username, an expiry timestamp,
  5. // the stored password digest, and a server-wide signing key. Crucially,
  6. // nothing here re-derives the password from a user-supplied secret;
  7. // the digest is simply read from storage and hashed alongside the key.
  8. String data = username + ":" + tokenExpiryTime + ":" + password + ":" + getKey();
  9. MessageDigest digest = MessageDigest.getInstance(algorithm.getDigestAlgorithm());
  10. // Anyone who already knows both the digest and the key (both of which
  11. // were disclosed in the prior stage) can compute this exact value
  12. // without ever possessing the plaintext password.
  13. return new String(Hex.encode(digest.digest(data.getBytes())));
  14. }

這項設計假設兩項輸入都能持續保持機密;一旦任何能獨立取得這些資料的管道(在這起案例中是檔案資訊洩漏)遭到入侵,密碼運算本身就無法提供額外防護,因為它原本就不是用來驗證即時提供的認證資料,而只是將先前已完成驗證的 Session 綁定至簽署過的 Token。

3.5 從資料庫欄位觸發 Driver 層級的物件重建(CVE-2026-129242)

最後一個階段會達成完整的命令執行,原因在於通用欄位讀取方法針對特定 SQL 型別,會在沒有明確提示的情況下觸發原生物件反序列化,而且反序列化過程完全沒有過濾重建後的類別圖 [1] [5] 。

  1. // user-property loop inside the JDBC-backed identity service
  2. ps2 = getDMLStatement("userprops.selectForUser", con);
  3. ps2.setString(1, username);
  4. rs2 = ps2.executeQuery();
  5. while (rs2.next()) {
  6. String propName = rs2.getString(1);
  7. // getObject() delegates entirely to the driver's own type mapping;
  8. // for an OTHER/JAVA_OBJECT column the driver does not return a string
  9. // or primitive, it reconstructs a live Java object from stored bytes.
  10. Object propValue = rs2.getObject(2);
  11. u.getProperties().put(propName, propValue == null ? "" : propValue);
  12. }
  13. // driver-side conversion for an OTHER-typed column
  14. case Types.OTHER:
  15. case Types.JAVA_OBJECT: {
  16. Object o = getColumnInType(columnIndex, sourceType);
  17. // The raw column bytes are handed to a helper whose only job is to
  18. // turn them back into an object, with no inspection of what class
  19. // that object will be.
  20. return ((JavaObjectData) o).getObject();
  21. }
  22. // JavaObjectData.getObject() and the underlying stream construction
  23. public Object getObject() {
  24. return InOutUtil.deserialize(data);
  25. }
  26. public static Serializable deserialize(byte[] ba) throws IOException, ClassNotFoundException {
  27. HsqlByteArrayInputStream bi = new HsqlByteArrayInputStream(ba);
  28. // A plain ObjectInputStream is created with no resolveClass() override
  29. // and no allow-list filter attached, so any serializable class present
  30. // on the application's classpath can be instantiated from these bytes.
  31. ObjectInputStream is = new ObjectInputStream(bi);
  32. // readObject() rebuilds the entire attacker-chosen object graph,
  33. // including objects whose field-restoration logic triggers further
  34. // method calls (gadget chains) culminating in command execution.
  35. return (Serializable) is.readObject();
  36. }

這再次印證了原生 Java 序列化長期以來的安全教訓:任何會直接從不受信任的位元組中回傳反序列化物件的 API,即使只是看似普通的資料庫欄位 getter,也會重新引入與直接反序列化網路 Payload 相同的風險類別,因為 readObject() 在重建物件之前不會執行型別驗證 [5] 。

4. 討論

個別來看,每項缺陷都能對應到常見的漏洞類別:詳細錯誤訊息洩漏、不一致的輸入正規化、不安全的 XML 重新解析、假設輸入資料保密而非驗證即時認證資訊的簽章設計,以及未經檢查的原生反序列化。單獨來看,這些問題通常都不會被評定為重大漏洞;但當它們串連在一起時,匿名網路用戶端與命令執行之間的所有驗證界線都會被移除。最重要的工程經驗是:當兩個元件對相同數值的標準化形式(服務名稱、檔名、解碼後的文字)產生不同認知時,深度防禦的假設就會失效——每個元件單獨來看可能都「正確」,但組合起來卻不再安全 [1] 。

5. 結論

這條漏洞利用鏈說明,Pre-Authentication 遠端程式碼執行可能不是來自單一重大漏洞,而是多個可以獨立修補的缺陷組合而成。將通用物件 getter 替換為具備明確型別的存取方法、確保第一次解析與重新載入時使用一致的實體解析器、在每次存取控制判斷之前先將識別碼正規化、在使用檔案系統之前限制識別碼長度,以及使用不依賴磁碟儲存資料的方式獨立推導簽署 key,都能分別切斷攻擊鏈中的一個環節;只要移除其中任何一個環節,就足以阻止這裡描述的完整漏洞利用路徑 [1] 。