Linux Privesc
Introduction
Use the "id" and "whoami" commands to check your user account.
Execute Linux Smart Enumeration (lse.sh) with progressively increasing levels to gather more detailed information about the system.
Run LinEnum and other relevant scripts to identify potential vulnerabilities and security-related issues that may lead to privilege escalation.
Take the time to carefully review the results of your enumeration. If Linux Smart Enumeration at level 0 or 1 identifies something noteworthy, make a note of it. To avoid getting sidetracked, make a checklist of the prerequisites needed for the privilege escalation method to work.
Check for files in the user's home directory and other common locations, such as "/var/backup" or "/var/logs". If the user has a history file, read it as it may contain valuable information like commands or passwords.
Start with simpler methods that require fewer steps, such as Sudo, Cron Jobs, and SUID files. Examine root processes, determine their versions, and search for potential exploits. Look for internal ports that can be forwarded to your attack machine.
If you still haven't obtained root access, go back and review the full enumeration results again, and highlight anything that appears unusual, such as unfamiliar process or file names, non-standard filesystems (anything other than ext, swap, or tmpfs on Linux), or unusual usernames. At this point, you can also begin exploring the possibility of kernel exploits.
Tools
Linux Smart Enumeration
Download from here.
Linux Smart Enumeration has several levels that progressively disclose more detailed information.
LinEnum
Download from here.
LinEnum is a powerful Bash script that can extract a wealth of valuable information from a target system. The tool can also copy important files for export and search for files that contain specific keywords, such as "password".
LinPEAS
Downlaod from here.
Run LinPEAS saving colors:
Kernel Exploits
Locating and utilizing kernel exploits is typically a straightforward process:
Perform enumeration to identify the kernel version (using a command such as "uname -a").
Search for relevant exploits that match the kernel version on search engines like Google, ExploitDB, or GitHub.
Compile and execute the exploit, but exercise caution as kernel exploits can be unstable, single-use only, and may cause system crashes.
Enumerate the kernel version:
Use searchsploit to find matching exploits:
We can try and adjust our search to be less specific with the kernel version, but more specific with the distribution:
Install Linux Exploit Suggester 2 (https://github.com/jondonas/linux-exploit- suggester-2) and run the tool against the original kernel version:
Service Exploits
To display all processes that are currently running with root privileges, use the following command:
With any results, try to identify the version number of the program being executed.
Running the program with the --version/-v command line option often shows the version number:
On Debian-like distributions, dpkg can show installed programs and their version:
On systems that use rpm, the following achieves the same:
Port Forwarding
In certain cases, a root process may be linked to an internal port for communication purposes. If, for any reason, you cannot run an exploit on the target machine itself, you can forward the port to your local machine using SSH:
The exploit code can now be run on your local machine at whichever port you chose.
Weak File Permissions
Find all writable files in /etc:
Find all readable files in /etc:
Find all directories which can be written to:
World Readable /etc/shadow
Check the permissions of the /etc/shadow file and note that it is world readable:
Extract the root user’s password hash:
Save the password hash in a file (e.g. hash.txt):
Crack the password hash using john:
Use the su command to switch to the root user, entering the password we cracked when prompted:
World Writable /etc/shadow
Check the permissions of the /etc/shadow file and note that it is world writable:
Copy / save the contents of /etc/shadow so we can restore it later.
Generate a new SHA-512 password hash:
Edit the /etc/shadow and replace the root user’s password hash with the one we generated.
Use the su command to switch to the root user, entering the new password when prompted:
World Writable /etc/passwd
The root account in /etc/passwd is usually configured like this:
root:x:0:0:root:/root:/bin/bash
The “x” in the second field instructs Linux to look for the password hash in the /etc/shadow file.
In some versions of Linux, it is possible to simply delete the “x”, which Linux interprets as the user having no password:
root::0:0:root:/root:/bin/bash
Check the permissions of the /etc/passwd file and note that it is world writable.:
Generate a password hash for the password “password” using openssl:
Edit the /etc/passwd file and enter the hash in the second field of the root user row:
Use the su command to switch to the root user:
Alternatively, append a new row to /etc/passwd to create an alternate root user (e.g. newroot):
Use the su command to switch to the newroot user:
SUIDs and GUIDs
We can use find
to locate SUID programs and discover which programs are SUID:
Next we can use this source to find exploitable methods of the found binary:
GTFO Bins:
Stored Passwords
View the contents of hidden files in the user’s home directory:
You can also check for configuration files inside the OS.
NFS
Show the NFS server’s export list:
Similar Nmap script:
Mount an NFS share:
Last updated