Last active
October 30, 2018 20:35
-
-
Save catb0t/9ee27b17d25560b3ac6d0ee938284040 to your computer and use it in GitHub Desktop.
setuidtest explicit w/syscalls
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
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <sys/syscall.h> | |
void printid(void) { | |
uid_t r, e, s; | |
getresuid(&r, &e, &s); | |
printf("real: %d eff: %d saved: %d\n", r, e, s); | |
} | |
int main(void) { | |
printid(); | |
if (seteuid(0) != 0) { | |
puts("ERROR Cannot gain root priviledges"); | |
printid(); | |
return 1; | |
} else | |
puts("Gained root priviledges"); | |
printid(); | |
// if (setuid(getuid()) != 0) { | |
if (syscall(SYS_setuid, syscall(SYS_getuid)) != 0) { | |
puts("ERROR Dropping priviledges failed"); | |
printid(); | |
return 1; | |
} else | |
puts("Dropped root priviledges"); | |
printid(); | |
// if (setuid(0) == 0) { | |
if (syscall(SYS_setuid, 0) == 0) { | |
puts("ERROR Still able to recover root"); | |
printid(); | |
return 1; | |
} else | |
puts("Unable to recover root"); | |
printid(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment