-
Notifications
You must be signed in to change notification settings - Fork 7
/
testsuite
executable file
·293 lines (244 loc) · 10.6 KB
/
testsuite
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/sh
#
# Small testsuite to make sure parsing works and rules are applied
#
ecount=0
_warn() {
cat >&2 <<EOF
testsuite: $*
EOF
}
_die() {
_warn $*
exit 1
}
_echo() {
case `uname -s` in
SunOS)
/usr/ucb/echo $*
;;
Darwin)
/bin/echo $*
;;
*)
echo $*
;;
esac
}
_run() {
shift
host=$1
shift 2
port=$1
shift 3
"$WD/coc" -t stderr $1 $2 $3 $4 $5 $6 $7 $8 $9 -- "$WD/tcpcontest" "$host" "$port"
}
_header() {
_echo -n "Checking if we" $* "... "
}
_footer() {
if test $? -eq 0; then
_echo "OK"
else
_echo "KO"
ecount=`expr $ecount + 1`
fi
}
ALLOW() {
_header ALLOW $*
_run $* -l allow 2>&1 >/dev/null | grep ALLOW >/dev/null
_footer
}
BLOCK() {
_header BLOCK $*
_run $* -l block 2>&1 >/dev/null | grep BLOCK >/dev/null
_footer
}
ABORT_ON() {
_header "abort on" $*
_run $* -l error 2>&1 >/dev/null | grep ERROR >/dev/null
_footer
}
WD="`dirname $0`"
test -f "$WD/tcpcontest" || _die "Missing tcpcontest helper program!"
ALLOW host ::1 port 50 with args -a ::1 -b \'*\'
ALLOW host ::1 port 50 with args -a [::1] -b \'*\'
ALLOW host ::1 port 50 with args -a [::1]:50 -b \'*\'
BLOCK host ::1 port 50 with args -a [::1]:49 -b \'*\'
ALLOW host ::1 port 21 with args -a [::1]:ftp -b \'*\'
ALLOW host a::f port 50 with args -a a::f -b \'*\'
BLOCK host a::f port 50 with args -b [a::f]:50
ALLOW host 2001:db8:0:1:1:1:1:1 port 50 with args -a 2001:db8:0:1:1:1:1:1 -b \'*\'
ALLOW host 127.0.0.1 port 50 with args -a 127.0.0.1:50 -b \'*\'
ALLOW host 127.0.0.1 port 50 with args -a 127.0.0.1 -b \'*\'
BLOCK host 127.0.0.1 port 50 with args -a 127.0.0.1:49 -b \'*\'
ALLOW host 127.0.0.1 port 50 with args
ALLOW host 127.0.0.1 port 50 with args -a \'*\'
BLOCK host 127.0.0.1 port 50 with args -b \'*\'
ALLOW host localhost port 50 with args -a localhost -b \'*\'
BLOCK host localhost port 50 with args -a localhost:49 -b \'*\'
ALLOW host 127.0.0.1 port 80 with args -a ::ffff:7f00:1 -b \'*\'
BLOCK host 127.0.0.2 port 80 with args -a ::ffff:7f00:1 -b \'*\'
ALLOW host 127.0.0.1 port 80 with args -a [::ffff:7f00:1]:80 -b \'*\'
BLOCK host 127.0.0.1 port 80 with args -a [::ffff:7f00:1]:81 -b \'*\'
ALLOW host ::ffff:7f00:1 port 80 with args -a 127.0.0.1 -b \'*\'
BLOCK host ::ffff:7f00:2 port 80 with args -a 127.0.0.1 -b \'*\'
ALLOW host ::ffff:7f00:1 port 80 with args -a 127.0.0.1:80 -b \'*\'
BLOCK host ::ffff:7f00:1 port 80 with args -a 127.0.0.1:81 -b \'*\'
ALLOW host www.google.com port 80 with args -d -a \'*.google.com\' -a \'*.1e100.net\' -b \'*\'
#ALLOW host lwn.net port 80 with args -a lwn.net:80 -b \'*\'
ABORT_ON host www.google.com port 80 with args -a \'*.google.com\' -a \'*.1e100.net\' -b \'*\'
ABORT_ON host ::1 port 80 with args -a ab::g
ABORT_ON host ::1 port 80 with args -a :::1
ABORT_ON host ::1 port 80 with args -a a::b::a
ABORT_ON host ::1 port 80 with args -a fffff::
ABORT_ON host localhost port 80 with args -a 256.168.10.192
ABORT_ON host ::1 port 80 with args -a 256:fffff::
# CIDR notation test
## IPv4
### Standard
ALLOW host 127.0.0.1 port 80 with args -a 127.0.0.1 -b \'*\'
ALLOW host 127.0.0.1 port 80 with args -a 127.0.0.1/24 -b \'*\'
BLOCK host 127.0.1.1 port 80 with args -a 127.0.0.1/24 -b \'*\'
BLOCK host 127.0.0.1 port 80 with args -b 127.0.0.1
### With port
ALLOW host 127.0.0.1 port 80 with args -a 127.0.0.0/24:80 -b \'*\'
BLOCK host 127.0.0.1 port 80 with args -a 127.0.0.0/24:81 -b \'*\'
BLOCK host 127.0.1.0 port 80 with args -a 127.0.0.0/24:80 -b \'*\'
BLOCK host 127.0.0.1 port 80 with args -b 127.0.0.0/24:80
ALLOW host 127.0.0.0 port 21 with args -a 127.0.0.0/24:ftp -b \'*\'
### Invalid syntax
ABORT_ON host 127.0.0.1 port 80 with args -a 127.0.0.1/-1 -b \'*\'
ABORT_ON host 127.0.0.1 port 80 with args -a 127.0.0.1/33 -b \'*\'
ABORT_ON host 127.0.0.1 port 80 with args -a 127.0.0.1/a -b \'*\'
ABORT_ON host 127.0.0.1 port 80 with args -a 127.0.0.1/ -b \'*\'
ABORT_ON host 127.0.0.1 port 80 with args -a 127.0.0.1/24/24 -b \'*\'
ABORT_ON host 127.0.0.1 port 80 with args -a 127.0.0.1:80/24 -b \'*\'
ABORT_ON host 127.0.0.1 port 80 with args -a 127.0.0/24.1 -b \'*\'
### 32bit mask
ALLOW host 127.0.0.1 port 80 with args -a 127.0.0.1/32 -b \'*\'
BLOCK host 127.0.0.2 port 80 with args -a 127.0.0.1/32 -b \'*\'
BLOCK host 127.0.0.1 port 80 with args -a 0.0.0.0/32 -b \'*\'
BLOCK host 127.0.0.1 port 80 with args -a 255.255.255.255/32 -b \'*\'
### 31bit mask
BLOCK host 127.0.0.1 port 80 with args -a 127.0.0.2/31 -b \'*\'
ALLOW host 127.0.0.2 port 80 with args -a 127.0.0.2/31 -b \'*\'
ALLOW host 127.0.0.3 port 80 with args -a 127.0.0.2/31 -b \'*\'
BLOCK host 127.0.0.4 port 80 with args -a 127.0.0.2/31 -b \'*\'
### 1bit mask
ALLOW host 1.0.0.0 port 80 with args -a 127.0.0.0/1 -b \'*\'
ALLOW host 127.255.255.255 port 80 with args -a 127.0.0.0/1 -b \'*\'
#BLOCK host 128.0.0.1 port 80 with args -a 127.0.0.0/1 -b \'*\'
BLOCK host 255.255.255.255 port 80 with args -a 127.0.0.0/1 -b \'*\'
### 0bit mask
ALLOW host 0.0.0.1 port 80 with args -a 127.0.0.0/0 -b \'*\'
ALLOW host 0.0.1.0 port 80 with args -a 127.0.0.0/0 -b \'*\'
ALLOW host 0.1.0.0 port 80 with args -a 127.0.0.0/0 -b \'*\'
ALLOW host 1.0.0.0 port 80 with args -a 127.0.0.0/0 -b \'*\'
ALLOW host 127.255.255.255 port 80 with args -a 127.0.0.0/0 -b \'*\'
#ALLOW host 128.0.0.1 port 80 with args -a 127.0.0.0/0 -b \'*\'
ALLOW host 255.255.255.255 port 80 with args -a 127.0.0.0/0 -b \'*\'
ALLOW host 127.0.0.1 port 80 with args -a 0.0.0.0/0 -b \'*\'
ALLOW host 127.0.0.1 port 80 with args -a 255.255.255.255/0 -b \'*\'
## IPv6
### Standard
ALLOW host ::1 port 80 with args -a ::1 -b \'*\'
ALLOW host ::1 port 80 with args -a ::1/24 -b \'*\'
ALLOW host ::1 port 80 with args -a [::1/24] -b \'*\'
BLOCK host a::1 port 80 with args -a ::1/24 -b \'*\'
BLOCK host ::1 port 80 with args -b ::1
### With port
ALLOW host ::1 port 80 with args -a [::1/24]:80 -b \'*\'
BLOCK host ::1 port 80 with args -a [::1/24]:81 -b \'*\'
BLOCK host a::1 port 80 with args -a [::1/24]:80 -b \'*\'
BLOCK host ::1 port 80 with args -b [::1/24]:80
ALLOW host ::1 port 21 with args -a [::1/24]:ftp -b \'*\'
### Invalid syntax
ABORT_ON host ::1 port 80 with args -a ::1/-1 -b \'*\'
ABORT_ON host ::1 port 80 with args -a ::1/129 -b \'*\'
ABORT_ON host ::1 port 80 with args -a ::1/a -b \'*\'
ABORT_ON host ::1 port 80 with args -a ::1/ -b \'*\'
ABORT_ON host ::1 port 80 with args -a ::1/24/24 -b \'*\'
ABORT_ON host ::1 port 80 with args -a [::1]/24 -b \'*\'
ABORT_ON host ::1 port 80 with args -a [::1/24/24] -b \'*\'
ABORT_ON host ::1 port 80 with args -a [::1/24]:80:80 -b \'*\'
ABORT_ON host ::1 port 80 with args -a [::1]:80/24 -b \'*\'
ABORT_ON host ::1 port 80 with args -a [:1:/24:1] -b \'*\'
ABORT_ON host ::1 port 80 with args -a /24[::1] -b \'*\'
### 128bit mask
ALLOW host ::1 port 80 with args -a ::1/128 -b \'*\'
BLOCK host ::2 port 80 with args -a ::1/128 -b \'*\'
BLOCK host ::1 port 80 with args -a ::0/128 -b \'*\'
BLOCK host ::1 port 80 with args -a 2001:db8:0:1:1:1:1:1/128 -b \'*\'
ALLOW host 2001:db8:0:1:1:1:1:1 port 80 with args -a 2001:db8:0:1:1:1:1:1/128 -b \'*\'
### 127bit mask
BLOCK host ::1 port 80 with args -a ::2/127 -b \'*\'
ALLOW host ::2 port 80 with args -a ::2/127 -b \'*\'
ALLOW host ::3 port 80 with args -a ::2/127 -b \'*\'
BLOCK host ::4 port 80 with args -a ::2/127 -b \'*\'
### 1bit mask
BLOCK host ::0 port 80 with args -a 8000::/1 -b \'*\'
BLOCK host 7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff port 80 with args -a 8000::/1 -b \'*\'
ALLOW host 8000:: port 80 with args -a 8000::/1 -b \'*\'
ALLOW host ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff port 80 with args -a 8000::/1 -b \'*\'
### 0bit mask
ALLOW host 2001:db8:0:1:1:1:1:1 port 80 with args -a 8000::/0 -b \'*\'
ALLOW host ::0 port 80 with args -a 8000::/0 -b \'*\'
ALLOW host ::1 port 80 with args -a 8000::/0 -b \'*\'
ALLOW host ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff port 80 with args -a 8000::/0 -b \'*\'
ALLOW host ::1 port 80 with args -a ::0/0 -b \'*\'
ALLOW host ::1 port 80 with args -a ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0 -b \'*\'
## Rule IP is IPv4 mapping
### With port
ALLOW host 127.1.1.1 port 80 with args -a [::ffff:7f01:101/128]:80 -b \'*\'
BLOCK host 127.1.1.1 port 80 with args -a [::ffff:7f01:101/128]:81 -b \'*\'
### 128bit mask
ALLOW host 127.1.1.1 port 80 with args -a ::ffff:7f01:101/128 -b \'*\'
BLOCK host 127.1.1.2 port 80 with args -a ::ffff:7f01:101/128 -b \'*\'
BLOCK host 128.1.1.1 port 80 with args -a ::ffff:7f01:101/128 -b \'*\'
### 127bit mask
BLOCK host 127.0.0.1 port 80 with args -a ::ffff:7f00:2/127 -b \'*\'
ALLOW host 127.0.0.2 port 80 with args -a ::ffff:7f00:2/127 -b \'*\'
ALLOW host 127.0.0.3 port 80 with args -a ::ffff:7f00:2/127 -b \'*\'
BLOCK host 127.0.0.4 port 80 with args -a ::ffff:7f00:2/127 -b \'*\'
### 97bit mask
ALLOW host 1.0.0.0 port 80 with args -a ::ffff:7f01:101/97 -b \'*\'
ALLOW host 127.255.255.255 port 80 with args -a ::ffff:7f01:101/97 -b \'*\'
BLOCK host 128.0.0.0 port 80 with args -a ::ffff:7f01:101/97 -b \'*\'
### 96bit mask
ALLOW host 127.0.0.1 port 80 with args -a ::ffff:7f01:101/96 -b \'*\'
ALLOW host 128.1.1.2 port 80 with args -a ::ffff:7f01:101/96 -b \'*\'
### These are not treated as ipv4 mapped address because the rule side is masked.
BLOCK host 127.0.0.1 port 80 with args -a ::ffff:7f00:1/0 -b \'*\'
BLOCK host 127.0.0.1 port 80 with args -a ::ffff:7f00:1/95 -b \'*\'
## Connect IP is IPv4 mapping
### With port
ALLOW host ::ffff:7f01:101 port 80 with args -a 127.1.1.1/32:80 -b \'*\'
BLOCK host ::ffff:7f01:101 port 80 with args -a 127.1.1.1/32:81 -b \'*\'
### 32bit mask
ALLOW host ::ffff:7f01:101 port 80 with args -a 127.1.1.1/32 -b \'*\'
BLOCK host ::ffff:7f01:101 port 80 with args -a 127.1.1.2/32 -b \'*\'
BLOCK host ::ffff:7f01:101 port 80 with args -a 128.1.1.1/32 -b \'*\'
BLOCK host ::ffff:7f01:102 port 80 with args -a 127.1.1.1/32 -b \'*\'
### 31bit mask
BLOCK host ::ffff:7f01:102 port 80 with args -a 127.1.1.1/31 -b \'*\'
ALLOW host ::ffff:7f01:102 port 80 with args -a 127.1.1.2/31 -b \'*\'
ALLOW host ::ffff:7f01:102 port 80 with args -a 127.1.1.3/31 -b \'*\'
BLOCK host ::ffff:7f01:102 port 80 with args -a 127.1.1.4/31 -b \'*\'
### 1bit mask
ALLOW host ::ffff:7f01:101 port 80 with args -a 127.1.1.1/1 -b \'*\'
ALLOW host ::ffff:7f01:101 port 80 with args -a 127.1.1.2/1 -b \'*\'
ALLOW host ::ffff:7f01:101 port 80 with args -a 127.1.2.1/1 -b \'*\'
ALLOW host ::ffff:7f01:101 port 80 with args -a 127.2.1.1/1 -b \'*\'
BLOCK host ::ffff:7f01:101 port 80 with args -a 128.1.1.1/1 -b \'*\'
### 0bit mask
ALLOW host ::ffff:101:101 port 80 with args -a 127.1.1.1/0 -b \'*\'
ALLOW host ::ffff:ffff:ffff port 80 with args -a 127.1.1.1/0 -b \'*\'
## hostname
### Invalid syntax
ABORT_ON host localhost port 80 with args -a localhost/24 -b \'*\'
if test $ecount -gt 0; then
_die "$ecount test(s) failed!"
else
echo "All tests passed!"
fi