前言
最近一直在對剛研發(fā)出來的自動化Web/API漏洞Fuzz的命令行掃描工具進行維護更新(工具地址:https://github.com/StarCrossPortal/scalpel),目前掃描工具已更新至第三個版本,新增了5條2022年CVE漏洞POC,修復了例如Content-
Type和body類型不一致等問題。最新版本測試穩(wěn)定,滿足Web/API的漏洞Fuzz和多場景的漏洞檢測,歡迎大家試用。
在維護更新掃描器POC庫時,筆者看到了這個被稱為“Textshell”的CVE漏洞,決定學習分析一波。
項目介紹
Apache Commons Text 是一個低級庫,用于執(zhí)行各種文本操作,例如轉義、計算字符串差異以及用通過插值器查找的值替換文本中的占位符。
漏洞描述
2022年10月13號,官方發(fā)布了Apache Commons Text的漏洞通告,漏洞編號:CVE-2022-42889。Apache Commons
Text
執(zhí)行變量插值,允許動態(tài)評估和擴展屬性。插值的標準格式是“${prefix:name}”,其中“prefix”用于定位執(zhí)行插值的。org.apache.commons.text.lookup.StringLookup
的實例。從 1.5 版到 1.9 版,攻擊者可構造惡意文本,使得Apache Commons Text 在解析時執(zhí)行任意惡意代碼。
利用范圍
1.5 <= Apache Commons Text <= 1.9
漏洞分析
環(huán)境搭建
IDEA 通過Maven導入依賴
pom.xml如下:
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
測試代碼:
package org.text;
import org.apache.commons.text.StringSubstitutor;
public class Main {
public static void main(String[] args) {
StringSubstitutor interpolator = StringSubstitutor.createInterpolator();
// String payload = interpolator.replace("${script:js:new java.lang.ProcessBuilder(\"calc\").start()}");
String payload = "${script:js:new java.lang.ProcessBuilder(\"calc\").start()}";
interpolator.replace(payload);
}
}
JDK版本1.8
動態(tài)分析
在代碼分析之前,我們先看看官方用戶手冊(https://commons.apache.org/proper/commons-
text/userguide.html)中的內容。
這里演示了使用默認查找StringSubstitutor來構造復雜字符串的用法,而漏洞描述中的關鍵所在就是執(zhí)行變量插值,其標準格式是${prefix:name}。
參考下 StringLookupFactory的文檔(http://commons.apache.org/proper/commons-
text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html)
自從1.5版本之后,可以滿足script類型的字符串查找,但是并不是默認包括的。
將代碼定位到
org.apache.commons.text.lookup.InterpolatorStringLookup#lookup
這里lookup方法會提取”:“后的部分作為 prefix 值,然后根據(jù) stringLookupMap 提取其對應的 lookup 實例化對象。
到org.apache.commons.text.lookup.ScriptStringLookup#lookup中。
調用ScriptEngineManager執(zhí)行代碼。
了解了漏洞后半部分,打下斷點,動態(tài)調試一下,看看如何調用lookup方法。
org.apache.commons.text.StringSubstitutor#createInterpolator
這里就是實例化了StringSubstitutor 并向其中傳入
StringLookupFactory.INSTANCE.interpolatorStringLookup()
org.apache.commons.text.StringSubstitutor#replace
對參數(shù)轉換類型,然后傳入
substitute 處理,后續(xù)將經過一系列判斷檢查。
最后傳入resolveVariable
org.apache.commons.text.StringSubstitutor#resolveVariable
在getStringLookup的值之后,就會直接到org.apache.commons.text.lookup.InterpolatorStringLookup中調用lookup方法。
到這里,正如開頭所分析的那樣lookup方法會提取”:“后的部分作為
prefix 值,然后根據(jù) stringLookupMap 提取其對應的 lookup
實例化對象,最后通過調用ScriptEngineManager執(zhí)行代碼。
漏洞復現(xiàn)
當然,網上已經有很多大佬對這個進行了分析,此漏洞與Log4Shell (CVE-2021-44228)其實是不同的,因為在 Log4Shell
中,可以從日志消息正文中進行字符串插值,該正文通常包含不受信任的輸入。在 Apache Common Text issue
中,相關方法明確用于執(zhí)行字符串插值并明確記錄在案,因此應用程序不太可能在沒有適當驗證的情況下無意中傳遞不受信任的輸入。
漏洞檢測工具
工具地址: https://github.com/StarCrossPortal/scalpel
已更新:
目前掃描工具已更新至第三個版本,新增對CVE-2022-0885、CVE-2022-1054、CVE-2022-1392、CVE-2022-21500、CVE-2022-23854漏洞的檢測,已內置100+漏洞POC,修復了例如Content-
Type和body類型不一致等問題。最新版本測試穩(wěn)定,滿足Web/API的漏洞Fuzz和多場景的漏洞檢測。
持續(xù)更新:
漏洞POC、掃描工具漏洞檢測優(yōu)化(檢測邏輯,滿足對需要連續(xù)數(shù)據(jù)包關聯(lián)操作漏洞場景的檢測)
的檢測,已內置100+漏洞POC,修復了例如Content-
Type和body類型不一致等問題。最新版本測試穩(wěn)定,滿足Web/API的漏洞Fuzz和多場景的漏洞檢測。
持續(xù)更新:
漏洞POC、掃描工具漏洞檢測優(yōu)化(檢測邏輯,滿足對需要連續(xù)數(shù)據(jù)包關聯(lián)操作漏洞場景的檢測)
網絡安全工程師企業(yè)級學習路線
這時候你當然需要一份系統(tǒng)性的學習路線
如圖片過大被平臺壓縮導致看不清的話,可以在文末下載(無償?shù)模?,大家也可以一起學習交流一下。
一些我收集的網絡安全自學入門書籍
一些我白嫖到的不錯的視頻教程:
文章來源:http://www.zghlxwxcb.cn/news/detail-539707.html
上述資料【掃下方二維碼】就可以領取了,無償分享文章來源地址http://www.zghlxwxcb.cn/news/detail-539707.html
到了這里,關于CVE-2022-42889 Apache Commons Text RCE漏洞分析的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!