forked from slimm609/checksec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checksec
executable file
·1987 lines (1834 loc) · 85.6 KB
/
checksec
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# The BSD License (http://www.opensource.org/licenses/bsd-license.php)
# specifies the terms and conditions of use for checksec.sh:
#
# Copyright (c) 2014-2019, Brian Davis
# Copyright (c) 2013, Robin David
# Copyright (c) 2009-2011, Tobias Klein
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Tobias Klein nor the name of trapkit.de may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
# --- Modified Version ---
# Name : checksec.sh
# Version : 1.7.0
# Author : Brian Davis
# Date : Feburary 2014
# Download: https://github.com/slimm609/checksec.sh
#
# --- Modified Version ---
# Name : checksec.sh
# Version : based on 1.5
# Author : Robin David
# Date : October 2013
# Download: https://github.com/RobinDavid/checksec
#
# --- Original version ---
# Name : checksec.sh
# Version : 1.5
# Author : Tobias Klein
# Date : November 2011
# Download: http://www.trapkit.de/tools/checksec.html
# Changes : http://www.trapkit.de/tools/checksec_changes.txt
#set global lang to C
export LC_ALL="C"
# global vars
debug=false
have_readelf=1
verbose=false
format="cli"
SCRIPT_NAME="checksec"
SCRIPT_URL="https://github.com/slimm609/checksec.sh/raw/master/${SCRIPT_NAME}"
SIG_URL="https://github.com/slimm609/checksec.sh/raw/master/$(basename ${SCRIPT_NAME} .sh).sig"
SCRIPT_VERSION=2019072901
SCRIPT_MAJOR=2
SCRIPT_MINOR=1
SCRIPT_REVISION=0
pkg_release=false
commandsmissing=false
OPT=0
extended_checks=false
# FORTIFY_SOURCE vars
FS_end=_chk
FS_cnt_total=0
FS_cnt_checked=0
FS_cnt_unchecked=0
FS_chk_func_libc=0
FS_functions=0
FS_libc=0
# check for required files and deps first
# check if command exists
command_exists () {
type "${1}" > /dev/null 2>&1;
}
for command in cat awk sysctl uname mktemp openssl grep stat file find sort fgrep head ps readlink basename id which xargs; do
if ! (command_exists ${command}); then
echo -e "\e[31mWARNING: '${command}' not found! It's required for most checks.\e[0m"
commandsmissing=true
fi
done
if [[ ${command}smissing == true ]]; then
echo -e "\n\e[31mWARNING: Not all necessary commands found. Some tests might not work!\e[0m\n"
sleep 2
fi
if (command_exists readelf); then
readelf=readelf
elif (command_exists eu-readelf); then
readelf=eu-readelf
elif (command_exists greadelf); then
readelf=greadelf
else
echo -e "\n\e[31mERROR: readelf is a required tool for almost all tests. Aborting...\e[0m\n"
exit
fi
if [[ $(id -u) != 0 ]]; then
export PATH=${PATH}:/sbin/:/usr/sbin/
fi
sysarch=$(uname -m)
if [[ "${sysarch}" == "x86_64" ]]; then
arch="64"
elif [[ "${sysarch}" == "i?86" ]]; then
arch="32"
elif [[ "${sysarch}" =~ "arm" ]]; then
arch="arm"
elif [[ "${sysarch}" =~ "aarch64" ]]; then
arch="aarch64"
fi
#openssl public key for verification of updates
read -r PUBKEY <<EOF
LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF3Z25kcnk2WGJpNE8wR2w1T2UzSQp1eWRyMlZqR1hteDJFM0thd0wrK1F3a2FVT0RHOEVuT24weFZ1S1ZkZEphZjY3Rmxzd3pPYjh1RFRDTjdsWURnCnFKQXdmNllTOUFsdU5RRmlFQWhFRlgxL0dsMi9TSnFHYXhFVU9HTlV3NTI5a3BVR0MwNmN6SHhENEcvdWNBQlkKT05iWm9Vc1pIYmRnZUNueWs1dzZ0SWs3MEplNmZ2em5Da2JxbUZhS0UyQnhWTERLU0liSDBTak5XT3RSMmF6ZAp1V3p2RU1kVXFlZlZjYXErUDFjV0dLNy94VllSNkV3ME1aQTdWU0xkREhlRUVySW9Kc3UvM2VaeUR5ZDlaUlJvCmdpajM2R1N2SFREclU1ZVdXRlN0Q01UM29DRDhMSjVpbXBReWpWd3Z5M3Z4ZVNVYzVkdytZUDU0OU9jNHF2bzYKOXdJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==
EOF
# Fetch the update
fetch() {
if type wget > /dev/null 2>&1 ; then
${debug} && echo "fetching update via wget"
wget --no-check-certificate -O "${2}" "${1}" >/dev/null 2>&1
elif type curl > /dev/null 2>&1 ; then
${debug} && echo "fetching update via curl"
curl --insecure --remote-name -o "${2}" "${1}" >/dev/null 2>&1
else
echo 'Warning: Neither wget nor curl is available. online updates unavailable' >&2
exit 1
fi
}
# Version compare
vercomp () {
if [[ "${1}" == "${2}" ]]
then
return 0
fi
local IFS=.
local i ver1="${1}" ver2="${2}"
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
# Update/Upgrade
upgrade () {
if ${pkg_release}; then
printf "\033[31mError: Unknown option '%s'.\033[m\n\n" "${1}"
help
exit 1
fi
umask 027
TMP_FILE=$(mktemp /tmp/checksec.XXXXXXXXXX)
SIG_FILE=$(mktemp /tmp/checksec_sig.XXXXXXXX)
PUBKEY_FILE=$(mktemp /tmp/checksec_pubkey.XXXXXXXXXX)
fetch "${SCRIPT_URL}" "${TMP_FILE}"
fetch "${SIG_URL}" "${SIG_FILE}"
echo "${PUBKEY}" | base64 -d > "${PUBKEY_FILE}"
if ! openssl dgst -sha256 -verify "${PUBKEY_FILE}" -signature "${SIG_FILE}" "${TMP_FILE}" >/dev/null 2>&1; then
echo "file signature does not match. Update may be tampered"
rm -f "${TMP_FILE}" "${SIG_FILE}" "${PUBKEY_FILE}" >/dev/null 2>&1
exit 1
fi
UPDATE_VERSION=$(grep "^SCRIPT_VERSION" "${TMP_FILE}" | awk -F"=" '{ print $2 }')
if [[ "${SCRIPT_VERSION}" != "${UPDATE_VERSION}" ]]; then
PERMS=$(stat -c "%a" "$0")
rm -f "${SIG_FILE}" "${PUBKEY_FILE}" >/dev/null 2>&1
mv "${TMP_FILE}" "$0" >/dev/null 2>&1
exit_status=$?
if [[ "${exit_status}" -eq "0" ]]; then
echo "checksec.sh updated - Rev. ${UPDATE_VERSION}"
chmod "${PERMS}" "${0}"
else
echo "Error: Could not update... Please check permissions"
rm -f "${TMP_FILE}" >/dev/null 2>&1
exit 1
fi
else
echo "checksec.sh not updated... Already on latest version"
rm -f "${TMP_FILE}" "${SIG_FILE}" "${PUBKEY_FILE}" >/dev/null 2>&1
exit 1
fi
exit 0
}
# version information
version() {
echo "checksec v${SCRIPT_MAJOR}.${SCRIPT_MINOR}.${SCRIPT_REVISION}, Brian Davis, github.com/slimm609/checksec.sh, Dec 2015"
echo "Based off checksec v1.5, Tobias Klein, www.trapkit.de, November 2011"
echo
}
# help
help() {
echo "Usage: checksec [--format={cli,csv,xml,json}] [OPTION]"
echo
echo
echo "Options:"
echo
echo " ## Checksec Options"
echo " --file={file}"
echo " --dir={directory}"
echo " --proc={process name}"
echo " --proc-all"
echo " --proc-libs={process ID}"
echo " --kernel[=kconfig]"
echo " --fortify-file={executable-file}"
echo " --fortify-proc={process ID}"
echo " --version"
echo " --help"
if ! ${pkg_release}; then
echo " --update or --upgrade"
fi
echo
echo " ## Modifiers"
echo " --debug"
echo " --verbose"
echo " --format={cli,csv,xml,json}"
echo " --output={cli,csv,xml,json}"
echo " --extended"
echo
echo "For more information, see:"
echo " https://github.com/slimm609/checksec.sh"
echo
}
# format
format () {
list="cli csv xml json"
if [[ -n "${output_format}" ]]; then
if [[ ! ${list} =~ ${output_format} ]]; then
printf "\033[31mError: Please provide a valid format {cli, csv, xml, json}.\033[m\n\n"
exit 1
fi
fi
if [[ "${output_format}" == "xml" ]]; then
echo '<?xml version="1.0" encoding="UTF-8"?>'
fi
format="${output_format}"
}
#run help if nothing is passed
if [[ $# -lt 1 ]]; then
help
exit 1
fi
echo_message() {
if [[ ${format} == "csv" ]]; then
echo -n -e "$2"
elif [[ ${format} == "xml" ]]; then
echo -n -e "$3"
elif [[ ${format} == "json" ]]; then
echo -n -e "$4"
else #default to cli
echo -n -e "${1}"
fi
}
# check selinux status
getsestatus() {
${debug} && echo -e "\n***fuction getsestatus"
if (command_exists getenforce); then
${debug} && echo "***fuction getsestatus->getenforce"
sestatus=$(getenforce)
if [[ "${sestatus}" == "Disabled" ]]; then
status=0
elif [[ "${sestatus}" == "Permissive" ]]; then
status=1
elif [[ "${sestatus}" == "Enforcing" ]]; then
status=2
fi
elif (command_exists sestatus); then
${debug} && echo "***fuction getsestatus->sestatus"
sestatus=$(sestatus | grep "SELinux status" | awk '{ print $3}')
if [[ "${sestatus}" == "disabled" ]]; then
status=0
elif [[ "${sestatus}" == "enabled" ]]; then
sestatus2=$(sestatus | grep "Current" | awk '{ print $3}')
if [[ "${sestatus2}" == "permissive" ]]; then
status=1
elif [[ "${sestatus2}" == "enforcing" ]]; then
status=2
fi
fi
fi
return ${status}
}
# check if directory exists
dir_exists () {
${debug} && echo "fuction dir_exists"
if [[ -d "${1}" ]] ; then
return 0
else
return 1
fi
}
# check user privileges
root_privs () {
${debug} && echo "***function root_privs"
if [[ $(/usr/bin/id -u) -eq 0 ]] ; then
return 0
else
return 1
fi
}
# check if input is numeric
isNumeric () {
${debug} && echo "***function isNumeric"
echo "$@" | grep -q -v "[^0-9]"
}
# check if input is a string
isString () {
${debug} && echo "***function isString"
echo "$@" | grep -q -v "[^ A-Z_a-z]"
}
# check file(s)
filecheck() {
${debug} && echo "***function filecheck"
# check for RELRO support
${debug} && echo "***function filecheck->RELRO"
if ${readelf} -l "${1}" 2>/dev/null | grep -q 'GNU_RELRO'; then
if ${readelf} -d "${1}" 2>/dev/null | grep -q 'BIND_NOW'; then
echo_message '\033[32mFull RELRO \033[m ' 'Full RELRO,' '<file relro="full"' " \"${1}\": { \"relro\":\"full\","
else
echo_message '\033[33mPartial RELRO\033[m ' 'Partial RELRO,' '<file relro="partial"' " \"${1}\": { \"relro\":\"partial\","
fi
else
echo_message '\033[31mNo RELRO \033[m ' 'No RELRO,' '<file relro="no"' " \"file\": { \"relro\":\"no\","
fi
# check for stack canary support
${debug} && echo -e "\n***function filecheck->canary"
if ${readelf} -s "${1}" 2>/dev/null | grep -Eq '__stack_chk_fail|__intel_security_cookie'; then
echo_message '\033[32mCanary found \033[m ' 'Canary found,' ' canary="yes"' '"canary":"yes",'
else
echo_message '\033[31mNo canary found\033[m ' 'No Canary found,' ' canary="no"' '"canary":"no",'
fi
# check for NX support
${debug} && echo -e "\n***function filecheck->nx"
if ${readelf} -W -l "${1}" 2>/dev/null | grep -q 'GNU_STACK'; then
if ${readelf} -W -l "${1}" 2>/dev/null | grep 'GNU_STACK' | grep -q 'RWE'; then
echo_message '\033[31mNX disabled\033[m ' 'NX disabled,' ' nx="no"' '"nx":"no",'
else
echo_message '\033[32mNX enabled \033[m ' 'NX enabled,' ' nx="yes"' '"nx":"yes",'
fi
else
echo_message '\033[31mNX disabled\033[m ' 'NX disabled,' ' nx="no"' '"nx":"no",'
fi
# check for PIE support
${debug} && echo -e "\n***function filecheck->pie"
if ${readelf} -h "${1}" 2>/dev/null | grep -q 'Type:[[:space:]]*EXEC'; then
echo_message '\033[31mNo PIE \033[m ' 'No PIE,' ' pie="no"' '"pie":"no",'
elif ${readelf} -h "${1}" 2>/dev/null | grep -q 'Type:[[:space:]]*DYN'; then
if ${readelf} -d "${1}" 2>/dev/null | grep -q 'DEBUG'; then
echo_message '\033[32mPIE enabled \033[m ' 'PIE enabled,' ' pie="yes"' '"pie":"yes",'
else
echo_message '\033[33mDSO \033[m ' 'DSO,' ' pie="dso"' '"pie":"dso",'
fi
else
echo_message '\033[33mNot an ELF file\033[m ' 'Not an ELF file,' ' pie="not_elf"' '"pie":"not_elf",'
fi
if ${extended_checks}; then
# check if compiled with Clang CFI
${debug} && echo -e "\n***function filecheck->clangcfi"
#if $readelf -s "$1" 2>/dev/null | grep -Eq '\.cfi'; then
read -a cfifunc <<< $($readelf -s "${1}" 2>/dev/null | grep .cfi | awk '{ print $8 }' )
func=${cfifunc/.cfi/}
if [ ! -z "$cfifunc" ] && $readelf -s "$1" 2>/dev/null | grep -q "$func$"; then
echo_message '\033[32mClang CFI found \033[m ' 'with CFI,' ' clangcfi="yes"' '"clangcfi":"yes",'
else
echo_message '\033[31mNo Clang CFI found\033[m ' 'without CFI,' ' clangcfi="no"' '"clangcfi":"no",'
fi
# check if compiled with Clang SafeStack
${debug} && echo -e "\n***function filecheck->safestack"
if $readelf -s "$1" 2>/dev/null | grep -Eq '__safestack_init'; then
echo_message '\033[32mSafeStack found \033[m ' 'with SafeStack,' ' safestack="yes"' '"safestack":"yes",'
else
echo_message '\033[31mNo SafeStack found\033[m ' 'without SafeStack,' ' safestack="no"' '"safestack":"no",'
fi
fi
# check for rpath / run path
${debug} && echo -e "\n***function filecheck->rpath"
# search for a line that matches RPATH and extract the colon-separated path list within brackets
# example input: "0x000000000000000f (RPATH) Library rpath: [/lib/systemd:/lib/apparmor]"
IFS=: read -a rpath_array <<< $(${readelf} -d "${1}" 2>/dev/null | awk -F'[][]' '/RPATH/ {print $2}')
if [[ "${#rpath_array[@]}" -gt 0 ]]; then
if xargs stat -c %A <<< ${rpath_array[*]} 2>/dev/null | grep -q 'rw'; then
echo_message '\033[31mRW-RPATH \033[m ' 'RPATH,' ' rpath="yes"' '"rpath":"yes",'
else
echo_message '\033[31mRPATH \033[m ' 'RPATH,' ' rpath="yes"' '"rpath":"yes",'
fi
else
echo_message '\033[32mNo RPATH \033[m ' 'No RPATH,' ' rpath="no"' '"rpath":"no",'
fi
${debug} && echo -e "\n***function filecheck->runpath"
# search for a line that matches RUNPATH and extract the colon-separated path list within brackets
IFS=: read -a runpath_array <<< $(${readelf} -d "${1}" 2>/dev/null | awk -F'[][]' '/RUNPATH/ {print $2}')
if [[ "${#runpath_array[@]}" -gt 0 ]]; then
if xargs stat -c %A <<< ${runpath_array[*]} 2>/dev/null | grep -q 'rw'; then
echo_message '\033[31mRW-RUNPATH \033[m ' 'RUNPATH,' ' runpath="yes"' '"runpath":"yes",'
else
echo_message '\033[31mRUNPATH \033[m ' 'RUNPATH,' ' runpath="yes"' '"runpath":"yes",'
fi
else
echo_message '\033[32mNo RUNPATH \033[m ' 'No RUNPATH,' ' runpath="no"' '"runpath":"no",'
fi
# check for stripped symbols in the binary
SYM_cnt=' '
SYM_cnt=( $(${readelf} --symbols "${1}" 2>/dev/null | grep '\.symtab' | cut -d' ' -f5 | cut -d: -f1))
if ${readelf} --symbols "${1}" 2>/dev/null | grep -q '\.symtab'; then
echo_message "\033[31m${SYM_cnt[0]} Symbols \033[m " 'Symbols,' ' symbols="yes"' '"symbols":"yes",'
else
echo_message '\033[32mNo Symbols \033[m ' 'No Symbols,' ' symbols="no"' '"symbols":"no",'
fi
# check for FORTIFY SOURCE
${debug} && echo "***function filecheck->fortify"
if [[ -e /lib/libc.so.6 ]] ; then
FS_libc=/lib/libc.so.6
elif [[ -e /lib/libc.so.7 ]] ; then
FS_libc=/lib/libc.so.7
elif [[ -e /lib/libc.so ]] ; then
FS_libc=/lib/libc.so
elif [[ -e /lib64/libc.so.6 ]] ; then
FS_libc=/lib64/libc.so.6
elif [[ -e /lib/i386-linux-gnu/libc.so.6 ]] ; then
FS_libc=/lib/i386-linux-gnu/libc.so.6
elif [[ -e /lib/x86_64-linux-gnu/libc.so.6 ]] ; then
FS_libc=/lib/x86_64-linux-gnu/libc.so.6
elif [[ -e /lib/arm-linux-gnueabihf/libc.so.6 ]] ; then
FS_libc=/lib/arm-linux-gnueabihf/libc.so.6
elif [[ -e /lib/aarch64-linux-gnu/libc.so.6 ]] ; then
FS_libc=/lib/aarch64-linux-gnu/libc.so.6
elif [[ -e /usr/x86_64-gentoo-linux-musl/bin/ld ]] ; then
FS_libc=/usr/x86_64-gentoo-linux-musl/bin/ld
else
printf "\033[31mError: libc not found.\033[m\n\n"
exit 1
fi
FS_chk_func_libc="$(${readelf} -s $FS_libc 2>/dev/null | sed -ne 's/.*__\(.*_chk\)@@.*/\1/p')"
FS_func_libc="$(echo "${FS_chk_func_libc}" | sed 's/_chk$//')"
FS_functions="$(${readelf} --dyn-syms "${1}" 2>/dev/null | awk '{ print $8 }' | sed -e 's/_*//' -e 's/@.*//' -e '/^$/d')"
FS_cnt_checked=$(fgrep -xf <(sort <<< "${FS_chk_func_libc}") <(sort <<< "${FS_functions}") | wc -l)
FS_cnt_unchecked=$(fgrep -xf <(sort <<< "${FS_func_libc}") <(sort <<< "${FS_functions}") | wc -l)
FS_cnt_total=$((FS_cnt_unchecked+FS_cnt_checked))
if [[ "${FS_functions}" =~ _chk ]]; then
echo_message '\033[32mYes\033[m' 'Yes,' ' fortify_source="yes" ' '"fortify_source":"yes",'
else
echo_message "\033[31mNo\033[m" "No," ' fortify_source="no" ' '"fortify_source":"no",'
fi
echo_message "\t${FS_cnt_checked}\t" ${FS_cnt_checked}, "fortified=\"${FS_cnt_checked}\" " "\"fortified\":\"${FS_cnt_checked}\","
echo_message "\t${FS_cnt_total}\t" ${FS_cnt_total} "fortify-able=\"${FS_cnt_total}\"" "\"fortify-able\":\"${FS_cnt_total}\""
}
# check process(es)
proccheck() {
${debug} && echo -e "\n***function proccheck"
# check for RELRO support
${debug} && echo "***function proccheck->RELRO"
if ${readelf} -l "${1}/exe" 2>/dev/null | grep -q 'Program Headers'; then
if ${readelf} -l "${1}/exe" 2>/dev/null | grep -q 'GNU_RELRO'; then
if ${readelf} -d "${1}/exe" 2>/dev/null | grep -q 'BIND_NOW'; then
echo_message '\033[32mFull RELRO \033[m ' 'Full RELRO,' ' relro="full"' '"relro":"full",'
else
echo_message '\033[33mPartial RELRO\033[m ' 'Partial RELRO,' ' relro="partial"' '"relro":"partial",'
fi
else
echo_message '\033[31mNo RELRO \033[m ' 'No RELRO,' ' relro="no"' '"relro":"no",'
fi
else
echo -n -e '\033[31mPermission denied (please run as root)\033[m\n'
exit 1
fi
# check for stack canary support
${debug} && echo -e "\n***function proccheck->canary"
if ${readelf} -s "${1}/exe" 2>/dev/null | grep -q 'Symbol table'; then
if ${readelf} -s "${1}/exe" 2>/dev/null | grep -Eq '__stack_chk_fail|__intel_security_cookie'; then
echo_message '\033[32mCanary found \033[m ' 'Canary found,' ' canary="yes"' '"canary":"yes",'
else
echo_message '\033[31mNo canary found \033[m ' 'No Canary found,' ' canary="no"' '"canary":"no",'
fi
else
if [[ "${1}" == "1" ]] ; then
echo_message '\033[33mPermission denied \033[m ' 'Permission denied,' ' canary="Permission denied"' '"canary":"Permission denied",'
else
echo_message '\033[33mNo symbol table found \033[m ' 'No symbol table found,' ' canary="No symbol table found"' '"canary":"No symbol table found",'
fi
fi
if ${extended_checks}; then
# check if compiled with Clang CFI
$debug && echo -e "\n***function proccheck->clangcfi"
#if $readelf -s "$1" 2>/dev/null | grep -Eq '\.cfi'; then
read -a cfifunc <<< $($readelf -s "$1/exe" 2>/dev/null | grep .cfi | awk '{ print $8 }' )
func=${cfifunc/.cfi/}
if [ ! -z "$cfifunc" ] && $readelf -s "$1/exe" 2>/dev/null | grep -q "$func$"; then
echo_message '\033[32mClang CFI found \033[m ' 'with CFI,' ' clangcfi="yes"' '"clangcfi":"yes",'
else
echo_message '\033[31mNo Clang CFI found\033[m ' 'without CFI,' ' clangcfi="no"' '"clangcfi":"no",'
fi
# check if compiled with Clang SafeStack
$debug && echo -e "\n***function proccheck->safestack"
if $readelf -s "$1/exe" 2>/dev/null | grep -Eq '__safestack_init'; then
echo_message '\033[32mSafeStack found \033[m ' 'with SafeStack,' ' safestack="yes"' '"safestack":"yes",'
else
echo_message '\033[31mNo SafeStack found\033[m ' 'without SafeStack,' ' safestack="no"' '"safestack":"no",'
fi
fi
# check for Seccomp mode
${debug} && echo -e "\n***function proccheck->Seccomp"
seccomp=$(grep 'Seccomp:' "${1}/status" 2> /dev/null | cut -b10)
if [[ "${seccomp}" == "1" ]] ; then
echo_message '\033[32mSeccomp strict\033[m ' 'Seccomp strict,' ' seccomp="strict"' '"seccomp":"strict",'
elif [[ "${seccomp}" == "2" ]] ; then
echo_message '\033[32mSeccomp-bpf \033[m ' 'Seccomp-bpf,' ' seccomp="bpf"' '"seccomp":"bpf",'
else
echo_message '\033[31mNo Seccomp \033[m ' 'No Seccomp,' ' seccomp="no"' '"seccomp":"no",'
fi
# first check for PaX support
${debug} && echo -e "\n***function proccheck->PAX"
if grep -q 'PaX:' "${1}/status" 2> /dev/null ; then
pageexec=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b6)
segmexec=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b10)
mprotect=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b8)
randmmap=$(grep 'PaX:' "${1}/status" 2> /dev/null | cut -b9)
if [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "M" && "${randmmap}" = "R" ]] ; then
echo_message '\033[32mPaX enabled\033[m ' 'Pax enabled,' ' pax="yes"' '"pax":"yes",'
elif [[ "${pageexec}" = "p" && "${segmexec}" = "s" && "${randmmap}" = "R" ]] ; then
echo_message '\033[33mPaX ASLR only\033[m ' 'Pax ASLR only,' ' pax="aslr_only"' '"pax":"aslr_only",'
elif [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "m" && "${randmmap}" = "R" ]] ; then
echo_message '\033[33mPaX mprot off \033[m' 'Pax mprot off,' ' pax="mprot_off"' '"pax":"mprot_off",'
elif [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "M" && "${randmmap}" = "r" ]] ; then
echo_message '\033[33mPaX ASLR off\033[m ' 'Pax ASLR off,' ' pax="aslr_off"' '"pax":"aslr_off",'
elif [[ "${pageexec}" = "P" || "${segmexec}" = "S" ]] && [[ "${mprotect}" = "m" && "${randmmap}" = "r" ]] ; then
echo_message '\033[33mPaX NX only\033[m ' 'Pax NX only,' ' pax="nx_only"' '"pax":"nx_only",'
else
echo_message '\033[31mPaX disabled\033[m ' 'Pax disabled,' ' pax="no"' '"pax":"no",'
fi
# fallback check for NX support
${debug} && echo -e "\n***function proccheck->NX"
elif ${readelf} -W -l "${1}/exe" 2>/dev/null | grep 'GNU_STACK' | grep -q 'RWE'; then
echo_message '\033[31mNX disabled\033[m ' 'NX disabled,' ' nx="no"' '"nx":"no",'
else
echo_message '\033[32mNX enabled \033[m ' 'NX enabled,' ' pax="yes"' '"nx":"yes",'
fi
# check for PIE support
${debug} && echo -e "\n***function proccheck->PIE"
if ${readelf} -h "${1}/exe" 2>/dev/null | grep -q 'Type:[[:space:]]*EXEC'; then
echo_message '\033[31mNo PIE \033[m ' 'No PIE,' ' pie="no"' '"pie":"no",'
elif ${readelf} -h "${1}/exe" 2>/dev/null | grep -q 'Type:[[:space:]]*DYN'; then
if ${readelf} -d "${1}/exe" 2>/dev/null | grep -q 'DEBUG'; then
echo_message '\033[32mPIE enabled \033[m ' 'PIE enabled,' ' pie="yes"' '"pie":"yes",'
else
echo_message '\033[33mDynamic Shared Object\033[m ' 'Dynamic Shared Object,' ' pie="dso"' '"pie":"dso",'
fi
else
echo_message '\033[33mNot an ELF file \033[m ' 'Not an ELF file,' ' pie="not_elf"' '"pie":"not_elf",'
fi
#check for forifty source support
FS_functions=( $(${readelf} -s "${1}/exe" 2>/dev/null | awk '{ print $8 }' | sed 's/_*//' | sed -e 's/@.*//') )
for ((FS_elem_functions=0; FS_elem_functions<${#FS_functions[@]}; FS_elem_functions++))
do
if [[ ${FS_functions[$FS_elem_functions]} =~ _chk ]] ; then
echo_message '\033[32mYes\033[m' 'Yes' " fortify_source='yes'>" '"fortify_source":"yes" }'
return
fi
done
echo_message "\033[31mNo\033[m" "No" " fortify_source='no'>" '"fortify_source":"no" }'
}
# check mapped libraries
libcheck() {
${debug} && echo "***function libcheck"
libs=( $(awk '{ print $6 }' "/proc/${1}/maps" | grep '/' | sort -u | xargs file | grep ELF | awk '{ print $1 }' | sed 's/:/ /') )
echo_message "\n* Loaded libraries (file information, # of mapped files: ${#libs[@]}):\n\n" "" "" "\"libs\": {"
for ((element=0; element<${#libs[@]}; element++))
do
echo_message " ${libs[$element]}:\n" "${libs[$element]}," "" ""
echo_message " " "" " " ""
filecheck "${libs[$element]}"
if [[ ${element} == $((${#libs[@]} - 1)) ]]; then
echo_message "\n\n" "\n" " filename='${libs[$element]}' />\n" ""
else
echo_message "\n\n" "\n" " filename='${libs[$element]}' />\n" "},"
fi
done
}
# check for system-wide ASLR support
aslrcheck() {
${debug} && echo "***function aslrcheck"
# PaX ASLR support
${debug} && echo -e "\n***function aslrcheck->PAX ASLR"
if ! (grep -q 'Name:' /proc/1/status 2> /dev/null) ; then
echo_message '\033[33m insufficient privileges for PaX ASLR checks\033[m\n' '' '' ''
echo_message ' Fallback to standard Linux ASLR check' '' '' ''
fi
if grep -q 'PaX:' /proc/1/status 2> /dev/null; then
if grep -q 'PaX:' /proc/1/status 2> /dev/null | grep -q 'R'; then
echo_message '\033[32mPaX ASLR enabled\033[m\n\n' '' '' ''
else
echo_message '\033[31mPaX ASLR disabled\033[m\n\n' '' '' ''
fi
else
${debug} && echo -e "\n***function aslrcheck->randomize_va_space"
# standard Linux 'kernel.randomize_va_space' ASLR support
# (see the kernel file 'Documentation/sysctl/kernel.txt' for a detailed description)
echo_message " (kernel.randomize_va_space): " '' '' ''
if sysctl -a 2>/dev/null | grep -q 'kernel.randomize_va_space = 1'; then
echo_message '\033[33mPartial (Setting: 1)\033[m\n\n' '' '' ''
echo_message " Description - Make the addresses of mmap base, stack and VDSO page randomized.\n" '' '' ''
echo_message " This, among other things, implies that shared libraries will be loaded to \n" '' '' ''
echo_message " random addresses. Also for PIE-linked binaries, the location of code start\n" '' '' ''
echo_message " is randomized. Heap addresses are *not* randomized.\n\n" '' '' ''
elif sysctl -a 2>/dev/null | grep -q 'kernel.randomize_va_space = 2'; then
echo_message '\033[32mFull (Setting: 2)\033[m\n\n' '' '' ''
echo_message " Description - Make the addresses of mmap base, heap, stack and VDSO page randomized.\n" '' '' ''
echo_message " This, among other things, implies that shared libraries will be loaded to random \n" '' '' ''
echo_message " addresses. Also for PIE-linked binaries, the location of code start is randomized.\n\n" '' '' ''
elif sysctl -a 2>/dev/null | grep -q 'kernel.randomize_va_space = 0'; then
echo_message '\033[31mNone (Setting: 0)\033[m\n' '' '' ''
else
echo_message '\033[31mNot supported\033[m\n' '' '' ''
fi
echo_message " See the kernel file 'Documentation/sysctl/kernel.txt' for more details.\n\n" '' '' ''
fi
}
# check cpu nx flag
nxcheck() {
${debug} && echo -e "\n***function nxcheck"
if grep -q nx /proc/cpuinfo; then
echo_message '\033[32mYes\033[m\n\n' '' '' ''
else
echo_message '\033[31mNo\033[m\n\n' '' '' ''
fi
}
#Check core dumps restricted?
coredumpcheck() {
${debug} && echo -e "\n***function coredumpcheck"
coreValue=$(grep -ic "hard core 0" /etc/security/limits.conf)
dumpableValue=$(sysctl -b -e fs.suid_dumpable)
if [[ "${coreValue}" == 1 ]] && [[ "${dumpableValue}" == 0 ]] || [[ "${dumpableValue}" == 2 ]]; then
echo_message '\033[32mRestricted\033[m\n\n' '' '' ''
else
echo_message '\033[31mNot Restricted\033[m\n\n' '' '' ''
fi
}
# check for kernel protection mechanisms
kernelcheck() {
${debug} && echo "***function kernelcheck"
echo_message " Description - List the status of kernel protection mechanisms. Rather than\n" '' '' ''
echo_message " inspect kernel mechanisms that may aid in the prevention of exploitation of\n" '' '' ''
echo_message " userspace processes, this option lists the status of kernel configuration\n" '' '' ''
echo_message " options that harden the kernel itself against attack.\n\n" '' '' ''
echo_message " Kernel config:\n" '' '' '{ "kernel": '
if [[ ! "${1}" == "" ]] ; then
kconfig="cat ${1}"
echo_message " Warning: The config ${1} on disk may not represent running kernel config!\n\n" "${1}" "<kernel config=\"${1}\"" "{ \"KernelConfig\":\"${1}\","
# update the architecture based on the config rather than the system
if ${kconfig} | grep -qi 'CONFIG_ARM=y\|CONFIG_ARM=y'; then
arch="arm"
fi
if ${kconfig} | grep -qi 'CONFIG_ARM64=y'; then
arch="aarch64"
fi
if ${kconfig} | grep -qi 'CONFIG_X86_64=y'; then
arch="64"
fi
if ${kconfig} | grep -qi 'CONFIG_X86_32=y'; then
arch="32"
fi
elif [[ -f /proc/config.gz ]] ; then
kconfig="zcat /proc/config.gz"
echo_message "\033[32m/proc/config.gz\033[m\n\n" '/proc/config.gz' '<kernel config="/proc/config.gz"' '{ "KernelConfig":"/proc/config.gz",'
elif [[ -f /boot/config-"$(uname -r)" ]] ; then
kconfig="cat /boot/config-$(uname -r)"
kern=$(uname -r)
echo_message "\033[33m/boot/config-${kern}\033[m\n\n" "/boot/config-${kern}," "<kernel config='/boot/config-${kern}'" "{ \"KernelConfig\":\"/boot/config-${kern}\","
echo_message " Warning: The config on disk may not represent running kernel config!\n\n" "" "" ""
elif [[ -f "${KBUILD_OUTPUT:-/usr/src/linux}"/.config ]] ; then
kconfig="cat ${KBUILD_OUTPUT:-/usr/src/linux}/.config"
echo_message "\033[33m${KBUILD_OUTPUT:-/usr/src/linux}/.config\033[m\n\n" "${KBUILD_OUTPUT:-/usr/src/linux}/.config," "<kernel config='${KBUILD_OUTPUT:-/usr/src/linux}/.config'" "{ \"KernelConfig\":\"${KBUILD_OUTPUT:-/usr/src/linux}/.config\","
echo_message " Warning: The config on disk may not represent running kernel config!\n\n" "" "" ""
else
echo_message "\033[31mNOT FOUND\033[m\n\n" "NOT FOUND,,,,,,," "<kernel config='not_found' />" '{ "KernelConfig":"not_found",'
exit 0
fi
${debug} && ${kconfig} | grep "CONFIG_GRKERNSEC"
${debug} && ${kconfig} | grep "CONFIG_PAX"
echo_message " Vanilla Kernel ASLR: " "" "" ""
randomize_va=$(sysctl -b -e kernel.randomize_va_space)
if [[ "x${randomize_va}" == "x2" ]]; then
echo_message "\033[32mFull\033[m\n" "Full," " randomize_va_space='full'" '"randomize_va_space":"full",'
elif [[ "x${randomize_va}" == "x1" ]]; then
echo_message "\033[33mPartial\033[m\n" "Partial," " randomize_va_space='partial'" '"randomize_va_space":"partial",'
else
echo_message "\033[31mNone\033[m\n" "None," " randomize_va_space='none'" '"randomize_va_space":"none",'
fi
echo_message " Protected symlinks: " "" "" ""
symlink=$(sysctl -b -e fs.protected_symlinks)
if [[ "x${symlink}" == "x1" ]]; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " protect_symlinks='yes'" '"protect_symlinks":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " protect_symlinks='no'" '"protect_symlinks":"no",'
fi
echo_message " Protected hardlinks: " "" "" ""
hardlink=$(sysctl -b -e fs.protected_hardlinks)
if [[ "x${hardlink}" == "x1" ]]; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " protect_hardlinks='yes'" '"protect_hardlinks":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " protect_hardlinks='no'" '"protect_hardlinks":"no",'
fi
echo_message " Ipv4 reverse path filtering: " "" "" ""
ipv4_rpath=$(sysctl -b -e net.ipv4.conf.all.rp_filter)
if [[ "x${ipv4_rpath}" == "x1" ]]; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " ipv4_rpath='yes'" '"ipv4_rpath":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " ipv4_rpath='no'" '"ipv4_rpath":"no",'
fi
echo_message " Ipv6 reverse path filtering: " "" "" ""
ipv6_rpath=$(sysctl -b -e net.ipv6.conf.all.rp_filter)
if [[ "x${ipv6_rpath}" == "x1" ]]; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " ipv6_rpath='yes'" '"ipv6_rpath":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " ipv6_rpath='no'" '"ipv6_rpath":"no",'
fi
echo_message " Kernel heap randomization: " "" "" ""
# NOTE: y means it turns off kernel heap randomization for backwards compatability (libc5)
if ${kconfig} | grep -qi 'CONFIG_COMPAT_BRK=y'; then
echo_message "\033[31mDisabled\033[m\n" "Disabled," " kernel_heap_randomization='no'" '"kernel_heap_randomization":"no",'
else
echo_message "\033[32mEnabled\033[m\n" "Enabled," " kernel_heap_randomization='yes'" '"kernel_heap_randomization":"yes",'
fi
if ${kconfig} | grep -qi 'CONFIG_CC_STACKPROTECTOR' || ${kconfig} | grep -qa 'CONFIG_STACKPROTECTOR'; then
echo_message " GCC stack protector support: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_CC_STACKPROTECTOR=y' || ${kconfig} | grep -qi 'CONFIG_STACKPROTECTOR=y' ; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " gcc_stack_protector='yes'" '"gcc_stack_protector":"yes",'
if ${kconfig} | grep -qi 'CONFIG_CC_STACKPROTECTOR_STRONG' || ${kconfig} | grep -qi 'CONFIG_STACKPROTECTOR_STRONG'; then
echo_message " GCC stack protector strong: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_CC_STACKPROTECTOR_STRONG=y' || ${kconfig} | grep -qi 'CONFIG_STACKPROTECTOR_STRONG=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " gcc_stack_protector_strong='yes'" '"gcc_stack_protector_strong":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " gcc_stack_protector_strong='no'" '"gcc_stack_protector_strong":"no",'
fi
fi
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " gcc_stack_protector='no'" '"gcc_stack_protector":"no",'
fi
fi
if ${kconfig} | grep -qi 'CONFIG_GCC_PLUGIN_STRUCTLEAK'; then
echo_message " GCC structleak plugin: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_GCC_PLUGIN_STRUCTLEAK=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " gcc_structleak='yes'" '"gcc_structleak":"yes",'
echo_message " GCC structleak by ref plugin: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " gcc_structleak_byref='yes'" '"gcc_structleak_byref":"yes",'
else
echo_message "\033[32mEnabled\033[m\n" "Enabled," " gcc_structleak_byref='no'" '"gcc_structleak_byref":"no",'
fi
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " gcc_structleak='no'" '"gcc_structleak":"no",'
fi
fi
if ${kconfig} | grep -qi 'CONFIG_SLAB_FREELIST_RANDOM'; then
echo_message " SLAB freelist randomization: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_SLAB_FREELIST_RANDOM=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " slab_freelist_randomization='yes'" '"slab_freelist_randomization":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " slab_freelist_randomization='no'" '"slab_freelist_randomization":"no",'
fi
fi
if ${kconfig} | grep -qi 'CPU_SW_DOMAIN_PAN=y'; then
echo_message " Use CPU domains: " "" "" ""
if ${kconfig} | grep -qi 'CPU_SW_DOMAIN_PAN=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " cpu_sw_domain'yes'" '"cpu_sw_domain":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " cpu_sw_domain='no'" '"cpu_sw_domain":"no",'
fi
fi
if ${kconfig} | grep -qi 'CONFIG_VMAP_STACK'; then
echo_message " Virtually-mapped kernel stack: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_VMAP_STACK=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " virtually_mapped_stack='yes'" '"virtually_mapped_stack":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " virtually_mapped_stack='no'" '"virtually_mapped_stack":"no",'
fi
fi
if ${kconfig} | grep -qi 'CONFIG_DEVMEM'; then
if ${kconfig} | grep -qi 'CONFIG_DEVMEM=y'; then
echo_message " Restrict /dev/mem access: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_STRICT_DEVMEM=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " restrict_dev_mem_access='yes'" '"restrict_dev_mem_access":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " restrict_dev_mem_access='no'" '"restrict_dev_mem_access":"no",'
fi
echo_message " Restrict I/O access to /dev/mem: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_IO_STRICT_DEVMEM=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " restrict_io_dev_mem_access='yes'" '"restrict_io_dev_mem_access":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " restrict_io_dev_mem_access='no'" '"restrict_io_dev_mem_access":"no",'
fi
fi
fi
if ! ${kconfig} | grep -qi 'CONFIG_PAX'; then
if ${kconfig} | grep -qi 'CONFIG_DEBUG_RODATA' || ${kconfig} | grep -qi '|CONFIG_STRICT_KERNEL_RWX'; then
echo_message " Enforce read-only kernel data: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_DEBUG_RODATA=y\|CONFIG_STRICT_KERNEL_RWX=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " ro_kernel_data='yes'" '"ro_kernel_data":"yes",'
echo_message " Enforce read-only module data: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_STRICT_MODULE_RWX=y\|CONFIG_DEBUG_SET_MODULE_RONX'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " ro_module_data='yes'" '"ro_module_data":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " ro_module_data='no'" '"ro_module_data":"no",'
fi
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " ro_kernel_data='no'" '"ro_kernel_data":"no",'
fi
fi
fi
if ${kconfig} | grep -qi 'CONFIG_REFCOUNT_FULL'; then
echo_message " Full reference count validation: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_REFCOUNT_FULL=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " full_refcount_validation='yes'" '"full_refcount_validation":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " full_refcount_validation='no'" '"full_refcount_validation":"no",'
fi
fi
echo_message " Exec Shield: " """" ""
if grep -qi 'kernel.exec-shield = 1' /etc/sysctl.conf 2>/dev/null ; then
echo_message '\033[32mEnabled\033[m\n\n' '' '' ''
else
echo_message '\033[31mDisabled\033[m\n\n' '' '' ''
fi
if ${kconfig} | grep -qi 'CONFIG_HARDENED_USERCOPY'; then
echo_message " Hardened Usercopy: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_HARDENED_USERCOPY=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " hardened_usercopy='yes'" '"hardened_usercopy":"yes",'
echo_message " Hardened Usercopy Pagespan: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_HARDENED_USERCOPY_PAGESPAN=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " hardened_usercopy_pagespan='yes'" '"hardened_usercopy_pagespan":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " hardened_usercopy_pagespan='no'" '"hardened_usercopy_pagespan":"no",'
fi
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " hardened_usercopy='no'" '"hardened_usercopy":"no",'
fi
fi
if ${kconfig} | grep -qi 'CONFIG_FORTIFY_SOURCE'; then
echo_message " Harden str/mem functions: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_FORTIFY_SOURCE=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " fortify_source='yes'" '"fortify_source":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " fortify_source='no'" '"fortify_source":"no",'
fi
fi
if ${kconfig} | grep -qi 'CONFIG_DEVKMEM'; then
echo_message " Restrict /dev/kmem access: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_DEVKMEM=y'; then
echo_message "\033[31mDisabled\033[m\n" "Disabled" " restrict_dev_kmem_access='no'" '"restrict_dev_kmem_access":"no",'
else
echo_message "\033[32mEnabled\033[m\n" "Enabled" " restrict_dev_kmem_access='yes'" '"restrict_dev_kmem_access":"yes",'
fi
fi
#x86 only
if [[ "${arch}" == "32" ]] || [[ "${arch}" == "64" ]]; then
echo_message "\n" "\n" "" ""
echo_message "* X86 only: \n" "" "" ""
if ! ${kconfig} | grep -qi 'CONFIG_PAX_SIZE_OVERFLOW=y'; then
if ${kconfig} | grep -qi 'CONFIG_DEBUG_STRICT_USER_COPY_CHECKS'; then
echo_message " Strict user copy checks: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled," " strict_user_copy_check='yes'" '"strict_user_copy_check":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " strict_user_copy_check='no'" '"strict_user_copy_check":"no",'
fi
fi
fi
if ${kconfig} | grep -qi 'CONFIG_RANDOMIZE_BASE' || ${kconfig} | grep -qi 'CONFIG_PAX_ASLR'; then
echo_message " Address space layout randomization: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_RANDOMIZE_BASE=y' || ${kconfig} | grep -qi 'CONFIG_PAX_ASLR=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled" " random_address_space_layout='yes'>" '"random_address_space_layout":"yes"'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " random_address_space_layout='no'>" '"random_address_space_layout":"no"'
fi
fi
fi
#ARM only
if [[ "${arch}" == "arm" ]]; then
echo_message "\n" "\n" "\n" ""
echo_message "* ARM only: \n" "" "" ""
if ${kconfig} | grep -qi 'CONFIG_ARM_KERNMEM_PERMS'; then
echo_message " Restrict kernel memory permissions: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_ARM_KERNMEM_PERMS=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled" " arm_kernmem_perms='yes'>" '"arm_kernmem_perms":"yes",'
else
echo_message "\033[31mDisabled\033[m\n" "Disabled," " arm_kernmem_perms='no'>" '"arm_kernmem_perms":"no",'
fi
fi
if ${kconfig} | grep -qi 'CONFIG_DEBUG_ALIGN_RODATA'; then
echo_message " Make rodata strictly non-excutable: " "" "" ""
if ${kconfig} | grep -qi 'CONFIG_DEBUG_ALIGN_RODATA=y'; then
echo_message "\033[32mEnabled\033[m\n" "Enabled" " arm_strict_rodata='yes'>" '"arm_strict_rodata":"yes",'
else