Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2022-42889 PoC — Apache Commons Text prior to 1.10.0 allows RCE when applied to untrusted input due to insecure interpolation defaults

Source
Associated Vulnerability
Title:Apache Commons Text prior to 1.10.0 allows RCE when applied to untrusted input due to insecure interpolation defaults (CVE-2022-42889)
Description:Apache Commons Text performs variable interpolation, allowing properties to be dynamically evaluated and expanded. The standard format for interpolation is "${prefix:name}", where "prefix" is used to locate an instance of org.apache.commons.text.lookup.StringLookup that performs the interpolation. Starting with version 1.5 and continuing through 1.9, the set of default Lookup instances included interpolators that could result in arbitrary code execution or contact with remote servers. These lookups are: - "script" - execute expressions using the JVM script execution engine (javax.script) - "dns" - resolve dns records - "url" - load values from urls, including from remote servers Applications using the interpolation defaults in the affected versions may be vulnerable to remote code execution or unintentional contact with remote servers if untrusted configuration values are used. Users are recommended to upgrade to Apache Commons Text 1.10.0, which disables the problematic interpolators by default.
Description
This repository contains a Python script to automate the process of testing for a vulnerability known as Text4Shell, referenced under the CVE id: CVE-2022-42889.  
Readme
# CVE-2022-42889 (Text4Shell) Testing Script

This repository contains a Python script to automate the process of testing for a vulnerability known as Text4Shell, referenced under the CVE id: CVE-2022-42889.  

## About Text4Shell (CVE-2022-42889)  

Text4Shell is a critical vulnerability that affects a wide range of systems. The vulnerability lies in the way these systems parse text strings and allows for the execution of arbitrary code or SSRF attacks.  The vulnerability is exploited through crafted strings, where either JavaScript code is executed (leading to Remote Code Execution (RCE)) or URLs are fetched (leading to Server-Side Request Forgery (SSRF)).  

From [Tarlogic](https://www.tarlogic.com/blog/cve-2022-42889-text4shell-vulnerability/):

- **Exploitation requirements**:
- The application accepts user-controlled input that is subsequently processed by one of the following methods of the affected component:

	- StringLookupFactory.INSTANCE.interpolatorStringLookup().lookup()
	- StringSubstitutor.createInterpolator().replace()

- Java versions equal or greater than Java 15 would not be susceptible to remote code execution, since the Nashorn engine is disabled and the “script” prefix would not be available. However, other attacks via the “url” and “dns” prefixes would be possible.

## Script Usage  

This Python script helps in testing the presence of the Text4Shell vulnerability in a system. The scope of this script includes: testing of script and url prefixes.

The script has two modes of operation: RCE and SSRF, controlled by the `-m` or `--mode` command-line argument. It constructs a URL incorporating a crafted string based on the selected mode and makes a GET request to the URL.  

### RCE Mode  

In RCE mode, the script creates a crafted string that attempts to execute a JavaScript command. The command to be executed is passed as a command-line argument using `-c` or `--command`.  

```bash
python text4shell.py -u 'http://example.com/search?query=' -c 'your_command' -m 'rce'
```

### SSRF Mode

In SSRF mode, the script creates a crafted string that includes a URL fetch command.

```bash
python text4shell.py -u 'http://example.com/search?query=' -m 'ssrf' -s 'http://example.com/resource'
```

### Response

The script makes a GET request to the constructed URL and prints the HTTP response status code and body.
File Snapshot

[4.0K] /data/pocs/70724a81ca2b7592be97f4f4536de4dd70c5541a ├── [2.3K] README.md └── [1.5K] text4shell.py 0 directories, 2 files
Shenlong Bot has cached this for you
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →