-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusrmgr.c
43 lines (42 loc) · 1.11 KB
/
usrmgr.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
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <shadow.h>
#include <crypt.h>
#include <string.h>
#include <grp.h>
int main(int argc, char* argv[]) {
struct passwd* passwdEntry = getpwuid(getuid());
struct spwd* shadowEntry = getspnam(passwdEntry->pw_name);
struct group* wheel = getgrnam("wheel");
int ngroups = 0;
getgrouplist(passwdEntry->pw_name, passwdEntry->pw_gid, NULL, &ngroups);
__gid_t groups[ngroups];
getgrouplist(passwdEntry->pw_name, passwdEntry->pw_gid, groups, &ngroups);
for (int i = 0; i < ngroups; i++) {
struct group* gr = getgrgid(groups[i]);
if(gr->gr_gid == wheel->gr_gid) {
char* password = getpass("#: ");
if(!strcmp(shadowEntry->sp_pwdp, crypt(password, shadowEntry->sp_pwdp))) {
int len = (argc-1);
for(int i = 1; i < argc; i++) {
len += strlen(argv[i]);
}
char* cmd = malloc(len);
strcpy(cmd, "");
for(int i = 1; i < argc; i++) {
strcat(cmd, argv[i]);
if(i < argc - 1)
strcat(cmd, " ");
}
setuid(0);
system(cmd);
free(cmd);
} else
return 1;
break;
} else
return 1;
}
}