Sudo
sudo -l
Enumeration
The command sudo allows the current user to execute certain commands as other users. To view a list of such commands:
sudo -lIn the trivial case, the current user can execute any command as any user:

In this case we can spawn a root shell directly:
Method 1: GTFOBins
For a privesc cheatsheet, check out GTFOBins:
Examples
If find is in sudo -l:
If awk is in sudo -l:
If nmap is in sudo -l:
If vim is in sudo -l:
Method 2: Intended Functionality
apache2
If apache2 is in sudo -l, then we can read the root password hash from /etc/shadow by triggering an error:
wget
A wget privesc example:
Method 3: LD_PRELOAD
LD_PRELOAD is an environment variable that lists shared libraries with functions that override the standard set, just as /etc/ld.so.preload does. These are implemented by the loader /lib/ld-linux.so.
If sudo -l finds LD_PRELOAD as well as some sudo command, for example, /usr/sbin/apache2:
then we can utilize this "feature" for privilege escalation. Store the following C program in /tmp:
Compile it:
Trigger it with any sudo command (this command can be anything, here apache2 is just an example):
Then we will get a root shell.
Method 4: Attacking Sudo Itself
CVE-2019-14287
If sudo -l shows we can execute /bin/bash as any user other than root:
Joe Vennix found that if you specify a UID of -1 (or its unsigned equivalent: 4294967295), Sudo would incorrectly read this as being 0 (i.e. root). This means that by specifying a UID of -1 or 4294967295, you can execute a command as root, despite being explicitly prevented from doing so.
That means we can get a root shell using the following payload:
Test this CVE in TryHackMe:
CVE-2019-18634
In /etc/sudoers, there is an option named pwfeedback, which is turned off by default. If it is turned on, Linux will give you "feedback" when you type password by showing a asterisk for each character you type.
In Sudo 1.8.25p, this pwfeedback option leads to buffer overflow vulnerability if it is turned on. To exploit this vulnerability, download the C source code:
Compile it:
Give permission and run it:
Test this CVE in TryHackMe:
Challenge: TryHackMe - Simple CTF
Last updated
Was this helpful?



