CVE-2023-28487 Overview
CVE-2023-28487 is an Improper Encoding or Escaping of Output vulnerability (CWE-116) affecting Sudo versions prior to 1.9.13. The vulnerability exists because Sudo fails to escape control characters in sudoreplay output, potentially allowing attackers to inject malicious control sequences that could manipulate terminal displays or obfuscate malicious activity in audit logs.
Critical Impact
Unescaped control characters in sudoreplay output can be leveraged to manipulate terminal displays, inject ANSI escape sequences, or potentially hide malicious commands from administrators reviewing sudo session logs.
Affected Products
- Sudo Project Sudo (versions before 1.9.13)
- NetApp Active IQ Unified Manager for VMware vSphere
Discovery Timeline
- 2023-03-16 - CVE-2023-28487 published to NVD
- 2024-11-21 - Last updated in NVD database
Technical Details for CVE-2023-28487
Vulnerability Analysis
This vulnerability stems from insufficient output encoding in the sudoreplay utility, which is used to replay sudo session recordings for audit and forensic purposes. When control characters are present in logged command data, they are not properly escaped before being displayed or written to logs.
Control characters (ASCII codes 0-31) include special sequences like tabs, carriage returns, and ANSI escape codes. When these characters pass through sudoreplay unescaped, an attacker who has executed commands containing embedded control characters can:
- Manipulate the visual appearance of audit logs
- Inject ANSI escape sequences that could alter terminal behavior
- Hide portions of malicious commands from administrators reviewing session recordings
- Potentially exploit terminal emulator vulnerabilities through crafted escape sequences
The vulnerability affects both the session replay functionality and the list mode (sudoreplay -l) used to enumerate available sessions.
Root Cause
The root cause is the failure to sanitize control characters in the log output processing code. Prior to version 1.9.13, the sudoreplay utility would output raw control characters directly to the terminal or log destination without any encoding or escaping, violating secure output handling practices defined in CWE-116 (Improper Encoding or Escaping of Output).
Attack Vector
The attack vector is network-accessible, requiring no privileges or user interaction. An attacker with the ability to execute commands via sudo can embed control characters in their commands or arguments. When an administrator later uses sudoreplay to review the session, these control characters are rendered directly, potentially:
- Hiding the true nature of executed commands
- Injecting misleading information into the terminal display
- Triggering unintended behavior in the reviewing terminal emulator
The fix implements octal encoding for control characters, using a # prefix (e.g., #011 for horizontal tab, #015 for carriage return, #040 for spaces in command paths).
syslog(3),
to a local log file, or both.
The log format is almost identical in both cases.
+Any control characters present in the log data are formatted in octal
+with a leading
+\(oq#\(cq
+character.
+For example, a horizontal tab is stored as
+\(oq#011\(cq
+and an embedded carriage return is stored as
+\(oq#015\(cq.
+In addition, space characters in the command path are stored as
+\(oq#040\(cq.
+Command line arguments that contain spaces are enclosed in single quotes
+('').
+This makes it possible to distinguish multiple command line arguments
+from a single argument that contains spaces.
+Literal single quotes and backslash characters
+(\(oq\e\(cq)
+in command line arguments are escaped with a backslash.
Source: GitHub Sudo Commit
Detection Methods for CVE-2023-28487
Indicators of Compromise
- Unusual control characters or escape sequences appearing in sudo logs
- Log entries containing raw binary data or non-printable characters
- Session recordings that display unexpectedly when replayed
- Terminal anomalies when reviewing sudoreplay output
Detection Strategies
- Audit sudo version across systems to identify installations running versions prior to 1.9.13
- Monitor sudo log files for non-printable ASCII characters (codes 0-31)
- Implement log analysis rules to detect embedded ANSI escape sequences in command logs
- Use file integrity monitoring on sudo-related binaries and configuration files
Monitoring Recommendations
- Enable comprehensive sudo logging with I/O logging for forensic capabilities
- Implement centralized log collection to capture sudo session data in a controlled environment
- Configure alerting for commands containing unusual character patterns
- Review sudoreplay output in sanitized terminal environments or through log processing tools that neutralize control sequences
How to Mitigate CVE-2023-28487
Immediate Actions Required
- Upgrade Sudo to version 1.9.13 or later immediately
- Review existing sudo session logs for potential manipulation attempts
- Implement terminal emulator hardening to limit escape sequence processing
- Consider reviewing critical sudo sessions using raw log files rather than terminal replay
Patch Information
The vulnerability has been addressed in Sudo version 1.9.13. The fix implements proper octal encoding for all control characters in log messages and sudoreplay -l output. Security patches are available through the official Sudo release and the commit 334daf92b31b79ce68ed75e2ee14fca265f029ca.
Distribution-specific updates are available via:
Workarounds
- Pipe sudoreplay output through cat -v to display control characters visibly
- Review session logs using tools that escape or strip control characters before display
- Avoid using terminal emulators with extensive escape sequence support when reviewing untrusted session recordings
- Implement log sanitization at the collection layer before administrative review
# Example: View sudoreplay output with control characters made visible
sudoreplay -l | cat -v
# Example: Check current sudo version
sudo -V | head -1
# Verify sudo version is 1.9.13 or later to confirm patch
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

