The kernel is a computer program that controls everything in the system. It facilitates interactions between hardware and software components. It acts as a translator.
Let us use the dirtycow exploit to escalate our privileges.
Dirty Cow Exploit
We are now root.
Passwords & File Permissions
Escalation via Stored Passwords
We can use the history command to find out if any passwords were input in the terminal.
MySQL username and password
We can also view .bash_history using nano .bash_history.
Do we have access to a file we "shouldn't"? Can we modify it? Can we execute it?
As a regular user, we should NOT have read access to the /etc/shadow file. Why? We can view the hashes and take them offline to attempt to crack them.
File Permissions
Assuming we had read write privileges, we could delete the 'x' placeholder for the root user in the /etc/passwd file file. This will remove the password for the root user and we could switch to them.
Alternatively, we could delete the root hash in the /etc/shadow file and replace it with a hash that we know its password. This would allow us to login with a password we set.
We could also change the group of our user in the /etc/passwd file to that of 0 (which is root).
After using ssh to login to the server, we run sudo -l to find out which commands we can run as root.
We cannot run bash as root.
Enter CVE-2019-14287 which affects sudo versions < 1.8.28. From the image below, we see that our sudo version is 1.8.21p2 so it is probably vulnerable to the exploit.
Let us exploit it to escalate our privileges.
sudo -u#-1 /bin/bash
We are root
And success! We are now root.
CVE-2019-18634
Find below the exploit code. This vulnerability affects versions of sudo earlier than 1.8.26.
It is helpful in situations where we cannot run 'sudo'.
After downloading the exploit code and compiling it, let us run it to escalate our privileges.
CVE-2019-18634
Success. We are now root.
Set Owner User ID (SUID)
We can use the command below to find files with SUID.
find / -perm -u=s -type f 2>/dev/null
Files with SUID
We can see the SUID in the files e.g.
SUID
We can then go to GTFOBins to search if there are any binaries we can use to bypass local security restrictions in misconfigured systems.
Other SUID Escalation
Escalation via Shared Object Injection
We are looking for somewhere that we can inject.
find / -type f -perm -04000 -ls 2>/dev/null
Something happens when we run the binary
We will use a tool called strace to figure out what the binary is doing.
strace /usr/local/bin/suid-so 2>&1
strace /usr/local/bin/suid-so 2>&1 | grep -i -E "open|access|no such file"
We will overwrite libcalc.so and put something malicious in it so that when the binary suid-so runs, we can elevate our privileges.
We have read-write access on /home/user.
Let us create our malicious code, and save it us libcalc.c
libcal.c
Now we just need to run /usr/local/bin/suid-so
And we are root!!!
Escalation via Binary Symlinks
This is a vulnerability on nginx. It has to do with the permissions of the logs created by Nginx. Because of how the permissions are set, attackers can escalate their privileges from a www-data user to root.