🐧Linux Privilege Escalation
Enumeration
Kernel Exploits
The Kernel exploit methodology is simple:
Identify the kernel version
Search and find an exploit code for the kernel version of the target system
Run the exploit
You can transfer the exploit code from your machine to the target system using the SimpleHTTPServer
Python module and wget
respectively.
Sudo
The steps of this privilege escalation vector can be summarized as follows:
Run
sudo -l
Check for LD_PRELOAD (with the
env_keep
option)Write a simple C code compiled as a share object (.so extension) file
Run the program with
sudo
rights and the LD_PRELOAD option pointing to our .so file
SUID
Capabilities
Cron Jobs
Crontab is always worth checking as it can sometimes lead to easy privilege escalation vectors. The following scenario is not uncommon in companies that do not have a certain cyber security maturity level:
System administrators need to run a script at regular intervals.
They create a cron job to do this
After a while, the script becomes useless, and they delete it
They do not clean the relevant cron job
Two points to note:
The command syntax will vary depending on the available tools. (e.g.
nc
will probably not support the-e
option you may have seen used in other cases)We should always prefer to start reverse shells, as we not want to compromise the system integrity during a real penetration testing engagement.
Path
Depends entirely on the existing configuration of the target system, so be sure you can answer the questions below before trying this.
What folders are located under $PATH
Does your current user have write privileges for any of these folders?
Can you modify $PATH?
Is there a script/application you can start that will be affected by this vulnerability?
NFS
The critical element for this privilege escalation vector is the
no_root_squash
option. By default, NFS will change the root user tonfsnobody
and strip any file from operating with root privileges. If theno_root_squash
option is present on a writable share, we can create an executable with SUID bit set and run it on the target system.
Last updated