diff options
author | 2021-03-08 15:39:03 -0500 | |
---|---|---|
committer | 2021-03-08 15:39:03 -0500 | |
commit | b69074fa495a237aba30e0f43f28c4086df04e04 (patch) | |
tree | feeb68163fa82fd80dc1a644733da66617e70032 /src/jailtest | |
parent | profile fixes (diff) | |
download | firejail-b69074fa495a237aba30e0f43f28c4086df04e04.tar.gz firejail-b69074fa495a237aba30e0f43f28c4086df04e04.tar.zst firejail-b69074fa495a237aba30e0f43f28c4086df04e04.zip |
more jailtest
Diffstat (limited to 'src/jailtest')
-rw-r--r-- | src/jailtest/jailtest.h | 4 | ||||
-rw-r--r-- | src/jailtest/main.c | 29 | ||||
-rw-r--r-- | src/jailtest/sysfiles.c | 88 |
3 files changed, 119 insertions, 2 deletions
diff --git a/src/jailtest/jailtest.h b/src/jailtest/jailtest.h index 10174cc9a..0c4883061 100644 --- a/src/jailtest/jailtest.h +++ b/src/jailtest/jailtest.h | |||
@@ -38,6 +38,10 @@ void access_destroy(void); | |||
38 | void noexec_setup(void); | 38 | void noexec_setup(void); |
39 | void noexec_test(const char *msg); | 39 | void noexec_test(const char *msg); |
40 | 40 | ||
41 | // sysfiles.c | ||
42 | void sysfiles_setup(const char *file); | ||
43 | void sysfiles_test(void); | ||
44 | |||
41 | // virtual.c | 45 | // virtual.c |
42 | void virtual_setup(const char *directory); | 46 | void virtual_setup(const char *directory); |
43 | void virtual_destroy(void); | 47 | void virtual_destroy(void); |
diff --git a/src/jailtest/main.c b/src/jailtest/main.c index 850277bc5..3369dca39 100644 --- a/src/jailtest/main.c +++ b/src/jailtest/main.c | |||
@@ -114,8 +114,32 @@ int main(int argc, char **argv) { | |||
114 | virtual_setup("/bin"); | 114 | virtual_setup("/bin"); |
115 | virtual_setup("/usr/share"); | 115 | virtual_setup("/usr/share"); |
116 | virtual_setup(user_run_dir); | 116 | virtual_setup(user_run_dir); |
117 | 117 | // basic sysfiles | |
118 | 118 | sysfiles_setup("/etc/shadow"); | |
119 | sysfiles_setup("/etc/gshadow"); | ||
120 | sysfiles_setup("/usr/bin/mount"); | ||
121 | sysfiles_setup("/usr/bin/su"); | ||
122 | sysfiles_setup("/usr/bin/ksu"); | ||
123 | sysfiles_setup("/usr/bin/sudo"); | ||
124 | sysfiles_setup("/usr/bin/strace"); | ||
125 | // X11 | ||
126 | sysfiles_setup("/usr/bin/xev"); | ||
127 | sysfiles_setup("/usr/bin/xinput"); | ||
128 | // compilers | ||
129 | sysfiles_setup("/usr/bin/gcc"); | ||
130 | sysfiles_setup("/usr/bin/clang"); | ||
131 | // networking | ||
132 | sysfiles_setup("/usr/bin/dig"); | ||
133 | sysfiles_setup("/usr/bin/nslookup"); | ||
134 | sysfiles_setup("/usr/bin/resolvectl"); | ||
135 | sysfiles_setup("/usr/bin/nc"); | ||
136 | sysfiles_setup("/usr/bin/ncat"); | ||
137 | sysfiles_setup("/usr/bin/nmap"); | ||
138 | sysfiles_setup("/usr/sbin/tcpdump"); | ||
139 | // terminals | ||
140 | sysfiles_setup("/usr/bin/gnome-terminal"); | ||
141 | sysfiles_setup("/usr/bin/xfce4-terminal"); | ||
142 | sysfiles_setup("/usr/bin/lxterminal"); | ||
119 | 143 | ||
120 | // print processes | 144 | // print processes |
121 | pid_read(0); | 145 | pid_read(0); |
@@ -145,6 +169,7 @@ int main(int argc, char **argv) { | |||
145 | noexec_test("/var/tmp"); | 169 | noexec_test("/var/tmp"); |
146 | noexec_test(user_run_dir); | 170 | noexec_test(user_run_dir); |
147 | access_test(); | 171 | access_test(); |
172 | sysfiles_test(); | ||
148 | } | 173 | } |
149 | else { | 174 | else { |
150 | printf(" Error: I cannot join the process mount space\n"); | 175 | printf(" Error: I cannot join the process mount space\n"); |
diff --git a/src/jailtest/sysfiles.c b/src/jailtest/sysfiles.c new file mode 100644 index 000000000..7e4709453 --- /dev/null +++ b/src/jailtest/sysfiles.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014-2021 Firejail Authors | ||
3 | * | ||
4 | * This file is part of firejail project | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | #include "jailtest.h" | ||
21 | #include <dirent.h> | ||
22 | #include <sys/wait.h> | ||
23 | |||
24 | typedef struct { | ||
25 | char *tfile; | ||
26 | } TestFile; | ||
27 | |||
28 | #define MAX_TEST_FILES 32 | ||
29 | TestFile tf[MAX_TEST_FILES]; | ||
30 | static int files_cnt = 0; | ||
31 | |||
32 | void sysfiles_setup(const char *file) { | ||
33 | // I am root! | ||
34 | assert(file); | ||
35 | |||
36 | if (files_cnt >= MAX_TEST_FILES) { | ||
37 | fprintf(stderr, "Error: maximum number of system test files exceded\n"); | ||
38 | exit(1); | ||
39 | } | ||
40 | |||
41 | if (access(file, F_OK)) { | ||
42 | // no such file | ||
43 | return; | ||
44 | } | ||
45 | |||
46 | |||
47 | char *fname = strdup(file); | ||
48 | if (!fname) | ||
49 | errExit("strdup"); | ||
50 | |||
51 | tf[files_cnt].tfile = fname; | ||
52 | files_cnt++; | ||
53 | } | ||
54 | |||
55 | void sysfiles_test(void) { | ||
56 | // I am root in sandbox mount namespace | ||
57 | assert(user_uid); | ||
58 | int i; | ||
59 | |||
60 | pid_t child = fork(); | ||
61 | if (child == -1) | ||
62 | errExit("fork"); | ||
63 | |||
64 | if (child == 0) { // child | ||
65 | // drop privileges | ||
66 | if (setgid(user_gid) != 0) | ||
67 | errExit("setgid"); | ||
68 | if (setuid(user_uid) != 0) | ||
69 | errExit("setuid"); | ||
70 | |||
71 | for (i = 0; i < files_cnt; i++) { | ||
72 | assert(tf[i].tfile); | ||
73 | |||
74 | // try to open the file for reading | ||
75 | FILE *fp = fopen(tf[i].tfile, "r"); | ||
76 | if (fp) { | ||
77 | |||
78 | printf(" Warning: I can access %s\n", tf[i].tfile); | ||
79 | fclose(fp); | ||
80 | } | ||
81 | } | ||
82 | exit(0); | ||
83 | } | ||
84 | |||
85 | // wait for the child to finish | ||
86 | int status; | ||
87 | wait(&status); | ||
88 | } | ||