11.Vulnerable-services
Last updated
Last updated
1. Create libhax.c
2. Compile libhax.c
3. Create rootshell.c
4. Compile rootshell.c
5. Create /etc/ld.so.preload
6. Trigger the exploit
7. Execute the root shell
Version 4.5.0 and below: The screen
utility in these versions lacks proper permission checks when creating or truncating log files.
Arbitrary File Write: This allows an attacker to write to or create files with root privileges, leading to privilege escalation.
ld.so.preload
Abuse: The exploit leverages this vulnerability to manipulate the ld.so.preload
file, which specifies shared libraries to load before others. By pointing it to a malicious library, arbitrary code can be executed with root privileges.
Create Malicious Library (libhax.so
):
A C library is created that, upon loading, changes the ownership and permissions of a shell executable (/tmp/rootshell
) to root and sets the SUID bit.
It also removes the ld.so.preload
file to clean up.
Create Root Shell (rootshell
):
A simple C program is created that spawns a root shell using setuid(0)
and related functions.
Create ld.so.preload
:
The script uses screen
's logging feature to write the path to the malicious library (/tmp/libhax.so
) into /etc/ld.so.preload
. The umask 000
is very important, as it ensures that the file is created with the needed permissions.
Trigger the Vulnerability:
Running screen -ls
triggers the vulnerability. Because screen is a SUID binary, when it runs, it loads the ld.so.preload
library, and the code within the library executes.
Root Shell:
The malicious library changes the permissions of /tmp/rootshell
, and the script then executes it, providing a root shell.
SUID Binaries: The exploit relies on screen
being a SUID binary. This is a common requirement for many privilege escalation exploits.
ld.so.preload
: Understanding how ld.so.preload
works is crucial for understanding this exploit. It is a powerful but dangerous feature.
Clean Up: The exploit includes steps to clean up after itself, such as removing the malicious library and ld.so.preload
. This is good practice but not always guaranteed.
Mitigation:
Update screen
: The primary mitigation is to update to a patched version of screen
.
Remove SUID bit: If updating is not possible, removing the SUID bit from screen
will prevent this exploit, but it may break functionality.
File System Permissions: Proper file system permissions can help prevent unauthorized modification of critical system files.
Real-World Scenarios: This exploit is a good example of how seemingly minor vulnerabilities can lead to significant security breaches.
Exploit variations: There are slight variations of this exploit. For example, instead of removing the preload file, the malicious library may replace its content with a blank line.
Detection: This type of exploit can be detected by monitoring changes to /etc/ld.so.preload
and by detecting suspicious SUID binaries. Monitoring for unexpected root shells is also important.
Containerization: In containerized environments, this vulnerability may be less impactful, as the container's root user is typically isolated from the host's root user. However, container escape vulnerabilities can still occur.