Sudo
sudo -l
Last updated
sudo -l
Last updated
Always check sudo -l
at the beginning of the privilege escalation phase.
The command sudo
allows the current user to execute certain commands as other users. To view a list of such commands:
In the trivial case, the current user can execute any command as any user:
In this case we can spawn a root shell directly:
For a privesc cheatsheet, check out GTFOBins:
If find
is in sudo -l
:
If awk
is in sudo -l
:
If nmap
is in sudo -l
:
If vim
is in sudo -l
:
If apache2
is in sudo -l
, then we can read the root password hash from /etc/shadow
by triggering an error:
A wget
privesc example:
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.
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:
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: