-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivdo.c
51 lines (43 loc) · 1.1 KB
/
privdo.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/***************************************************
*
* Name: privdo
* Description: Utility to run a program as EUID
* Author: 000exploit
* Purpose: Exploring the possibility of increasing/
* lowering program priviliges to run soft-
* ware with different access rights.
*
***************************************************/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
const char helpmsg[] = "Usage:\n\tprivdo [command] [args]";
int main(int argc, char* argv[]) {
if ((argc < 2) || strcmp(argv[1], "-h") == 0) {
fprintf(stderr, "%s\n", helpmsg);
return 1;
}
int uid = getuid();
int euid = geteuid();
if (uid == euid) {
puts("Do \"chmod u+s privdo\" or change the user.");
return 2;
}
int suid = setuid(euid);
if (suid < 0) {
perror("setuid");
}
struct passwd *pw = getpwuid(euid);
if(pw == NULL) {
perror("getpwuid");
return 3;
} else {
printf("Executing command %s as user %s with argument %s\n",
argv[1], pw->pw_name, argv[2]);
}
int exec = execvp(argv[1], argv+1);
perror(argv[1]);
return exec;
}