CVE-2026-138161 — Gammu — CWE-120
Gammu before 1.45.2 contains a buffer overflow vulnerability in LoadBackup() that allows attackers to corrupt memory by supplying an overlong MD5 value in a crafted backup file. Attackers can overwrite adjacent phonebook and calendar entry pointers via strcpy() into MD5Original when files are loaded with convertbackup or restore, causing crashes or potential code execution.
Gammu before 1.45.2 contains a buffer overflow vulnerability in LoadBackup() that allows attackers to corrupt memory by supplying an overlong MD5 value in a crafted backup file. Attackers can overwrite adjacent phonebook and calendar entry pointers via strcpy() into MD5Original when files are loaded with convertbackup or restore, causing crashes or potential code execution.
🎯 What is this vulnerability?
CVE‑2026‑138161 is a classic buffer‑copy without bounds checking (CWE‑120) in the Gammu mobile‑device management suite (all releases prior to 1.45.2).
The flaw resides in the LoadBackup() routine that parses a backup file during the convertbackup or restore commands.
The routine copies the MD5 hash field (MD5Original) into a fixed‑size local buffer using strcpy():
char MD5Original[33]; /* 32 hex chars + NUL */
strcpy(MD5Original, md5_from_file); /* no length check */If the backup file contains an MD5 string longer than 32 characters, the strcpy() overruns the buffer and corrupts the stack.
Adjacent memory contains pointers to phonebook and calendar entries; the overflow can overwrite those pointers. The result is either:
- Denial‑of‑Service – the program crashes (segmentation fault, stack smashing).
- Potential Code Execution – if the attacker can control the overwritten pointers to point to malicious code or a shellcode payload, arbitrary code may run with the privileges of the Gammu process.
- Upgrade to Gammu 1.45.2 or later – the upstream patch replaces
strcpy()with a bounds‑checked copy (strncpy()/snprintf()) and validates the MD5 length.
Authentication / Authorization – The vulnerability is local (AV:L) and requires no privilege (PR:N). The only requirement is that the user runs Gammu with the crafted backup file (UI:R). No network or authentication checks are bypassed.
⚡ Attack Chain
| Step | Description | Technical Detail |
|---|---|---|
| 1. Discovery & Reconnaissance | Identify that the target system runs Gammu < 1.45.2. | • Scan the filesystem for gammu binary (which gammu). <br>• Run gammu --version to confirm the exact release. <br>• Verify that the system has a backup/restore workflow (e.g., a cron job or a user‑initiated gammu --restore). |
| 2. Exploitation | Deliver a crafted backup file that triggers the overflow. | Crafting the file – The backup format is a simple text file with key/value pairs. The critical field is MD5Original. An overlong value (e.g., 64 hex characters) will overflow. <br>PoC (illustrative) – The exact format is not public, but the following demonstrates the principle: <br>``bash\n# Create a malicious backup file\ncat > /tmp/malicious.backup <<'EOF'\n# Gammu backup file (simplified)\nMD5Original=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\n# … other fields …\nEOF\n\n# Run Gammu with the crafted file (local user interaction required)\ngammu --restore /tmp/malicious.backup\n`\n*The above is illustrative; the real backup format may differ, but the key idea is to supply an MD5 string longer than 32 characters.* <br>Execution – When gammu --restore parses the file, LoadBackup() copies the oversized MD5 into MD5Original`, overrunning the stack and corrupting the adjacent pointers. |
| 3. Post‑exploitation | Achieve the desired impact. | *If the Gammu process runs as a privileged user (e.g., root or a service account), the attacker can: <br>• Crash the service (Denial‑of‑Service). <br>• Overwrite pointers to point to a shellcode buffer placed earlier in the stack, thereby executing arbitrary code with the same privileges. <br>• Corrupt phonebook/calendar data, causing integrity loss.* <br>Privilege Escalation – If Gammu is executed as root (common in automated backup scripts), the attacker can gain root access. <br>Data Exfiltration – By corrupting the phonebook/calendar pointers, the attacker can read or modify sensitive contact or calendar data. |
🌍 Real World Impact
| Impact | CVSS Vector | Explanation |
|---|---|---|
| Confidentiality | C:H | Overwritten pointers may expose private phonebook or calendar entries to the attacker. |
| Integrity | I:H | The attacker can tamper with or delete entries, corrupting the backup data. |
| Availability | A:H | A single crafted backup file can crash Gammu, potentially stopping automated backup/restore jobs or a service that relies on it. |
Because the vulnerability is local and requires the victim to run Gammu with the malicious file, the attack surface is limited to users who have the ability to execute Gammu. In many deployments, Gammu runs as a dedicated service account or is invoked by a scheduled job; if that account has elevated privileges, the risk escalates to privilege escalation.
🛡️ Remediation & Mitigation
Affected Versions
All Gammu releases before 1.45.2.Patch / Upgrade
# Example (Debian/Ubuntu)
sudo apt-get update
sudo apt-get install --only-upgrade gammu
# Verify
gammu --version # should show 1.45.2 or newerWorkarounds (if upgrade is not immediately possible)
| Mitigation | How to Apply |
|---|---|
| Disable backup/restore | Remove or comment out the convertbackup/restore commands from any automation scripts. If the feature is not needed, uninstall the gammu package or set file permissions to prevent execution. |
| Restrict file access | Ensure that only trusted users can write to the directory where backup files are stored. Use chmod 700 /path/to/backup/dir and chown root:root /path/to/backup/dir. |
| File integrity monitoring | Deploy a host‑based IDS (e.g., OSSEC, Wazuh) to alert on large MD5 fields or abnormal backup file sizes. |
| Runtime protection | Enable stack canaries, ASLR, and non‑executable stack on the host. These mitigations reduce the likelihood that an overflow leads to code execution. |
Detection
| Indicator | Log / System Event |
|---|---|
| Segmentation fault / core dump | /var/log/syslog, /var/log/messages may contain Segmentation fault (core dumped) or * stack smashing detected *. |
| Abnormal exit code | gammu may exit with code 139 (SIGSEGV). |
| Large MD5 field | Custom monitoring can flag backup files where MD5Original exceeds 32 characters. |
| Unexpected Gammu restarts | If Gammu is run as a service, systemd logs may show frequent restarts. |
⚠️ Urgency
[🤖 CVE Professor AI Security Engine]
FOFA Query