CVE-2022-48339
📋 TL;DR
CVE-2022-48339 is a command injection vulnerability in GNU Emacs' htmlfontify.el module. It allows attackers to execute arbitrary code by crafting malicious file or directory names containing shell metacharacters. This affects all GNU Emacs users who process untrusted files through the htmlfontify functionality.
💻 Affected Systems
- GNU Emacs
📦 What is this software?
⚠️ Risk & Real-World Impact
Worst Case
Full system compromise with arbitrary code execution as the user running Emacs, potentially leading to data theft, ransomware deployment, or lateral movement.
Likely Case
Local privilege escalation or arbitrary command execution when processing malicious files from untrusted sources.
If Mitigated
No impact if proper input validation and escaping are implemented, or if untrusted files are not processed.
🎯 Exploit Status
Exploitation requires the ability to control file or directory names processed by the vulnerable function.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: Fixed in commit 1b4dc4691c1f87fc970fbe568b43869a15ad0d4c and later versions
Vendor Advisory: https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1b4dc4691c1f87fc970fbe568b43869a15ad0d4c
Restart Required: Yes
Instructions:
1. Update GNU Emacs to version after 28.2. 2. Apply the patch from the Git commit. 3. Restart Emacs to load the fixed code.
🔧 Temporary Workarounds
Disable htmlfontify module
allPrevent loading of the vulnerable htmlfontify.el module
Add (setq load-path (remove "/path/to/htmlfontify.el" load-path)) to .emacs
Input validation wrapper
allCreate wrapper functions that sanitize file and directory names before passing to hfy-istext-command
Implement custom functions that filter shell metacharacters from file paths
🧯 If You Can't Patch
- Avoid processing untrusted files or directories with Emacs htmlfontify functionality
- Implement strict file name validation at the application level before passing to Emacs
🔍 How to Verify
Check if Vulnerable:
Check Emacs version with 'emacs --version' and verify if it's 28.2 or earlier
Check Version:
emacs --version | head -1
Verify Fix Applied:
Verify the Git commit contains the fix: check for the presence of commit 1b4dc4691c1f87fc970fbe568b43869a15ad0d4c
📡 Detection & Monitoring
Log Indicators:
- Unusual shell commands executed from Emacs process
- File operations with suspicious characters in names
Network Indicators:
- Outbound connections from Emacs process to unexpected destinations
SIEM Query:
process.name:"emacs" AND cmdline:"sh" OR cmdline:"bash"
🔗 References
- https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1b4dc4691c1f87fc970fbe568b43869a15ad0d4c
- https://lists.debian.org/debian-lts-announce/2023/05/msg00008.html
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/FLPQ4K6H2S5TY3L5UDN4K4B3L5RQJYQ6/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/U6HDBUQNAH2WL4MHWCTUZLN7NGF7CHTK/
- https://www.debian.org/security/2023/dsa-5360
- https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1b4dc4691c1f87fc970fbe568b43869a15ad0d4c
- https://lists.debian.org/debian-lts-announce/2023/05/msg00008.html
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/FLPQ4K6H2S5TY3L5UDN4K4B3L5RQJYQ6/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/U6HDBUQNAH2WL4MHWCTUZLN7NGF7CHTK/
- https://www.debian.org/security/2023/dsa-5360