Skip to content

Instantly share code, notes, and snippets.

@catb0t
Last active October 30, 2018 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catb0t/9ee27b17d25560b3ac6d0ee938284040 to your computer and use it in GitHub Desktop.
Save catb0t/9ee27b17d25560b3ac6d0ee938284040 to your computer and use it in GitHub Desktop.
setuidtest explicit w/syscalls
#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