---
description: Linux Privilege Escalation
---

# SUID Shenanigans

[Privilege Escalation](https://payatu.com/guide-linux-privilege-escalation) is the act of exploiting a bug, design flaw or configuration oversight in an operating system or software application to gain elevated access to resources that are normally protected from an application or user.

### What is SUID

Set owner UserID up on execution is a special type of file permission given to a file. When a user runs a program, given they have the correct reading/executing rights, it will run using their account privileges. SUID allows a user to run a program using another users privileges.

In some cases, we can take advantage of having a file run as another user, to execute commands as them. If a binary has the SUID bit set, it will have an **s** appear. If we check the file permissions of the passwd binary, we can see the permissions are -**rwsr-xr-x**.

The SUID bit is set on the execute permission, meaning when a user runs this, it will run as the file owner (which is root).

**In essence, SUID files execute with the permission of the file owner.**

### **Taking advantage of SUID files**

Some administrators will set the SUID bit manually to allow certain programs to be run as them. Lets say you're a system administrator and a non-privileged user wants to program that requires it to be run with higher privileges. They can set the SUID bit, then the non-privileged user can execute the program without having any extra account permissions set.

We can scan the whole file system to find all files with the SUID bit set, with the following code:

`find / -user root -perm -4000 -exec ls -ldb {} \;`

The find command has a parameter where it can execute commands. So when it finds a file, it will list its permissions. If a sysadmin has manually set an SUID bit on a binary, the code above will find it.

[GTFOBins](https://gtfobins.github.io/) is a curated list of Unix binaries that can be exploited by an attacker to bypass local security restrictions. When we find the SUID binaries we can search on this list to see how to exploit them.

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7T9a5AN5rHd3kXJg7U%2Fimage.png?alt=media\&token=1e6bac74-d778-4efd-8d5b-230380fbe415)

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TA1wPRlnc_8bW1Nx8%2Fimage.png?alt=media\&token=2da88d49-fde9-40cb-b37e-e74b2022c303)

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TAk2FNaGXu9fi3a6L%2Fimage.png?alt=media\&token=9e477209-aa53-47f9-94fa-e58160142e6e)

First step is to ssh into the machine on port 65534

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TAsDGSvtItN0cmIGy%2Fimage.png?alt=media\&token=0bb65fa3-857a-4a25-bae8-2f2dba4e8aa2)

Once in we can see that holly doesnt have to read the `flag1.txt` file&#x20;

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TB6NjJU8z3JWAQwrq%2Fimage.png?alt=media\&token=ba402d85-58d4-4cbf-b242-db00cda8458b)

Searching the system for files with the SUID bit set, we can see that we can run `find` as other user.

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TCTd3X4dWHnD4rg6n%2Fimage.png?alt=media\&token=424701a1-c895-4723-ac7b-943829facb2f)

By running the find command we can execute other commands, like `cat` which can help us read the `flag1.txt`

`find /home/igor -name flag1.txt -exec cat flag1.txt {} \;`

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TCpYy4SZeKGS_BYxU%2Fimage.png?alt=media\&token=696e0b33-de8e-46a1-a3c9-362da6a4ef51)

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7THGy5_53MA2O5BT_N%2Fimage.png?alt=media\&token=c534c51a-1c1a-43d9-b5c8-fa0dd937e67f)

After searching for all the files owned by root with the SUID bit set, and going through all of them in GTFOBins website, I couldn't find a way to get root. The binary `system-control` caught my attention and somehow I thought it was related to `systemctl`. In the end, all I that was a stupid assumption, because the only thing I needed to to was to run the binary.

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TI1gjxBqtd2AuOn0r%2Fimage.png?alt=media\&token=2210bd1f-a50e-4ad5-951a-31f297f66a2d)

{% hint style="info" %}
Stop complicating things. If in doubt just run the damn binary instead of going around in circles.


{% endhint %}

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7T6gjTndJJnbBKsQY6%2F-M7TIHpZZYUIyjHxGhHR%2Fimage.png?alt=media\&token=87382d87-f997-4f04-bcc3-6b72837ab0f3)
