forked from slimm609/checksec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardening-checks.sh
executable file
·451 lines (414 loc) · 14.5 KB
/
hardening-checks.sh
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/usr/bin/env bash
DIR=$(
cd "$(dirname "$0")"
pwd
)
PARENT=$(
cd "$(dirname "$0")/.."
pwd
)
(
cd "${DIR}/binaries/"
./build_binaries.sh
)
for bin in all all32 all_cl all_cl32 \
cfi cfi32 sstack sstack32 \
dso.so dso32.so dso_cl.so dso_cl32.so \
none none32 none_cl none_cl32 \
partial partial32 partial_cl partial_cl32 \
rel.o rel32.o rel_cl.o rel_cl32.o \
rpath rpath32 rpath_cl rpath_cl32 \
runpath runpath32 runpath_cl runpath_cl32 \
nolibc nolibc_cl nolibc32 nolibc_cl32 \
fszero fszero_cl fszero32 fszero_cl32; do
if [[ ! -f "${DIR}/binaries/output/${bin}" ]]; then
echo "Could not find test file output/${bin}. Run build_binaries.sh in the binaries folder to generate it."
exit 255
fi
done
#============================================
# file checks
#============================================
echo "Starting RELRO check"
# Full RELRO
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f1) != "Full RELRO" ]]; then
echo "Full RELRO validation failed on \"${bin}\""
exit 1
fi
done
# Partial RELRO
for bin in partial partial32 partial_cl partial_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f1) != "Partial RELRO" ]]; then
echo "Partial RELRO validation failed on \"${bin}\""
exit 1
fi
done
# No RELRO
for bin in none none32 none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f1) != "No RELRO" ]]; then
echo "No RELRO validation failed on \"${bin}\""
exit 1
fi
done
# N/A
for bin in rel.o rel32.o rel_cl.o rel_cl32.o; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f1) != "N/A" ]]; then
echo "N/A RELRO validation failed on \"${bin}\""
exit 1
fi
done
echo "RELRO validation tests passed"
#============================================
echo "Starting Stack Canary check"
# Canary found
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f2) != "Canary found" ]]; then
echo "Stack Canary validation failed on \"${bin}\""
exit 1
fi
done
# No Canary found
for bin in none none32 none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f2) != "No Canary found" ]]; then
echo "No Stack Canary validation failed on \"${bin}\""
exit 1
fi
done
echo "Stack Canary validation tests passed"
#============================================
echo "Starting NX check"
# NX enabled
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f3) != "NX enabled" ]]; then
echo "NX enabled validation failed on \"${bin}\""
exit 1
fi
done
# NX disabled
for bin in none none32 none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f3) != "NX disabled" ]]; then
echo "NX disabled validation failed on \"${bin}\""
exit 1
fi
done
# N/A
for bin in rel.o rel32.o rel_cl.o rel_cl32.o; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f3) != "N/A" ]]; then
echo "N/A NX validation failed on \"${bin}\""
exit 1
fi
done
echo "NX validation tests passed"
#============================================
echo "Starting PIE check"
# PIE enabled
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f4) != "PIE enabled" ]]; then
echo "PIE enabled validation failed on \"${bin}\""
exit 1
fi
done
# No PIE
for bin in none none32 none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f4) != "No PIE" ]]; then
echo "No PIE validation failed on \"${bin}\""
exit 1
fi
done
# DSO
for bin in dso.so dso32.so dso_cl.so dso_cl32.so; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f4) != "DSO" ]]; then
echo "PIE DSO validation failed on \"${bin}\""
exit 1
fi
done
# REL
for bin in rel.o rel32.o rel_cl.o rel_cl32.o; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f4) != "REL" ]]; then
echo "PIE REL validation failed on \"${bin}\""
exit 1
fi
done
echo "PIE validation tests passed"
#============================================
echo "Starting CFI check"
# with CFI
for bin in cfi cfi32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --extended --format=csv | cut -d, -f5) != "with CFI" ]]; then
echo "CFI validation failed on \"${bin}\""
exit 1
fi
done
# without CFI
for bin in none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --extended --format=csv | cut -d, -f5) != "without CFI" ]]; then
echo "No CFI validation failed on \"${bin}\""
exit 1
fi
done
echo "CFI validation tests passed"
#============================================
echo "Starting SafeStack check"
# with SafeStack
for bin in sstack sstack32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --extended --format=csv | cut -d, -f6) != "with SafeStack" ]]; then
echo "SafeStack validation failed on \"${bin}\""
exit 1
fi
done
# without SafeStack
for bin in none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --extended --format=csv | cut -d, -f6) != "without SafeStack" ]]; then
echo "No SafeStack validation failed on \"${bin}\""
exit 1
fi
done
echo "SafeStack validation tests passed"
#============================================
echo "Starting RUNPATH check"
# No RPATH
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f5) != "No RPATH" ]]; then
echo "No RPATH validation failed on \"${bin}\""
exit 1
fi
done
# RPATH
for bin in rpath rpath32 rpath_cl rpath_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f5) != "RPATH" ]]; then
echo "RPATH validation failed on \"${bin}\""
exit 1
fi
done
# N/A
for bin in rel.o rel32.o rel_cl.o rel_cl32.o; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f5) != "N/A" ]]; then
echo "N/A RPATH validation failed on \"${bin}\""
exit 1
fi
done
echo "RPATH validation tests passed"
#============================================
echo "Starting RUNPATH check"
# No RUNPATH
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f6) != "No RUNPATH" ]]; then
echo "No RUNPATH validation failed on \"${bin}\""
exit 1
fi
done
# RUNPATH
for bin in runpath runpath32 runpath_cl runpath_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f6) != "RUNPATH" ]]; then
echo "RUNPATH validation failed on \"${bin}\""
exit 1
fi
done
# N/A
for bin in rel.o rel32.o rel_cl.o rel_cl32.o; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f6) != "N/A" ]]; then
echo "N/A RUNPATH validation failed on \"${bin}\""
exit 1
fi
done
echo "RUNPATH validation tests passed"
#============================================
echo "Starting Symbols check"
# No Symbols
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f7) != "No Symbols" ]]; then
echo "No Symbols validation failed on \"${bin}\""
exit 1
fi
done
# Symbols
for bin in none none32 none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f7) != "Symbols" ]]; then
echo "Symbols validation failed on \"${bin}\""
exit 1
fi
done
echo "Symbols validation tests passed"
#============================================
echo "Starting Fortify check"
# Yes
for bin in all all32 all_cl all_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f8) != "Yes" ]]; then
echo "Fortify validation failed on \"${bin}\""
exit 1
fi
done
# No
for bin in none none32 none_cl none_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f8) != "No" ]]; then
echo "No Fortify validation failed on \"${bin}\""
exit 1
fi
done
# N/A
for bin in nolibc nolibc_cl nolibc32 nolibc_cl32 fszero fszero_cl fszero32 fszero_cl32; do
if [[ $("${PARENT}"/checksec --file="${DIR}/binaries/output/${bin}" --format=csv | cut -d, -f8) != "N/A" ]]; then
echo "No Fortify validation failed on \"${bin}\": $("${PARENT}"/checksec --file="${DIR}/binaries/${bin}" --format=csv | cut -d, -f8)"
exit 1
fi
done
echo "Fortify validation tests passed"
#============================================
# process checks
#============================================
echo "Starting RELRO process check"
# Full RELRO
for bin in all all32 all_cl all_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f3) != "Full RELRO" ]]; then
echo "Full RELRO process validation failed on \"${bin}\""
exit 1
fi
done
# Partial RELRO
for bin in partial partial32 partial_cl partial_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f3) != "Partial RELRO" ]]; then
echo "Partial RELRO process validation failed on \"${bin}\""
exit 1
fi
done
# No RELRO
for bin in none none32 none_cl none_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f3) != "No RELRO" ]]; then
echo "No RELRO process validation failed on \"${bin}\""
exit 1
fi
done
sleep 2
echo "RELRO process validation tests passed"
#============================================
echo "Starting Stack Canary process check"
# Canary found
for bin in all all32 all_cl all_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f4) != "Canary found" ]]; then
echo "Stack Canary process validation failed on \"${bin}\""
exit 1
fi
done
# No Canary found
for bin in none none32 none_cl none_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f4) != "No Canary found" ]]; then
echo "No Stack Canary process validation failed on \"${bin}\""
exit 1
fi
done
sleep 2
echo "Stack Canary process validation tests passed"
#============================================
echo "Starting CFI process check"
# with CFI
for bin in cfi cfi32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --extended --format=csv | cut -d, -f5) != "with CFI" ]]; then
echo "CFI process validation failed on \"${bin}\""
exit 1
fi
done
# without CFI
for bin in none_cl none_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --extended --format=csv | cut -d, -f5) != "without CFI" ]]; then
echo "No CFI process validation failed on \"${bin}\""
exit 1
fi
done
sleep 2
echo "CFI process validation tests passed"
#============================================
echo "Starting SafeStack process check"
# with SafeStack (omit 32-bit SafeStack because the binary does not work)
bin=sstack
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --extended --format=csv | cut -d, -f6) != "with SafeStack" ]]; then
echo "SafeStack process validation failed on \"${bin}\""
exit 1
fi
# without SafeStack
for bin in none_cl none_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --extended --format=csv | cut -d, -f6) != "without SafeStack" ]]; then
echo "No SafeStack process validation failed on \"${bin}\""
exit 1
fi
done
sleep 2
echo "SafeStack process validation tests passed"
#============================================
echo "Starting NX process check"
# NX enabled
for bin in all all32 all_cl all_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f6) != "NX enabled" ]]; then
echo "NX enabled process validation failed on \"${bin}\""
exit 1
fi
done
# NX disabled
for bin in none none32 none_cl none_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f6) != "NX disabled" ]]; then
echo "NX disabled process validation failed on \"${bin}\""
exit 1
fi
done
sleep 2
echo "NX process validation tests passed"
#============================================
echo "Starting PIE process check"
# PIE enabled
for bin in all all32 all_cl all_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f7) != "PIE enabled" ]]; then
echo "PIE enabled process validation failed on \"${bin}\""
exit 1
fi
done
# No PIE
for bin in none none32 none_cl none_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f7) != "No PIE" ]]; then
echo "No PIE process validation failed on \"${bin}\""
exit 1
fi
done
sleep 2
echo "PIE process validation tests passed"
#============================================
echo "Starting Fortify process check"
# Yes
for bin in all all32 all_cl all_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f8) != "Yes" ]]; then
echo "Fortify process validation failed on \"${bin}\""
exit 1
fi
done
# No
for bin in none none32 none_cl none_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f8) != "No" ]]; then
echo "No Fortify process validation failed on \"${bin}\""
exit 1
fi
done
# N/A
for bin in nolibc nolibc_cl nolibc32 nolibc_cl32 fszero fszero_cl fszero32 fszero_cl32; do
"${DIR}"/binaries/output/${bin} > /dev/null &
if [[ $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f8) != "N/A" ]]; then
echo "No Fortify process validation failed on \"${bin}\": $("${PARENT}"/checksec --proc=${bin} --format=csv | cut -d, -f8)"
exit 1
fi
done
echo "Fortify process validation tests passed"
echo "Done."
echo "All hardening validation tests passed"