Linux
This is a page dedicated to privilege escalation in unix based systems. Helpful hacktricks checklist: https://book.hacktricks.xyz/linux-hardening/linux-privilege-escalation-checklist
Checklist: https://book.hacktricks.xyz/linux-hardening/linux-privilege-escalation-checklist
Checklist2: https://swisskyrepo.github.io/InternalAllTheThings/redteam/escalation/linux-privilege-escalation/#checklists
Tools
Always double check information from automated tools manually.
linPEAS.sh
LinEnum.sh
linuxprivchecker.py
unix-privesc-check
Mestaploit: multi/recon/local_exploit_suggesterCheck directories manually
/opt, /tmp, /home # look for password files, logs, interesting .shSystem information
If any command does not work you can search for alternate ones in google.
hostname # get hostname
(cat /proc/version || uname -a ) 2>/dev/null # OS version, google for exploits
# you can get these information also from /etc/issue and /etc/*-release
lscpu # check architecture
ps aux # list processes
ps aux | grep root # list processes for given user
echo $PATH # check for write permission inside the path. Hijack binaries / libraries
find / -writable -type d 2>/dev/null # search for writeable directoriesIf the kernel is vulnerable here is the link containing some of the linux exploits: https://github.com/lucyoa/kernel-exploits
User information
Quick wins, find low handing fruits or basic knowledge about who are we.
You can leverage write permissions on /etc/passwd
Network enumeration
Maybe machine can be communicating with other network.
SUDO/Capabilities
Quick way to elevate privileges. Search for programs using the commands listed during execution of the commands below and utilize the GTFO Bins web page: https://gtfobins.github.io
Pkexec is not listed in GTFO Bins but sometimes vulnerable to CVE-2021-4034.
More information about that can be found here: https://github.com/Almorabea/pkexec-exploit?trk=article-ssr-frontend-pulse_little-text-block
SUID
GTFO Bins
In order to get a quick win you can use the following command:
And search for the commands in GTFO Bins to see if you can escalate with oneliner: https://gtfobins.github.io
Shared Object Injection
Look for somewhere where we can inject something.
When application is run look for: No such file or directory / open / access.
Then we can try to override it.
Trace what is happening and find what program tries to access.
Try to override it with malicious code. In order to do that you have to check privileges of given file:
Symlinks (vulnerable software on the server)
Search for files and applications (for example in user's home folder).
List packages with its version using dpkg to see if they are vulnerable.
Suid on sudo + vulnerablr nginx from apache = shell.
Environmental Variables
You can change PATH / environmental variable in order to execute malicious program created by us (for example reverse shell or just /bin/bash as root).
It is connected to SUID because the program that uses PATH or environmental variables has to be run as a root in order to do that.
Run the program after everything.
Log inspection
System logs can contain valuable information - it can be used to debugging some of our problems.
Search for strings in binaries
Weak file permissions
If important file has weak permissions we can take advantage of it.
If you have read/write permissions on /etc/shadow. You can get the hashes and crack them using hashcat and https://hashcat.net/wiki/doku.php?id=example_hashes in order to recognize the hashes.
You can also search for other files e.g. ssh-keys https://swisskyrepo.github.io/InternalAllTheThings/redteam/escalation/linux-privilege-escalation/#sensitive-files
Intended funcionallity
When sudo is on intended functionality of the tool e.g. apache2 in order to perform our job. Sometimes with the right flag we can do some interesting this:
The command above extract root hash.
Wget example: https://veteransec.com/2018/09/29/hack-the-box-sunday-walkthrough/
Of course this is a very specific case and depends on the configuration of the machine.
Escalation via LD_PRELOAD
If after sudo -l env_keep+=LD_PRELOAD shows up you are able to perform the exploit.
Prepare C file with the following code:
Compile the file with shell.c name:
Execute the file by loading it before other libraries:
Daemons
System daemons are Linux services that are spawned at boot time to perform specific operations without any need for user interaction.
CVE 2019-14287
Vulnerable sudo version: sudo <1.8.28
When after sudo -l this shows up: hacker ALL=(ALL,!root) /bin/bash
If you will change the value of 1 to any other number you can take advantage of any other user.
CVE 2019-18634
Vulnerable sudo version: sudo <=1.8.30
If you are changing to the other user and see the * instead of nothing while writing the password it can be indicator that the system is vulnerable.
Get file in C from here: https://github.com/saleemrashid/sudo-cve-2019-18634
Run exploit it in the system
NO PASSWD File Replacement
Password hunting
You can search for passwords, ssh-keys, secrets etc.
Resource to get more commands: https://swisskyrepo.github.io/InternalAllTheThings/redteam/escalation/linux-privilege-escalation/#looting-for-passwords
Check root processes
https://github.com/DominicBreuker/pspy
Cron jobs
Cron jobs are fired every x minutes / hours / days. If we can modify the program content of file or replace the file that is runned as root user we can get his shell.
Cron Path
See cron PATH variable in order to see where jobs are executed. Then you can use:
To see what permissions do we have in this path. Also see if the file not exist, if we can modify it, replace it. Then wait...
.sh reverse shell oneliner
Cron Wildcards
If in the file there are wildcards used in commands we can do injection.
Prepare the file like this:
Then create in appropriate location the following files:
What does it do?
When program is using a wildcard it checks files at the folder location, instead reading a file name wildcard interprets filename as flag.
What do the checkpoints mean?
--checkpoint=1
Display number for every progress that you make.
--checkpoint-action=exec=sh\runme.sh
As you do the progress (hit the checkpoint) execute this: sh\runme.sh
If everything succeded this command should give us a root shell:
File override
Find the file that crontab use and check the permissions:
If you have permissions to read and write you can delete this file and replace it with reverse shell which will give us a root shell.
Malicious file:
Listener on kali:
OSCP reverse shell
NFS Root Squashing
If folder has no_root_squash the folder can be mounted with root permissions.
Mount the folder on kali
Create the folder
Create a malicious file
Now just execute the file and get root shell.
Docker
If we are in docker group we can use this in order to elevate privileges.
Drives
Find sensitive data on the drives (credntials, private keys)
Kernel modules
Capture network traffic
Last updated