GeoServer驗證前RCE!
摘要
1. 簡介
允許匿名用戶端將伺服器端「已儲存查詢」保存下來的圖徵查詢服務,是 Web Feature Service(WFS) 規範中相當便利的擴充功能,但同時也大幅擴大了登入前的攻擊面:每一條在登入前即可存取的程式路徑,都必須各自抵禦 Path Traversal、標記注入及型別混淆攻擊。這起案例顯示,單一資源命名函式、單一服務分派捷徑,以及單一 JDBC 便利方法,即使各自獨立來看都有其合理性,仍可能被組合利用,完全繞過驗證機制,最終達成任意命令執行 [1] 。以下將依照攻擊者實際利用的順序,逐一檢視五個根本原因,透過逐行註解重現相關程式碼,並將每項缺陷歸納至既有的 Web 安全及反序列化漏洞類別中 [4][5] 。
2. 攻擊流程概述
在檢視個別程式路徑之前,先了解五個階段之間的控制流程與資料流向相當重要,因為單一漏洞本身並不足以完成整個攻擊。下圖分析將五個階段建模為匿名用戶端與伺服器內部子系統之間的訊息交換 [1] 。
3. 程式碼層級分析
3.1 檔名建構時未限制識別碼長度(CVE-2026-129244)
第一個階段將一般的讀取錯誤轉變為資訊洩漏。已儲存查詢的識別碼會直接轉換成檔名,過程中沒有設定長度限制,因此攻擊者可以刻意觸發底層檔案系統呼叫失敗,而產生的例外訊息(包括完整路徑)則會被序列化後回傳給用戶端 [1] 。
- // toFilename(): builds the on-disk filename from the untrusted query name
- String toFilename(String name) {
- // Strips characters that are not word characters (not a defense against length),
- // then appends a fixed extension. No upper bound is enforced on "name" here,
- // so an attacker can submit thousands of characters.
- return name.replaceAll("\\W", "") + ".xml";
- }
- // getType(): queries filesystem metadata for the constructed path
- public Type getType() {
- try {
- // Over-long paths cause the OS/JVM to throw an IOException such as
- // "File name too long" rather than a simple "not found" result.
- BasicFileAttributes attributes =
- java.nio.file.Files.readAttributes(file.toPath(), BasicFileAttributes.class);
- // ... normal branch when the path resolves successfully (omitted)
- } catch (NoSuchFileException e) {
- // A genuinely missing file is handled quietly.
- return Type.UNDEFINED;
- } catch (IOException e) {
- // Any other I/O failure, including "name too long", is wrapped and
- // rethrown so the original message (and therefore the full path) survives.
- throw new IllegalStateException(e);
- }
- }
- // dumpExceptionMessages(): collects every nested exception message for the response
- OwsUtils.dumpExceptionMessages(exception, sb, true);
- // Walking the full cause chain means the filesystem's own error string,
- // which names the absolute path it tried to open, is concatenated into "sb".
- e.getExceptionText().add(sb.toString());
- // That string is then placed into the public OWS exception response body,
- // disclosing the server's data directory to an unauthenticated caller.
這是典型的 詳細錯誤處理 問題:程式碼為了保留診斷資訊(保留原始錯誤原因),卻犧牲了機密性,因為例外訊息未經過濾,就直接傳送給匿名網路呼叫者。
3.2 移除前綴後才進行服務名稱比對(CVE-2026-129243)
設定檔中的存取控制規則會透過完全相同的名稱比對服務識別碼,但負責解析應呼叫哪個實作的分派器,卻允許識別碼帶有斜線前綴;另一方面,負責執行存取控制的元件仍然使用未修改、帶有前綴的原始字串進行比對 [1] 。
- // findService(): resolves which backend service implementation handles the request
- Service findService(String id, String ver, String namespace) throws ServiceException {
- if (id.contains("/")) {
- // Treats everything before the slash as path/workspace context and
- // discards it, so "x/WFS" and "WFS" resolve to the same implementation.
- id = id.substring(id.indexOf("/") + 1);
- }
- for (Service sBean : services) {
- // Case-insensitive match against the now-stripped id finds the real WFS service.
- if (sBean.getId().equalsIgnoreCase(id)) {
- matches.add(sBean);
- }
- }
- // ... selection among matches omitted
- }
- // operationDispatched(): the security callback that should block anonymous writes
- public Operation operationDispatched(Request request, Operation operation) {
- // request.getService() still returns the ORIGINAL, unstripped value ("x/WFS"),
- // because only the internal service-resolution step normalized it.
- String service = request.getService();
- String method = request.getRequest();
- for (ServiceAccessRule rule : rules) {
- // The configured rule's service name is "wfs" (lower-case, no prefix),
- // so a case-insensitive comparison against "x/WFS" never matches.
- if (rule.getService().equals(ServiceAccessRule.ANY)
- || rule.getService().equalsIgnoreCase(service)) {
- if (rule.getMethod().equals(ServiceAccessRule.ANY)
- || rule.getMethod().equalsIgnoreCase(method)) {
- bestMatch = rule;
- }
- }
- }
- // With no match found, the role requirement attached to the rule is
- // never applied, so the operation proceeds without an authorization check.
- if (bestMatch != null) {
- // ... role enforcement, skipped entirely when bestMatch is null
- }
- }
這是典型的 「解析器差異」(parser differential) :兩個元件對同一個輸入推導出不同的標準化形式,但安全判斷卻使用了錯誤的形式。
3.3 對已跳脫標記進行解碼後重新解析(CVE-2026-120705)
XInclude 原本是 XML 用於將外部子資源(sub-resource)組合進文件中的合法功能;然而,一旦用戶端提供的跳脫標記內容先被解除跳脫並儲存,之後又被當成可信任的 XML 結構重新解析,XInclude 處理便可能成為攻擊途徑 [1] [4] 。
- // characters(): SAX callback invoked while parsing the incoming request body
- public void characters(char[] ch, int start, int length) throws SAXException {
- // The XML parser has already converted "<xi:include .../>" text in the
- // request into a literal "<xi:include .../>" character sequence. This
- // handler appends that decoded text verbatim into an internal buffer,
- // with no re-escaping before the value is persisted.
- buffer.append(ch, start, length);
- }
- // encode(): runs when the accepted stored query is written to disk
- SAXParser saxp = XMLUtils.newSAXParserFactory(null).newSAXParser();
- // The buffered text (now containing a literal "<xi:include>") is fed back
- // into a SAX parser as if it were markup rather than character data,
- // so the previously inert text becomes a live, executable XML construct.
- saxp.parse(new InputSource(new StringReader(qe.getValue())), h);
- Document d = h.getDocument();
- e.appendChild(document.importNode(d.getDocumentElement(), true));
- // setXIncludeAware(): configures the parser used when the stored file is reloaded
- factory.setXIncludeAware(!supportDTD);
- // DTD support is disabled for safety, but this line ties XInclude processing
- // directly to that same flag, so disabling DTDs inadvertently enables XInclude,
- // letting the previously injected <xi:include href="file:///..."> resolve
- // local files such as the security configuration and user-credential store.
「解碼一次、儲存,然後重新解析」是已知的 Double-Decode 漏洞來源;在這起案例中,由於重新載入時使用的實體解析控制比第一次解析更寬鬆,因此原本的標記注入能力進一步轉變成讀取本機檔案的能力。
3.4 不依賴密碼驗證的 Cookie 簽章(CVE-2026-129245)
從前一個階段取得的偽造認證資料,已足以產生有效的驗證 Cookie,完全不需要透過登入表單驗證這些資料。原因在於簽章演算法將儲存的密碼摘要視為一般輸入位元組字串,而不是必須透過比對程序驗證的秘密資訊 [1] 。
- // makeTokenSignature(): computes the HMAC-like signature embedded in the cookie
- protected String makeTokenSignature(long tokenExpiryTime, String username,
- String password, RememberMeTokenAlgorithm algorithm) {
- // The signature input concatenates the username, an expiry timestamp,
- // the stored password digest, and a server-wide signing key. Crucially,
- // nothing here re-derives the password from a user-supplied secret;
- // the digest is simply read from storage and hashed alongside the key.
- String data = username + ":" + tokenExpiryTime + ":" + password + ":" + getKey();
- MessageDigest digest = MessageDigest.getInstance(algorithm.getDigestAlgorithm());
- // Anyone who already knows both the digest and the key (both of which
- // were disclosed in the prior stage) can compute this exact value
- // without ever possessing the plaintext password.
- return new String(Hex.encode(digest.digest(data.getBytes())));
- }
這項設計假設兩項輸入都能持續保持機密;一旦任何能獨立取得這些資料的管道(在這起案例中是檔案資訊洩漏)遭到入侵,密碼運算本身就無法提供額外防護,因為它原本就不是用來驗證即時提供的認證資料,而只是將先前已完成驗證的 Session 綁定至簽署過的 Token。
3.5 從資料庫欄位觸發 Driver 層級的物件重建(CVE-2026-129242)
最後一個階段會達成完整的命令執行,原因在於通用欄位讀取方法針對特定 SQL 型別,會在沒有明確提示的情況下觸發原生物件反序列化,而且反序列化過程完全沒有過濾重建後的類別圖 [1] [5] 。
- // user-property loop inside the JDBC-backed identity service
- ps2 = getDMLStatement("userprops.selectForUser", con);
- ps2.setString(1, username);
- rs2 = ps2.executeQuery();
- while (rs2.next()) {
- String propName = rs2.getString(1);
- // getObject() delegates entirely to the driver's own type mapping;
- // for an OTHER/JAVA_OBJECT column the driver does not return a string
- // or primitive, it reconstructs a live Java object from stored bytes.
- Object propValue = rs2.getObject(2);
- u.getProperties().put(propName, propValue == null ? "" : propValue);
- }
- // driver-side conversion for an OTHER-typed column
- case Types.OTHER:
- case Types.JAVA_OBJECT: {
- Object o = getColumnInType(columnIndex, sourceType);
- // The raw column bytes are handed to a helper whose only job is to
- // turn them back into an object, with no inspection of what class
- // that object will be.
- return ((JavaObjectData) o).getObject();
- }
- // JavaObjectData.getObject() and the underlying stream construction
- public Object getObject() {
- return InOutUtil.deserialize(data);
- }
- public static Serializable deserialize(byte[] ba) throws IOException, ClassNotFoundException {
- HsqlByteArrayInputStream bi = new HsqlByteArrayInputStream(ba);
- // A plain ObjectInputStream is created with no resolveClass() override
- // and no allow-list filter attached, so any serializable class present
- // on the application's classpath can be instantiated from these bytes.
- ObjectInputStream is = new ObjectInputStream(bi);
- // readObject() rebuilds the entire attacker-chosen object graph,
- // including objects whose field-restoration logic triggers further
- // method calls (gadget chains) culminating in command execution.
- return (Serializable) is.readObject();
- }
這再次印證了原生 Java 序列化長期以來的安全教訓:任何會直接從不受信任的位元組中回傳反序列化物件的 API,即使只是看似普通的資料庫欄位 getter,也會重新引入與直接反序列化網路 Payload 相同的風險類別,因為
readObject()
在重建物件之前不會執行型別驗證
[5]
。
4. 討論
個別來看,每項缺陷都能對應到常見的漏洞類別:詳細錯誤訊息洩漏、不一致的輸入正規化、不安全的 XML 重新解析、假設輸入資料保密而非驗證即時認證資訊的簽章設計,以及未經檢查的原生反序列化。單獨來看,這些問題通常都不會被評定為重大漏洞;但當它們串連在一起時,匿名網路用戶端與命令執行之間的所有驗證界線都會被移除。最重要的工程經驗是:當兩個元件對相同數值的標準化形式(服務名稱、檔名、解碼後的文字)產生不同認知時,深度防禦的假設就會失效——每個元件單獨來看可能都「正確」,但組合起來卻不再安全 [1] 。
5. 結論
這條漏洞利用鏈說明,Pre-Authentication 遠端程式碼執行可能不是來自單一重大漏洞,而是多個可以獨立修補的缺陷組合而成。將通用物件 getter 替換為具備明確型別的存取方法、確保第一次解析與重新載入時使用一致的實體解析器、在每次存取控制判斷之前先將識別碼正規化、在使用檔案系統之前限制識別碼長度,以及使用不依賴磁碟儲存資料的方式獨立推導簽署 key,都能分別切斷攻擊鏈中的一個環節;只要移除其中任何一個環節,就足以阻止這裡描述的完整漏洞利用路徑 [1] 。