Linux Shared Object Hijacking
Last updated
Last updated
Programs and binaries under development usually have custom libraries associated with them. Consider the following SETUID
binary.
We can use to print the shared object required by a binary or shared object.
Ldd
displays the location of the object and the hexadecimal address where it is loaded into memory for each of a program's dependencies.
We see a non-standard library named libshared.so
listed as a dependency for the binary.
As stated earlier, it is possible to load shared libraries from custom locations.
One such setting is the RUNPATH
configuration.
Libraries in this folder are given preference over other folders.
This can be inspected using the utility.
The configuration allows the loading of libraries from the /development
folder, which is writable by all users.
This misconfiguration can be exploited by placing a malicious library in /development
which will take precedence over other folders because entries in this file are checked first (before other folders present in the configuration files).
Before compiling a library, we need to find the function name called by the binary.
get an error
We can copy an existing library to the development
folder.
Running ldd
against the binary lists the library's path as /development/libshared.
so, which means that it is vulnerable.
Executing the binary throws an error stating that it failed to find the function named dbquery
.
We can compile a shared object which includes this function.
Executing the binary again should display the banner and pops a root shell.
The dbquery
function sets our user id to 0 (root) and executing /bin/sh
when called. Compile it using .