> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/priv-esc/linux-privilege-escalation/linux-privilege-escalation-checklist.md).

# Linux Privilege Escalation Checklist

## Checklist for Linux <a href="#references" id="references"></a>

### Access and Permission Checks

<details>

<summary>Check user's sudo privileges</summary>

List what commands the user can run as root, especially if there is a `.sudo_as_admin_successful` file in the users home directory.

```bash
sudo -l
```

</details>

<details>

<summary>Check for SUID/SGID Files</summary>

**SUID**

Locate SUID files (list filenames only)

```bash
find / -type f -perm /4000 2>/dev/null
```

Locate SUID files (`ls`-like listing)

```bash
find / -type f -perm /4000 -ls 2>/dev/null
```

**SGID**

Locate SGID files (list filenames only)

```bash
find / -type f -perm /2000 2>/dev/null
```

Locate SGID files (`ls`-like listing)

```bash
find / -type f -perm /2000 -ls 2>/dev/null
```

**SUID or SGID**

Locate SUID or SGID files (`ls`-like listing)

```bash
find / -type f -perm /6000 -ls 2>/dev/null
```

or

```bash
find / -type f -a \( -perm -u+s -o -perm -g+s \) -ls 2> /dev/null
```

</details>

<details>

<summary>Check for capabilities</summary>

Search the whole file system recursively for files with capabilities

```bash
getcap -r / 2>/dev/null
```

</details>

<details>

<summary>Check for weak file permissions</summary>

Check for writeable `/etc/passwd` or accessable (read or write) `/etc/shadow` file

```bash
ls -l /etc/passwd
ls -l /etc/shadow
```

Check for readable SSH private files

```bash
ls -l /home/<user>/.ssh
ls -l /root/.ssh
```

Check for writeable `/etc/sudoers` file

```bash
ls -l /etc/sudoers
echo "`whoami` ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
```

</details>

### Credential Checks

<details>

<summary>Check for passwords in history files</summary>

Check for passwords in user's history files

```bash
ls -l ~/.*history
cat ~/.*history | more
```

</details>

<details>

<summary>Check for DB password in wp-config.php</summary>

Check for database password(s) in the file `/var/www/html/wp-config.php` if the machine is running Wordpress

```bash
www-data@ColddBox-Easy:/var/www/html$ cat wp-config.php
<?php
<---snip--->
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'colddbox');

/** MySQL database username */
define('DB_USER', 'c0ldd');

/** MySQL database password */
define('DB_PASSWORD', 'cybersecurity');
<---snip--->
```

Reference: <https://developer.wordpress.org/advanced-administration/wordpress/wp-config/>

Also check if the password can be re-used for SSH-login etc.

</details>

<details>

<summary>Check for passwords in config.php files</summary>

Search for `config.php` files under `/var/www/html` and `grep` for passwords

```bash
find . -name config.php | xargs grep -i password
```

</details>

<details>

<summary>Check for passwords in script files</summary>

Search for passwords in various script files

```bash
find / -iname '*.sh' -or -iname '*.py' -or -iname '*.php' -or -iname '*.pl' 2>/dev/null | xargs grep -C 2 -i password
```

</details>

<details>

<summary>Check for credentials in e-mails</summary>

Check for credentials in e-mails under these directories

```bash
ls -l /var/mail
ls -l /var/spool/mail/
```

</details>

<details>

<summary>Check for passwords in environment variables</summary>

Check environment variables for credentials or any other interesting info

```bash
env
```

</details>

<details>

<summary>Check for passwords in .env files</summary>

```bash
find / -type f -name .env 2>/dev/null
```

</details>

### Processes, Services and Cron job Checks

<details>

<summary>Check for running processes</summary>

**List processes for specific user(s)**

List processes running as UID 0 (root)

```bash
ps u -u 0
```

List processes running as `root` or `kali`

```bash
ps u -u root,kali
```

**List ALL running processes**

With Unix options

```bash
ps -ef
```

With BSD options, list output

```bash
ps aux
```

With BSD options, tree view

```bash
ps axjf
```

</details>

<details>

<summary>Check for listening services</summary>

Check for TCP  & UDP services listening on 127.0.0.1 only

```bash
netstat -tunlp | grep 127.0.0.1
```

```bash
sudo netstat -tunlp | grep 127.0.0.1
```

Check for all TCP-services listening&#x20;

```bash
netstat -tln
```

Check for all UDP-services listening&#x20;

```bash
netstat -uln
```

</details>

<details>

<summary>Check for Cron jobs</summary>

Check for:

* Writable scripts or services
* Abnormal directories in PATH variable

Check current crontab

```bash
crontab -l
```

Check scheduled task files

```bash
ls -lah /etc/cron*
```

Check system-wide crontab

```bash
cat /etc/crontab
```

Check for CRON-messages in syslog file

```bash
grep "CRON" /var/log/syslog
```

</details>

### Search for interesting files

<details>

<summary>Check for hidden files and directories</summary>

Check for hidden files under `/home`

```bash
find /home -type f -name '.*' 2>/dev/null
```

Check for hidden directories (excluding `/home`)

```bash
find / -type d -not -path '/home/*' -name '.*' 2>/dev/null
```

Check for hidden directories (entire file system)

```bash
find / -type d -name '.*' 2>/dev/null
```

</details>

<details>

<summary>Check for script files</summary>

Check for script files

```bash
find / -iname '*.sh' -or -iname '*.csh' -or -iname '*.zsh' -or -iname '*.py' 2>/dev/null
```

Check for **writable** script files

```bash
find / -writable -iname '*.sh' -or -iname '*.csh' -or -iname '*.zsh' -or -iname '*.py' 2>/dev/null
```

</details>

<details>

<summary>Check for alternate groups</summary>

Check if the current user is a member of any additional groups

```bash
weston@national-treasure:~$ id
uid=1001(weston) gid=1001(weston) groups=1001(weston),1000(cage)
```

And then search for files belonging to this group

```bash
find / -type f -group cage 2>/dev/null
```

</details>

### Exploit Checks

<details>

<summary>Check for vulnerable kernel version</summary>

Check if the kernel version is vulnerable to known exploits

<pre class="language-bash"><code class="lang-bash"><strong>uname -a
</strong></code></pre>

**Overlayfs**\
Version: 3.13.0 < 3.19\
CVE: [CVE-2015-1328](https://nvd.nist.gov/vuln/detail/CVE-2015-1328)\
Exploit: <https://www.exploit-db.com/exploits/37292>

**Dirty Cow**\
Version: 2.6.18 - 4.8.0\
CVE: [CVE-2016-5195](https://nvd.nist.gov/vuln/detail/CVE-2016-5195)\
Exploit: <https://www.exploit-db.com/exploits/40616>\
Ref: <https://en.wikipedia.org/wiki/Dirty_COW>

</details>

<details>

<summary>Check for vulnerable policykit</summary>

Check the versions of these packages

```bash
apt list policykit-1
apt list polkit
```

**Pwnkit**\
Version: <= 0.105-31\
CVE: [CVE-2021-4034](https://nvd.nist.gov/vuln/detail/cve-2021-4034)\
Exploit: <https://github.com/joeammond/CVE-2021-4034>\
Ref: <https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt>

</details>

### Miscellaneous Checks <a href="#references" id="references"></a>

<details>

<summary>Check for file systems and disks</summary>

Check for both mounted and available file systems

```bash
mount
```

```bash
cat /etc/fstab
```

```bash
lsblk
```

</details>

## World-writable Directories <a href="#references" id="references"></a>

The three most commonly cited world-writable directories in Linux (typically with mode 1777 - world-writable plus the sticky bit set) are:

1. **`/tmp`** – The standard temporary directory. Any user can create, read, and execute files here, though the sticky bit means only the file's owner (or root) can delete or rename it.
2. **`/var/tmp`** – Similar purpose to `/tmp`, but intended for temporary files that should persist across reboots (files here are typically not cleared on boot, unlike `/tmp` on many distros).
3. **`/dev/shm`** – A tmpfs-backed shared memory directory. It's world-writable and backed by RAM, often used for inter-process communication or as scratch space, and is notably attractive for "fileless" payload execution since it's memory-backed and doesn't touch disk.

## References <a href="#references" id="references"></a>

APT Privilege Escalation - Hacking Articles: <https://www.hackingarticles.in/linux-for-pentester-apt-privilege-escalation/>

capabilities - Linux manual page: <https://man7.org/linux/man-pages/man7/capabilities.7.html>

Capability-based security - Wikipedia: <https://en.wikipedia.org/wiki/Capability-based_security>

cron - Wikipedia: <https://en.wikipedia.org/wiki/Cron>

**crontab**(1) - Linux manual page: <https://man7.org/linux/man-pages/man1/crontab.1.html>

crontab(5) - Linux manual page: <https://man7.org/linux/man-pages/man5/crontab.5.html>

**find** - Linux manual page: <https://man7.org/linux/man-pages/man1/find.1.html>

fstab - Linux manual page: <https://man7.org/linux/man-pages/man5/fstab.5.html>

**getcap** - Linux manual page: <https://man7.org/linux/man-pages/man8/getcap.8.html>

Linux - Privilege Escalation - Internal All The Things: <https://swisskyrepo.github.io/InternalAllTheThings/redteam/escalation/linux-privilege-escalation/>

Linux Capabilities - HackTricks: <https://book.hacktricks.xyz/linux-hardening/privilege-escalation/linux-capabilities>

Linux Privilege Escalation using Capabilities - Hacking Articles: <https://www.hackingarticles.in/linux-privilege-escalation-using-capabilities/>

**lsblk** - Linux manual page: <https://man7.org/linux/man-pages/man8/lsblk.8.html>

**mount** - Linux manual page: <https://man7.org/linux/man-pages/man8/mount.8.html>

**netstat** - Linux manual page: <https://man7.org/linux/man-pages/man8/netstat.8.html>

Setuid - Wikipedia: <https://en.wikipedia.org/wiki/Setuid>

**sudo** - Wikipedia: <https://en.wikipedia.org/wiki/Sudo>

**xargs** - Linux manual page: <https://www.man7.org/linux/man-pages/man1/xargs.1.html>
