Created
August 19, 2018 12:25
-
-
Save jachermocilla/c06916cbedd7f391fb5a5955a8d45208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* setuid example by [email protected] | |
* | |
* $gcc -o mysuid.exe mysuid.c | |
* $sudo chown root.root mysuid.exe | |
* $sudo chmod 4755 mysuid.exe | |
* | |
* Note: must be run in a filesystem mounted with no 'nosuid' | |
* ex: /tmp | |
* | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
int main(void) | |
{ | |
uid_t current_uid; | |
printf("RUID=%d, EUID=%d, GID=%d\n", getuid(), geteuid(), getgid()); | |
system("cat /etc/shadow"); | |
if (setuid(0)){ | |
perror("setuid"); | |
return 1; | |
} | |
printf("RUID=%d, EUID=%d, GID=%d\n", getuid(), geteuid(), getgid()); | |
system("cat /etc/shadow"); | |
setuid(current_uid); | |
printf("RUID=%d, EUID=%d, GID=%d\n", getuid(), geteuid(), getgid()); | |
system("cat /etc/shadow"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment