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
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
// this one is safe according to http://www.unixwiz.net/techtips/chroot-practices.html
void chroot_safe1(){
chdir("/tmp");
if (chroot("/tmp") != 0) {
perror("chroot /tmp");
}
setuid(1077);
}
void chroot_safe2(){
chdir("/tmp");
if (chroot("/tmp") != 0) {
perror("chroot /tmp");
}
setresuid(1077, 1077, 1077);
}
void chroot_safe3(){
chdir("/tmp");
if (chroot("/tmp") != 0) {
perror("chroot /tmp");
}
setreuid(1077, 44);
}
void chroot_safe4(){
chdir("/tmp");
if (chroot("/tmp") != 0) {
perror("chroot /tmp");
}
seteuid(1077);
}
int main(void) {
chroot_safe1();
chroot_safe2();
chroot_safe3();
chroot_safe4();
}