Understanding and Mitigating Sudo Privilege Escalation Security Risks in RHEL 5


6 views

In Red Hat Enterprise Linux 5 (RHEL 5), when a user is listed in the /etc/sudoers file, they can execute commands with root privileges by prefixing them with sudo. The authentication mechanism requires the user to enter their own password, not the root password. This is by design and represents the standard sudo behavior across Unix-like systems.

# Example /etc/sudoers entry
george ALL=(ALL) ALL

While this might appear as a security vulnerability at first glance, it's actually a controlled delegation of privileges. The key security considerations are:

  • Sudo access is explicitly granted by the system administrator
  • All sudo commands are logged in /var/log/secure
  • Command execution can be restricted to specific commands
  • Password caching has timeout controls

To maintain security while using sudo:

# Instead of full access, grant specific commands
george ALL=(root) /usr/bin/updatedb, /usr/bin/yum update

# Configure password timeout
Defaults:george timestamp_timeout=5

Implement robust logging to track sudo activity:

# Enhanced sudo logging configuration
Defaults logfile=/var/log/sudo.log
Defaults log_input, log_output
Defaults iolog_dir=/var/log/sudo-io/%{user}

For more granular control, consider:

  • Using SELinux contexts for specific applications
  • Implementing RBAC (Role-Based Access Control)
  • Creating restricted shells for certain users

Here's a production-grade sudoers configuration snippet:

# Allow dbadmin to manage database services without full root
User_Alias DBADMINS = dbuser1, dbuser2
Cmnd_Alias DBSERVICES = /sbin/service mysqld *, /sbin/service postgresql *
DBADMINS ALL=(root) NOPASSWD: DBSERVICES

# Developers can restart web services but not system services
User_Alias DEVS = dev1, dev2
Cmnd_Alias WEBSERVICES = /sbin/service httpd *, /sbin/service nginx *
DEVS ALL=(root) WEBSERVICES

In Red Hat Enterprise Linux 5, when a user is listed in the /etc/sudoers file, they can execute commands with root privileges by prefixing them with sudo. The authentication requires their own password, not the root password. This is indeed the expected behavior of sudo.

# Example sudoers entry:
george ALL=(ALL) ALL

While this might appear as a security hole at first glance, it's actually a designed feature with proper security controls:

  • Privileges are explicitly granted in sudoers file
  • All sudo commands are logged in /var/log/secure
  • Password authentication provides an additional layer

Improper sudo configuration can lead to privilege escalation. Consider these security best practices:

# Instead of broad permissions:
# user ALL=(ALL) ALL

# Use specific command restrictions:
george ALL=(root) /usr/bin/yum, /usr/bin/systemctl restart httpd

For sensitive environments, implement additional restrictions:

# Require password for specific commands
Cmnd_Alias CRITICAL = /bin/su, /usr/bin/passwd
george ALL=(ALL) ALL, !CRITICAL

# Time-based restrictions
Defaults:george timestamp_timeout=30

Implement comprehensive logging:

# Enhanced sudo logging
Defaults log_host, log_year, log_input, log_output
Defaults!/bin/su !syslog

Regularly audit sudo usage with:

grep sudo /var/log/secure | less
ausearch -m USER_CMD -ts today

For more granular control, consider:

  • Implementing SELinux contexts
  • Using capabilities instead of full root access
  • Creating restricted shells for specific users
# Example using capabilities:
setcap cap_net_raw+ep /usr/bin/ping