REDHAT-BUG-2489969: Command Injection
Description
A command injection vulnerability exists in the foreman-rake errors:fetchlog task within Red Hat Satellite. The requestid parameter is passed to an underlying system command (typically grep) without adequate shell neutralization. While the task is intended to fetch specific log entries, an attacker with sudo permissions to execute this rake task can inject shell metacharacters (such as ;, ", or |) to break out of the intended command and execute arbitrary code.
Impact
Successful exploitation allows a restricted user to escalate privileges to the foreman user and subsequently to root across all managed hosts, Organizations, and Locations. This represents a complete compromise of the Red Hat Satellite server and the entire infrastructure it manages.
Recommendations
Validate Input: Sanitize the requestid parameter to ensure it only contains alphanumeric characters and dashes, rejecting any input containing shell metacharacters.
Use Argument Arrays: Replace system calls that use shell string interpolation with array-based arguments to prevent shell interpretation (e.g., using Open3.capture3 with separate arguments in Ruby). Specifically, the following code in lib/tasks/errors.rake file should be replaced with something like this:
--------------------------------------------------------------------------------
// Vulnerable code
result = grep "#{requestid}" "#{filepath}"
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
Replace the shell-interpolated grep call in lib/tasks/errors.rake with an argument-array system call, such as Open3.capture3 with request_id and file_path passed as separate arguments.
- Compensating control
Validate the request_id parameter to allow only alphanumeric characters and dashes, and reject values containing shell metacharacters such as semicolons, quotes, or pipes.