-
-
Notifications
You must be signed in to change notification settings - Fork 223
/
F20_vul_aggregator.sh
executable file
·1693 lines (1504 loc) · 77.3 KB
/
F20_vul_aggregator.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
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
#!/bin/bash -p
# EMBA - EMBEDDED LINUX ANALYZER
#
# Copyright 2020-2024 Siemens Energy AG
#
# EMBA comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
# welcome to redistribute it under the terms of the GNU General Public License.
# See LICENSE file for usage of this software.
#
# EMBA is licensed under GPLv3
#
# Author(s): Michael Messner
# Description: Aggregates all found version numbers together from S06, S08, S09, S25, S26,
# S115/S116 and L15.
# The versions are used for identification of known vulnerabilities cve-search,
# finally it creates a list of exploits that are matching for the CVEs.
F20_vul_aggregator() {
module_log_init "${FUNCNAME[0]}"
module_title "Final vulnerability aggregator"
pre_module_reporter "${FUNCNAME[0]}"
# we use this for later decisions:
export F20_DEEP=1
export WAIT_PIDS_F19=()
prepare_cve_search_module
local FOUND_CVE=0
local S26_LOGS_ARR=()
export CVE_AGGREGATOR_LOG="f20_vul_aggregator.txt"
local S02_LOG="${CSV_DIR}"/s02_uefi_fwhunt.csv
local S06_LOG="${CSV_DIR}"/s06_distribution_identification.csv
local S08_LOG="${CSV_DIR}"/s08_package_mgmt_extractor.csv
local S09_LOG="${CSV_DIR}"/s09_firmware_base_version_check.csv
local S24_LOG="${CSV_DIR}"/s24_kernel_bin_identifier.csv
local S25_LOG="${CSV_DIR}"/s25_kernel_check.csv
export S26_LOG_DIR="${LOG_DIR}"/s26_kernel_vuln_verifier/
local S36_LOG="${CSV_DIR}"/s36_lighttpd.csv
local S116_LOG="${CSV_DIR}"/s116_qemu_version_detection.csv
local S118_LOG="${CSV_DIR}"/s118_busybox_verifier.csv
local L15_LOG="${CSV_DIR}"/l15_emulated_checks_nmap.csv
local L25_LOG="${CSV_DIR}"/l25_web_checks.csv
local L35_LOG="${CSV_DIR}"/l35_metasploit_check.csv
if [[ -d "${S26_LOG_DIR}" ]]; then
mapfile -t S26_LOGS_ARR < <(find "${S26_LOG_DIR}" -name "cve_results_kernel_*.csv")
fi
local CVE_MINIMAL_LOG="${LOG_PATH_MODULE}"/CVE_minimal.txt
local EXPLOIT_OVERVIEW_LOG="${LOG_PATH_MODULE}"/exploits-overview.txt
export KERNEL_CVE_VERIFIED=()
export KERNEL_CVE_VERIFIED_VERSION=()
if [[ -f "${CVE_WHITELIST}" ]] && [[ $(grep -c -E "CVE-[0-9]+-[0-9]+" "${CVE_WHITELIST}") -gt 0 ]]; then
print_output "[!] WARNING: CVE whitelisting activated"
fi
if [[ -f "${CVE_BLACKLIST}" ]] && [[ $(grep -c -E "CVE-[0-9]+-[0-9]+" "${CVE_BLACKLIST}") -gt 0 ]]; then
print_output "[!] WARNING: CVE blacklisting activated"
fi
if [[ -d ${NVD_DIR} ]]; then
print_output "[*] Aggregate vulnerability details"
# get the kernel version from s24 and s25:
get_kernel_check "${S24_LOG}" "${S25_LOG}"
# if we found a kernel in the kernel checker module we are going to use this kernel version (usually this version is better)
# [+] Found Version details (base check): Linux kernel version 2.6.33
# vs:
# [+] Found Version details (kernel): Linux kernel version 2.6.33.2
if [[ -v KERNEL_CVE_EXPLOITS[@] ]]; then
if [[ ${#KERNEL_CVE_EXPLOITS[@]} -ne 0 ]]; then
# then we have found a kernel in our s25 kernel module
KERNELV=1
fi
fi
if [[ -v S26_LOGS_ARR ]]; then
get_kernel_verified "${S26_LOGS_ARR[@]}"
fi
get_uefi_details "${S02_LOG}"
get_firmware_details "${S06_LOG}"
get_package_details "${S08_LOG}"
get_lighttpd_details "${S36_LOG}"
get_firmware_base_version_check "${S09_LOG}"
get_usermode_emulator "${S116_LOG}"
get_systemmode_emulator "${L15_LOG}"
get_systemmode_webchecks "${L25_LOG}"
get_msf_verified "${L35_LOG}"
get_busybox_verified "${S118_LOG}"
aggregate_versions
write_csv_log "BINARY" "VERSION" "CVE identifier" "CVSS rating" "exploit db exploit available" "metasploit module" "trickest PoC" "Routersploit" "Snyk PoC" "Packetstormsecurity PoC" "local exploit" "remote exploit" "DoS exploit" "known exploited vuln" "kernel vulnerability verified" "FIRST EPSS" "FIRST PERC"
if [[ "${#VERSIONS_AGGREGATED[@]}" -gt 0 ]]; then
generate_cve_details_versions "${VERSIONS_AGGREGATED[@]}"
fi
if [[ "${#CVES_AGGREGATED[@]}" -gt 0 ]]; then
generate_cve_details_cves "${CVES_AGGREGATED[@]}"
fi
generate_special_log "${CVE_MINIMAL_LOG}" "${EXPLOIT_OVERVIEW_LOG}"
else
print_output "[-] WARNING: No CVE datasources found in external directory"
fi
FOUND_CVE=$(sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" "${LOG_FILE}" | grep -c -E "\[\+\]\ Found\ " || true)
module_end_log "${FUNCNAME[0]}" "${FOUND_CVE}"
}
prepare_cve_search_module() {
# we need to setup different exports for F20
export CVE_COUNTER=0
export KERNELV=0
export CVE_SEARCHSPLOIT=0
export RS_SEARCH=0
export MSF_SEARCH=0
export CVE_SEARCHSPLOIT=0
export MSF_INSTALL_PATH="/usr/share/metasploit-framework"
export BUSYBOX_VERIFIED_CVE=()
if command -v cve_searchsploit > /dev/null ; then
export CVE_SEARCHSPLOIT=1
fi
if [[ -f "${MSF_DB_PATH}" ]]; then
export MSF_SEARCH=1
fi
if [[ -f "${CONFIG_DIR}"/routersploit_cve-db.txt || -f "${CONFIG_DIR}"/routersploit_exploit-db.txt ]]; then
export RS_SEARCH=1
fi
if [[ -f "${CONFIG_DIR}"/PS_PoC_results.csv ]]; then
export PS_SEARCH=1
fi
if [[ -f "${CONFIG_DIR}"/Snyk_PoC_results.csv ]]; then
export SNYK_SEARCH=1
fi
if ! [[ -d "${LOG_PATH_MODULE}""/exploit/" ]]; then
mkdir -p "${LOG_PATH_MODULE}""/exploit/"
fi
if ! [[ -d "${LOG_PATH_MODULE}""/cve_sum/" ]]; then
mkdir -p "${LOG_PATH_MODULE}""/cve_sum/"
fi
}
aggregate_versions() {
sub_module_title "Software inventory generation."
local VERSION=""
export VERSIONS_AGGREGATED=()
local VERSIONS_KERNEL=()
local KERNELS=()
if [[ ${#VERSIONS_STAT_CHECK[@]} -gt 0 || ${#VERSIONS_EMULATOR[@]} -gt 0 || ${#KERNEL_CVE_EXPLOITS[@]} -gt 0 || ${#VERSIONS_SYS_EMULATOR[@]} -gt 0 || \
${#VERSIONS_S06_FW_DETAILS[@]} -gt 0 || ${#VERSIONS_SYS_EMULATOR_WEB[@]} -gt 0 || "${#CVE_S02_DETAILS[@]}" -gt 0 || "${#CVE_L35_DETAILS[@]}" -gt 0 || \
"${#VERSIONS_S36_DETAILS[@]}" -gt 0 || ${#KERNEL_CVE_VERIFIED[@]} -gt 0 || ${#BUSYBOX_VERIFIED_CVE[@]} -gt 0 ]]; then
print_output "[*] Software inventory initial overview:"
write_anchor "softwareinventoryinitialoverview"
for VERSION in "${VERSIONS_S06_FW_DETAILS[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
print_output "[+] Found Version details (${ORANGE}firmware details check${GREEN}): ""${ORANGE}${VERSION}${NC}"
done
for VERSION in "${VERSIONS_S08_PACKAGE_DETAILS[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
print_output "[+] Found Version details (${ORANGE}package management system check${GREEN}): ""${ORANGE}${VERSION}${NC}"
done
for VERSION in "${VERSIONS_S36_DETAILS[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
print_output "[+] Found Version details (${ORANGE}lighttpd statical check${GREEN}): ""${ORANGE}${VERSION}${NC}"
done
for VERSION in "${VERSIONS_STAT_CHECK[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
print_output "[+] Found Version details (${ORANGE}statical check${GREEN}): ""${ORANGE}${VERSION}${NC}"
done
for VERSION in "${VERSIONS_EMULATOR[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
print_output "[+] Found Version details (${ORANGE}emulator${GREEN}): ""${ORANGE}${VERSION}${NC}"
done
for VERSION in "${VERSIONS_SYS_EMULATOR[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
print_output "[+] Found Version details (${ORANGE}system emulator${GREEN}): ""${ORANGE}${VERSION}${NC}"
done
for VERSION in "${VERSIONS_SYS_EMULATOR_WEB[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
print_output "[+] Found Version details (${ORANGE}system emulator - web${GREEN}): ""${ORANGE}${VERSION}${NC}"
done
for VERSION in "${KERNEL_CVE_EXPLOITS[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
VERSION="$(echo "${VERSION}" | cut -d\; -f1-2 | tr ';' ':')"
print_output "[+] Found Version details (${ORANGE}kernel${GREEN}): ""${ORANGE}${VERSION}${NC}"
# we ensure that we search for the correct kernel version by adding a : at the end of the search string
VERSION=${VERSION/%/:}
VERSIONS_KERNEL+=( "${VERSION}" )
# print_output "[+] Added modfied Kernel Version details (${ORANGE}kernel$GREEN): ""$ORANGE$VERSION$NC"
done
# details from module s26
for VERSION in "${KERNEL_CVE_VERIFIED_VERSION[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
VERSION="$(echo "${VERSION}" | cut -d\; -f1 | sed 's/^/linux_kernel:/')"
print_output "[+] Found Version details (${ORANGE}kernel - with verified vulnerability details${GREEN}): ""${ORANGE}${VERSION}${NC}"
# we ensure that we search for the correct kernel version by adding a : at the end of the search string
VERSION=${VERSION/%/:}
VERSIONS_KERNEL+=( "${VERSION}" )
# print_output "[+] Added modfied Kernel Version details (${ORANGE}kernel$GREEN): ""$ORANGE$VERSION$NC"
done
for CVE_ENTRY in "${CVE_S02_DETAILS[@]}"; do
if [ -z "${CVE_ENTRY}" ]; then
continue
fi
if ! [[ "${CVE_ENTRY}" == *CVE-[0-9]* ]]; then
print_output "[-] WARNING: Broken CVE identifier found: ${ORANGE}${CVE_ENTRY}${NC}"
continue
fi
print_output "[+] Found CVE details (${ORANGE}binarly UEFI module${GREEN}): ""${ORANGE}${CVE_ENTRY}${NC}"
done
for CVE_ENTRY in "${CVE_L35_DETAILS[@]}"; do
if [ -z "${CVE_ENTRY}" ]; then
continue
fi
if ! [[ "${CVE_ENTRY}" == *CVE-[0-9]* ]]; then
print_output "[-] WARNING: Broken CVE identifier found: ${ORANGE}${CVE_ENTRY}${NC}"
continue
fi
print_output "[+] Found CVE details (${ORANGE}verified Metasploit exploits${GREEN}): ""${ORANGE}${CVE_ENTRY}${NC}"
done
local BUSYBOX_VERIFIED_VERSION=()
for ENTRY in "${BUSYBOX_VERIFIED_CVE[@]}"; do
CVE_ENTRY="${ENTRY/*\;/}"
if [ -z "${CVE_ENTRY}" ]; then
continue
fi
if ! [[ "${CVE_ENTRY}" == *CVE-[0-9]* ]]; then
print_output "[-] WARNING: Broken CVE identifier found: ${ORANGE}${CVE_ENTRY}${NC}"
continue
fi
print_output "[+] Found CVE details (${ORANGE}verified BusyBox CVE${GREEN}): ""${ORANGE}${CVE_ENTRY}${NC}"
print_output "[+] Found version details (${ORANGE}verified BusyBox CVE${GREEN}): ""${ORANGE}${ENTRY/\;*/}${NC}"
# we create a quick temp array for adding the details to the VERSIONS_AGGREGATED array
BUSYBOX_VERIFIED_VERSION+=( "${ENTRY/\;*/}" )
done
VERSIONS_AGGREGATED=("${VERSIONS_EMULATOR[@]}" "${VERSIONS_KERNEL[@]}" "${VERSIONS_STAT_CHECK[@]}" "${VERSIONS_SYS_EMULATOR[@]}" "${VERSIONS_S06_FW_DETAILS[@]}" "${VERSIONS_S08_PACKAGE_DETAILS[@]}" "${VERSIONS_S36_DETAILS[@]}" "${VERSIONS_SYS_EMULATOR_WEB[@]}" "${BUSYBOX_VERIFIED_VERSION[@]}")
# if we get from a module CVE details we also need to handle them
CVES_AGGREGATED=("${CVE_S02_DETAILS[@]}" "${CVE_L35_DETAILS[@]}")
fi
# sorting and unique our versions array:
eval "CVES_AGGREGATED=($(for i in "${CVES_AGGREGATED[@]}" ; do echo "\"${i}\"" ; done | sort -u))"
eval "VERSIONS_AGGREGATED=($(for i in "${VERSIONS_AGGREGATED[@]}" ; do echo "\"${i}\"" ; done | sort -u))"
if [[ -v VERSIONS_AGGREGATED[@] ]]; then
for VERSION in "${VERSIONS_AGGREGATED[@]}"; do
if [ -z "${VERSION}" ]; then
continue
fi
if [[ "${VERSION}" == *" "* ]]; then
print_output "[-] WARNING: Broken version identifier found: ${ORANGE}${VERSION}${NC}"
continue
fi
if ! [[ "${VERSION}" == *[0-9]* ]]; then
print_output "[-] WARNING: Broken version identifier found: ${ORANGE}${VERSION}${NC}"
continue
fi
if ! [[ "${VERSION}" == *":"* ]]; then
print_output "[-] WARNING: Broken version identifier found: ${ORANGE}${VERSION}${NC}"
continue
fi
write_log "${VERSION}" "${LOG_PATH_MODULE}"/versions.tmp
done
fi
if [[ -f "${LOG_PATH_MODULE}"/versions.tmp ]]; then
# on old kernels it takes a huge amount of time to query all kernel CVE's. So, we move the kernel entry to the begin of our versions array
mapfile -t KERNELS < <(grep kernel "${LOG_PATH_MODULE}"/versions.tmp | sort -u || true)
grep -v kernel "${LOG_PATH_MODULE}"/versions.tmp | sort -u > "${LOG_PATH_MODULE}"/versions1.tmp || true
for KERNEL in "${KERNELS[@]}"; do
if [[ -f "${LOG_PATH_MODULE}"/versions1.tmp ]]; then
if [[ $( wc -l "${LOG_PATH_MODULE}"/versions1.tmp | awk '{print $1}') -eq 0 ]] ; then
echo "${KERNEL}" > "${LOG_PATH_MODULE}"/versions1.tmp
else
sed -i "1s/^/${KERNEL}\n/" "${LOG_PATH_MODULE}"/versions1.tmp
fi
fi
done
if [[ -f "${LOG_PATH_MODULE}"/versions1.tmp ]]; then
mapfile -t VERSIONS_AGGREGATED < <(cat "${LOG_PATH_MODULE}"/versions1.tmp)
fi
rm "${LOG_PATH_MODULE}"/versions*.tmp 2>/dev/null
# leave this here for debugging reasons
if [[ ${#VERSIONS_AGGREGATED[@]} -ne 0 ]]; then
print_bar ""
print_output "[*] Software inventory aggregated:"
for VERSION in "${VERSIONS_AGGREGATED[@]}"; do
# ensure our set anchor is based on the binary name and is limited to 20 characters:
local ANCHOR="${VERSION/:*/}"
ANCHOR="cve_${ANCHOR:0:20}"
print_output "[+] Found Version details (${ORANGE}aggregated${GREEN}): ""${ORANGE}${VERSION}${NC}"
write_link "f20#${ANCHOR}"
done
for CVE_ENTRY in "${CVES_AGGREGATED[@]}"; do
print_output "[+] Found CVE details (${ORANGE}aggregated${GREEN}): ""${ORANGE}${CVE_ENTRY}${NC}"
done
print_bar ""
else
print_output "[-] No Version details found."
fi
else
print_output "[-] No Version details found."
fi
}
generate_special_log() {
local CVE_MINIMAL_LOG="${1:-}"
local EXPLOIT_OVERVIEW_LOG="${2:-}"
if [[ $(grep -c "Found.*CVEs\ .*and" "${LOG_FILE}" || true) -gt 0 ]]; then
sub_module_title "Minimal report of exploits and CVE's."
write_anchor "minimalreportofexploitsandcves"
local EXPLOIT_HIGH=0
local EXPLOIT_MEDIUM=0
local EXPLOIT_LOW=0
local KNOWN_EXPLOITED_VULNS=()
local KNOWN_EXPLOITED_VULN=""
local FILES=()
local FILE=""
local NAME=""
local CVE_VALUES=""
local EXPLOIT_=""
local EXPLOITS_AVAIL=()
readarray -t FILES < <(find "${LOG_PATH_MODULE}"/ -maxdepth 1 -type f -name "*.txt")
print_ln
print_output "[*] CVE log file generated."
write_link "${CVE_MINIMAL_LOG}"
print_ln
for FILE in "${FILES[@]}"; do
if [[ "${FILE}" == *"F20_summary"* ]]; then
continue
fi
if [[ "${FILE}" == *"exploits-overview"* ]]; then
continue
fi
local CVE_OUTPUT=""
NAME=$(basename "${FILE}" | sed -e 's/\.txt//g' | sed -e 's/_/\ /g')
mapfile -t CVE_VALUES < <(cut -d ":" -f1 "${FILE}") # | paste -s -d ',' || true)
# we need to check the whitelisted and blacklisted CVEs here:
for CVE_VALUE in "${CVE_VALUES[@]}"; do
if grep -q "^${CVE_VALUE}$" "${CVE_BLACKLIST}"; then
continue
fi
if [[ $(grep -E -c "^CVE-[0-9]+-[0-9]+$" "${CVE_WHITELIST}") -gt 0 ]]; then
if ! grep -q ^"${CVE_VALUE}"$ "${CVE_WHITELIST}"; then
continue
fi
fi
CVE_OUTPUT="${CVE_OUTPUT}"",""${CVE_VALUE}"
done
if [[ "${CVE_OUTPUT}" == *CVE-* ]]; then
CVE_OUTPUT=${CVE_OUTPUT#,}
print_output "[*] CVE details for ${GREEN}${NAME}${NC}:\\n"
print_output "${CVE_OUTPUT}"
write_log "\n[*] CVE details for ${GREEN}${NAME}${NC}:" "${CVE_MINIMAL_LOG}"
write_log "${CVE_OUTPUT}" "${CVE_MINIMAL_LOG}"
print_ln
fi
done
write_log "\n[*] Exploit summary:" "${EXPLOIT_OVERVIEW_LOG}"
grep -E "Exploit\ \(" "${LOG_DIR}"/"${CVE_AGGREGATOR_LOG}" | sort -t : -k 4 -h -r | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> "${EXPLOIT_OVERVIEW_LOG}" || true
mapfile -t EXPLOITS_AVAIL < <(grep -E "Exploit\ \(" "${LOG_DIR}"/"${CVE_AGGREGATOR_LOG}" | sort -t : -k 4 -h -r || true)
if [[ "${#EXPLOITS_AVAIL[@]}" -gt 0 ]]; then
print_ln
print_output "[*] Minimal exploit summary file generated."
write_link "${EXPLOIT_OVERVIEW_LOG}"
print_ln
fi
for EXPLOIT_ in "${EXPLOITS_AVAIL[@]}"; do
# remove color codes:
EXPLOIT_=$(echo "${EXPLOIT_}" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")
# extract CVSS value:
CVSS_VALUE=$(echo "${EXPLOIT_}" | sed -E 's/.*[[:blank:]]CVE-[0-9]{4}-[0-9]+[[:blank:]]//g' | cut -d: -f2 | sed -E 's/\ \(v2\)//g' | sed -e 's/[[:blank:]]//g' | tr -dc '[:print:]')
if (( $(echo "${CVSS_VALUE} > 6.9" | bc -l) )); then
print_output "${RED}${EXPLOIT_}${NC}"
((EXPLOIT_HIGH+=1))
elif (( $(echo "${CVSS_VALUE} > 3.9" | bc -l) )); then
print_output "${ORANGE}${EXPLOIT_}${NC}"
((EXPLOIT_MEDIUM+=1))
else
print_output "${GREEN}${EXPLOIT_}${NC}"
((EXPLOIT_LOW+=1))
fi
done
if [[ -f "${LOG_PATH_MODULE}"/exploit/known_exploited_vulns.log ]]; then
mapfile -t KNOWN_EXPLOITED_VULNS < <(grep -E "known exploited" "${LOG_PATH_MODULE}"/exploit/known_exploited_vulns.log || true 2>/dev/null)
if [[ -v KNOWN_EXPLOITED_VULNS[@] ]]; then
print_ln
print_output "[*] Summary of known exploited vulnerabilities:"
write_link "${LOG_PATH_MODULE}/exploit/known_exploited_vulns.log"
for KNOWN_EXPLOITED_VULN in "${KNOWN_EXPLOITED_VULNS[@]}"; do
print_output "${KNOWN_EXPLOITED_VULN}"
done
print_ln
fi
fi
echo "${EXPLOIT_HIGH}" > "${TMP_DIR}"/EXPLOIT_HIGH_COUNTER.tmp
echo "${EXPLOIT_MEDIUM}" > "${TMP_DIR}"/EXPLOIT_MEDIUM_COUNTER.tmp
echo "${EXPLOIT_LOW}" > "${TMP_DIR}"/EXPLOIT_LOW_COUNTER.tmp
echo "${#KNOWN_EXPLOITED_VULNS[@]}" > "${TMP_DIR}"/KNOWN_EXPLOITED_COUNTER.tmp
fi
}
generate_cve_details_cves() {
sub_module_title "CVE and exploit details."
write_anchor "cveandexploitdetails"
local CVES_AGGREGATED=("$@")
local CVE_ENTRY=""
CVE_COUNTER=0
for CVE_ENTRY in "${CVES_AGGREGATED[@]}"; do
if [[ "${THREADED}" -eq 1 ]]; then
cve_db_lookup_cve "${CVE_ENTRY}" &
WAIT_PIDS_F19+=( "$!" )
max_pids_protection "$(("${MAX_MOD_THREADS}"*2))" "${WAIT_PIDS_F19[@]}"
else
cve_db_lookup_cve "${CVE_ENTRY}"
fi
done
if [[ "${THREADED}" -eq 1 ]]; then
wait_for_pid "${WAIT_PIDS_F19[@]}"
fi
}
generate_cve_details_versions() {
sub_module_title "Collect CVE and exploit details from versions."
write_anchor "collectcveandexploitdetails"
CVE_COUNTER=0
local VERSIONS_AGGREGATED=("$@")
local BIN_VERSION=""
for BIN_VERSION in "${VERSIONS_AGGREGATED[@]}"; do
# BIN_VERSION is something like "binary:1.2.3"
if [[ "${THREADED}" -eq 1 ]]; then
cve_db_lookup_version "${BIN_VERSION}" &
WAIT_PIDS_F19+=( "$!" )
max_pids_protection "$(("${MAX_MOD_THREADS}"*2))" "${WAIT_PIDS_F19[@]}"
else
cve_db_lookup_version "${BIN_VERSION}"
fi
done
if [[ "${THREADED}" -eq 1 ]]; then
wait_for_pid "${WAIT_PIDS_F19[@]}"
fi
}
cve_db_lookup_cve() {
local CVE_ENTRY="${1:-}"
local CVE_ID=""
local CVE_V2=""
local CVE_V31=""
print_output "[*] CVE database lookup with CVE information: ${ORANGE}${CVE_ENTRY}${NC}" "no_log"
# there should be only one CVE file available
CVE_SOURCE=$(find "${NVD_DIR}" -name "${CVE_ENTRY}.json" | sort -u | head -1)
if [[ -f "${CVE_SOURCE}" ]]; then
CVE_ID=$(jq -r '.id' "${CVE_SOURCE}")
CVE_V2=$(jq -r '.metrics.cvssMetricV2[]?.cvssData.baseScore' "${CVE_SOURCE}")
# CVE_V31=$(jq -r '.metrics.cvssMetricV31[]?.cvssData.baseScore' "${CVE_SOURCE}"
CVE_V31=$(jq -r '.metrics.cvssMetricV31[]? | select(.type=="Primary") | .cvssData.baseScore' "${CVE_SOURCE}")
echo "${CVE_ID}:${CVE_V2:-"NA"}:${CVE_V31:-"NA"}" > "${LOG_PATH_MODULE}"/"${CVE_ENTRY}".txt || true
fi
# only do further analysis if needed
# in case we come from s26 module we do not need all the upcoming analysis
if [[ "${F20_DEEP}" == 1 ]]; then
cve_extractor "${CVE_ENTRY}"
fi
}
cve_db_lookup_version() {
# BIN_VERSION_ is something like "binary:1.2.3"
# function writes log files to "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt
local BIN_VERSION_="${1:-}"
local CVE_ID=""
local BIN_NAME=""
BIN_NAME=$(echo "${BIN_VERSION_}" | cut -d':' -f1)
# we create something like "binary_1.2.3" for log paths
# remove last : if it is there
local VERSION_PATH="${BIN_VERSION_%:}"
VERSION_PATH="${VERSION_PATH//:/_}"
local WAIT_PIDS_F19_CVE_SOURCE=()
local CVE_VER_SOURCES_ARR=()
local CVE_VER_SOURCES_ARR_DLINK=()
local VERSION_SEARCHx=""
# if we did the CVE analysis already in module s26, we can just use these results for our further analysis
# -> we skip the complete CVE analysis here:
if [[ "${BIN_NAME}" == *"linux_kernel"* ]] && [[ -s "${LOG_DIR}"/s26_kernel_vuln_verifier/"${VERSION_PATH}".txt ]]; then
print_output "[*] Detected kernel vulnerability details from module S26 - going to use these details"
cp "${LOG_DIR}"/s26_kernel_vuln_verifier/"${VERSION_PATH}".txt "${LOG_PATH_MODULE}" || (print_output "[-] S26 kernel vulns file found, but something was going wrong")
cve_extractor "${BIN_VERSION_}"
return
fi
# we test for the binary_name:version and for binary_name:*:
print_output "[*] CVE database lookup with version information: ${ORANGE}${BIN_VERSION_}${NC}" "no_log"
mapfile -t CVE_VER_SOURCES_ARR < <(grep -l -r "cpe:[0-9]\.[0-9]:[a-z]:.*${BIN_VERSION_%:}:.*:.*:.*:.*:.*:\|cpe:[0-9]\.[0-9]:[a-z]:.*${BIN_NAME}:\*:.*:.*:.*:.*:.*:" "${NVD_DIR}" | sort -u || true)
print_output "[*] CVE database lookup with version information: ${ORANGE}${BIN_VERSION_}${NC} resulted in ${ORANGE}${#CVE_VER_SOURCES_ARR[@]}${NC} possible vulnerabilities" "no_log"
if [[ "${BIN_VERSION_}" == *"dlink"* ]]; then
# dlink extrawurst: dlink vs d-link
# do a second cve-database check
VERSION_SEARCHx="$(echo "${BIN_VERSION_}" | sed 's/dlink/d-link/' | sed 's/_firmware//')"
print_output "[*] CVE database lookup with version information: ${ORANGE}${VERSION_SEARCHx}${NC}" "no_log"
mapfile -t CVE_VER_SOURCES_ARR_DLINK < <(grep -l -r "cpe:[0-9]\.[0-9]:[a-z]:.*${VERSION_SEARCHx}" "${NVD_DIR}" || true)
CVE_VER_SOURCES_ARR+=( "${CVE_VER_SOURCES_ARR_DLINK[@]}" )
fi
for CVE_VER_SOURCES_FILE in "${CVE_VER_SOURCES_ARR[@]}"; do
CVE_ID=$(jq -r '.id' "${CVE_VER_SOURCES_FILE}")
if [[ "${THREADED}" -eq 1 ]]; then
# analysis of cve json files in parallel
check_cve_sources "${CVE_ID}" "${BIN_VERSION_}" "${CVE_VER_SOURCES_FILE}" &
WAIT_PIDS_F19_CVE_SOURCE+=( "$!" )
max_pids_protection "$(("${MAX_MOD_THREADS}"*2))" "${WAIT_PIDS_F19_CVE_SOURCE[@]}"
else
check_cve_sources "${CVE_ID}" "${BIN_VERSION_}" "${CVE_VER_SOURCES_FILE}"
fi
done
[[ "${THREADED}" -eq 1 ]] && wait_for_pid "${WAIT_PIDS_F19_CVE_SOURCE[@]}"
# only do further analysis if needed
# in case we come from s26 module we do not need all the upcoming analysis
if [[ "${F20_DEEP}" == 1 ]]; then
cve_extractor "${BIN_VERSION_}"
fi
}
get_epss_data() {
local lCVE_ID="${1:-}"
local lCVE_EPSS_PATH=""
local lEPSS_PERC=""
local lEPSS_EPSS=""
local lEPSS_DATA=""
local lCVE_YEAR=""
lCVE_YEAR="$(echo "${lCVE_ID}" | cut -d '-' -f2)"
lCVE_EPSS_PATH="${EPSS_DATA_PATH}/CVE_${lCVE_YEAR}_EPSS.csv"
if [[ -f "${lCVE_EPSS_PATH}" ]]; then
lEPSS_DATA=$(grep "^${lCVE_ID};" "${lCVE_EPSS_PATH}" || true)
lEPSS_PERC=$(echo "${lEPSS_DATA}" | cut -d ';' -f3)
lEPSS_PERC=$(echo "${lEPSS_PERC} 100" | awk '{printf "%d", $1 * $2}')
# just cut it for now ...
lEPSS_EPSS=$(echo "${lEPSS_DATA}" | cut -d ';' -f2)
lEPSS_EPSS=$(echo "${lEPSS_EPSS} 100" | awk '{printf "%d", $1 * $2}')
fi
[[ ! "${lEPSS_EPSS}" =~ ^[0-9]+$ ]] && lEPSS_EPSS="NA"
[[ ! "${lEPSS_PERC}" =~ ^[0-9]+$ ]] && lEPSS_PERC="NA"
echo "${lEPSS_EPSS};${lEPSS_PERC}"
}
# Test the identified JSON files for CPE details and version information
# to ensure our BIN_VERSION is affected
check_cve_sources() {
local CVE_ID="${1:-}"
local BIN_VERSION_="${2:-}"
local CVE_VER_SOURCES_FILE="${3:-}"
local BIN_VERSION_ONLY=""
# if we have a version identifier like binary:1.2.3: we need to remove the last ':' before cutting it correctly
BIN_VERSION_ONLY=$(echo "${BIN_VERSION_%:}" | rev | cut -d':' -f1 | rev)
local BIN_NAME=""
BIN_NAME=$(echo "${BIN_VERSION_%:}" | rev | cut -d':' -f2 | rev)
local CVE_VER_START_INCL=""
local CVE_VER_START_EXCL=""
local CVE_VER_END_INCL=""
local CVE_VER_END_EXCL=""
local CVE_V2=""
local CVE_V31=""
local CVE_CPEs_vuln_ARR=()
local CVE_CPEMATCH=""
local CVE_SUMMARY=""
local lFIRST_EPSS=""
# print_output "[*] Testing binary ${BIN_NAME} with version ${BIN_VERSION_ONLY} for CVE matches ..." "no_log"
CVE_V2=$(jq -r '.metrics.cvssMetricV2[]?.cvssData.baseScore' "${CVE_VER_SOURCES_FILE}" | tr -dc '[:print:]')
# CVE_V31=$(jq -r '.metrics.cvssMetricV31[]?.cvssData.baseScore' "${CVE_VER_SOURCES_FILE}" | tr -dc '[:print:]')
CVE_V31=$(jq -r '.metrics.cvssMetricV31[]? | select(.type=="Primary") | .cvssData.baseScore' "${CVE_VER_SOURCES_FILE}" | tr -dc '[:print:]')
CVE_SUMMARY=$(escape_echo "$(jq -r '.descriptions[] | select(.lang=="en") | .value' "${CVE_VER_SOURCES_FILE}")")
# we need to check if any cpe of the CVE is vulnerable
# └─$ cat external/nvd-json-data-feeds/CVE-2011/CVE-2011-24xx/CVE-2011-2416.json | jq '.configurations[].nodes[].cpeMatch[] | select(.vulnerable==true) | .criteria' | grep linux
if [[ "$(jq -r '.configurations[].nodes[].cpeMatch[] | select(.vulnerable==true) | .criteria' "${CVE_VER_SOURCES_FILE}" | grep -c "${BIN_NAME}")" -eq 0 ]]; then
# print_output "[-] No matching criteria found - binary ${BIN_NAME} not vulnerable for CVE ${CVE_ID}" "no_log"
return
fi
# we get "EPSS;percentage" back
lFIRST_EPSS=$(get_epss_data "${CVE_ID}")
# if our cpe with the binary version matches we have a vuln and we can continue
if grep -q "cpe.*:${BIN_VERSION_%:}:" "${CVE_VER_SOURCES_FILE}"; then
# print_output "[+] CPE matches - vulnerability identified - CVE: ${CVE_ID} / BIN: ${BIN_VERSION_}" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-NA}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
return
fi
# extract valid CPEs matching our cpe.*:binary:*: from the CVE details
# usually this should only one cpe but in case we are using ARR. With this cpe ARR we can further check for versions from the CVE details like
# .versionStartIncluding
# .versionStartExcluding
# .versionEndIncluding
# .versionEndExcluding
mapfile -t CVE_CPEs_vuln_ARR < <(jq -rc '.configurations[].nodes[].cpeMatch[] | select(.vulnerable==true)' "${CVE_VER_SOURCES_FILE}" | grep "cpe:[0-9]\.[0-9]:[a-z]:.*:${BIN_NAME}:\*:" || true)
# the result looks like the following:
# └─$ jq -rc '.configurations[].nodes[].cpeMatch[] | select(.vulnerable==true)' external/nvd-json-data-feeds/CVE-2023/CVE-2023-02xx/CVE-2023-0215.json
# {"vulnerable":true,"criteria":"cpe:2.3:a:openssl:openssl:*:*:*:*:*:*:*:*","versionStartIncluding":"1.0.2","versionEndExcluding":"1.0.2zg","matchCriteriaId":"70985D55-A574-4151-B451-4D500CBFC29A"}
# {"vulnerable":true,"criteria":"cpe:2.3:a:openssl:openssl:*:*:*:*:*:*:*:*","versionStartIncluding":"1.1.1","versionEndExcluding":"1.1.1t","matchCriteriaId":"DE0061D6-8F81-45D3-B254-82A94915FD08"}
# {"vulnerable":true,"criteria":"cpe:2.3:a:openssl:openssl:*:*:*:*:*:*:*:*","versionStartIncluding":"3.0.0","versionEndExcluding":"3.0.8","matchCriteriaId":"A6DC5D88-4E99-48F2-8892-610ACA9B5B86"}
# {"vulnerable":true,"criteria":"cpe:2.3:a:stormshield:stormshield_management_center:*:*:*:*:*:*:*:*","versionEndExcluding":"3.3.3","matchCriteriaId":"62A933C5-C56E-485C-AD49-3B6A2C329131"}
# Now we walk through all the CPEMatch entries and extract the version details for further analysis
for CVE_CPEMATCH in "${CVE_CPEs_vuln_ARR[@]}"; do
# we need to check the version more in details in case we have no version in our cpe identifier
# └─$ jq -r '.configurations[].nodes[].cpeMatch[] | select(.criteria=="cpe:2.3:a:busybox:busybox:*:*:*:*:*:*:*:*") | .versionEndIncluding' external/nvd-json-data-feeds/CVE-2011/CVE-2011-27xx/CVE-2011-2716.json
# print_output "[*] Binary ${BIN_VERSION_} - Found no version identifier in our cpe for ${CVE_VER_SOURCES_FILE} - check for further version details with ${CVE_CPE_vuln}" "no_log"
# extract further version details form the current cpe under test
CVE_VER_START_INCL=$(echo "${CVE_CPEMATCH}" | jq -r '.versionStartIncluding' | grep -v "null" || true)
CVE_VER_START_EXCL=$(echo "${CVE_CPEMATCH}" | jq -r '.versionStartExcluding' | grep -v "null" || true)
CVE_VER_END_INCL=$(echo "${CVE_CPEMATCH}" | jq -r '.versionEndIncluding' | grep -v "null" || true)
CVE_VER_END_EXCL=$(echo "${CVE_CPEMATCH}" | jq -r '.versionEndExcluding' | grep -v "null" || true)
# if we have found some version details we need to further check them now:
if [[ -n "${CVE_VER_START_INCL}" || -n "${CVE_VER_START_EXCL}" || -n "${CVE_VER_END_INCL}" || -n "${CVE_VER_END_EXCL}" ]]; then
# print_output "[*] Binary ${BIN_VERSION_} - CVE ${CVE_ID} - CVE_VER_START_INCL / CVE_VER_START_EXCL / CVE_VER_END_INCL / CVE_VER_END_EXCL - ${CVE_VER_START_INCL} / ${CVE_VER_START_EXCL} / ${CVE_VER_END_INCL} / ${CVE_VER_END_EXCL}" "no_log"
## first check CVE_VER_START_INCL >= VERSION <= CVE_VER_END_INCL
if [[ -n "${CVE_VER_START_INCL}" ]]; then
# print_output "[*] ${BIN_VERSION_} - ${CVE_ID} - CVE_VER_START_INCL: ${CVE_VER_START_INCL} - $(version "${BIN_VERSION_ONLY}") vs $(version "${CVE_VER_START_INCL}")" "no_log"
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -lt "$(version_extended "${CVE_VER_START_INCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '<' "${CVE_VER_START_INCL}"; then
# BIN_VERSION is lt CVE_VER_START_INCL -> we can move on
continue
fi
# Case: if [[ "$(version "${BIN_VERSION_ONLY}")" -ge "$(version "${CVE_VER_START_INCL}")" ]]; then
# print_output "[*] ${CVE_ID} - CVE_VER_START_INCL - binary ${BIN_VERSION_} version $(version "${BIN_VERSION_ONLY}") is higher (incl) as CVE version $(version "${CVE_VER_START_INCL}")" "no_log"
# Todo: check for VERSION <= CVE_VER_END_INCL
if [[ -n "${CVE_VER_END_INCL}" ]]; then
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -le "$(version_extended "${CVE_VER_END_INCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '<=' "${CVE_VER_END_INCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_INCL / CVE_VER_END_INCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_END_INCL}" "${CVE_ID}"
fi
fi
continue
fi
## first check VERSION < CVE_VER_END_EXCL
if [[ -n "${CVE_VER_END_EXCL}" ]]; then
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -lt "$(version_extended "${CVE_VER_END_EXCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '<=' "${CVE_VER_END_EXCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_INCL / CVE_VER_END_EXCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_START_INCL}" "${CVE_ID}"
fi
fi
continue
fi
if ! [[ -n "${CVE_VER_END_EXCL}" && -n "${CVE_VER_START_INCL}" ]]; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_INCL / CVE_VER_END_EXCL: ${ORANGE}NA${GREEN} / CVE_VER_END_INCL: ${ORANGE}NA${GREEN}" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_END_INCL}" "${CVE_ID}"
fi
continue
fi
fi
if [[ -n "${CVE_VER_START_EXCL}" ]]; then
# print_output "[*] ${BIN_VERSION_ONLY} - ${CVE_ID} - CVE_VER_START_EXCL: ${CVE_VER_START_INCL}" "no_log"
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -le "$(version_extended "${CVE_VER_START_EXCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '<=' "${CVE_VER_START_EXCL}"; then
# BIN_VERSION is le CVE_VER_START_EXCL -> we can move on
continue
fi
# Case: if [[ "$(version "${BIN_VERSION_ONLY}")" -gt "$(version "${CVE_VER_START_EXCL}")" ]]; then
# print_output "[*] ${CVE_ID} - CVE_VER_START_EXCL - binary ${BIN_VERSION_} version $(version "${BIN_VERSION_ONLY}") is higher (excl) as CVE version $(version "${CVE_VER_START_EXCL}")" "no_log"
if [[ -n "${CVE_VER_END_INCL}" ]]; then
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -le "$(version_extended "${CVE_VER_END_INCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '<=' "${CVE_VER_END_INCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_EXCL / CVE_VER_END_INCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_END_INCL}" "${CVE_ID}"
fi
fi
continue
fi
if [[ -n "${CVE_VER_END_EXCL}" ]]; then
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -lt "$(version_extended "${CVE_VER_END_EXCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '<' "${CVE_VER_END_EXCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_EXCL / CVE_VER_END_EXCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_END_EXCL}" "${CVE_ID}"
fi
fi
continue
fi
if ! [[ -n "${CVE_VER_END_EXCL}" && -n "${CVE_VER_END_INCL}" ]]; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_EXCL / CVE_VER_END_INCL: ${ORANGE}NA${GREEN} / CVE_VER_END_EXCL: ${ORANGE}NA${GREEN}" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_START_EXCL}" "${CVE_ID}"
fi
continue
fi
fi
if [[ -n "${CVE_VER_END_INCL}" ]]; then
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -gt "$(version_extended "${CVE_VER_END_INCL}")" ]]; then
# print_output "[!] ${CVE_ID} - CVE_VER_END_INCL - binary ${BIN_VERSION_} - ${BIN_VERSION_ONLY} - CVE version ${CVE_VER_END_INCL}" "no_log"
if version_extended "${BIN_VERSION_ONLY}" '>' "${CVE_VER_END_INCL}"; then
# print_output "[!] ${CVE_ID} - CVE_VER_END_INCL - binary ${BIN_VERSION_} - ${BIN_VERSION_ONLY} - CVE version ${CVE_VER_END_INCL} - exit" "no_log"
# BIN_VERSION is gt CVE_VER_END_INCL -> we can move on
continue
fi
# This is the case: if [[ "$(version "${BIN_VERSION_ONLY}")" -le "$(version "${CVE_VER_END_INCL}")" ]]; then
# print_output "[*] ${CVE_ID} - CVE_VER_END_INCL - binary ${BIN_VERSION_} version $(version "${BIN_VERSION_ONLY}") is lower (incl) CVE version $(version "${CVE_VER_END_INCL}")" "no_log"
# our version is le the needed version
if [[ -n "${CVE_VER_START_INCL}" ]]; then
# if [[ "$(version_extended "${BIN_VERSION_ONLY}")" -ge "$(version_extended "${CVE_VER_START_INCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '>=' "${CVE_VER_START_INCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_INCL / CVE_VER_END_INCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_START_INCL}" "${CVE_ID}"
fi
fi
continue
fi
if [[ -n "${CVE_VER_START_EXCL}" ]]; then
# if [[ "$(version "${BIN_VERSION_ONLY}")" -gt "$(version "${CVE_VER_START_EXCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '>' "${CVE_VER_START_EXCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_EXCL / CVE_VER_END_INCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_START_EXCL}" "${CVE_ID}"
fi
fi
continue
fi
if ! [[ -n "${CVE_VER_START_EXCL}" && -n "${CVE_VER_START_INCL}" ]]; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_START_INCL: ${ORANGE}NA${GREEN} / CVE_VER_START_EXCL: ${ORANGE}NA${GREEN} / CVE_VER_END_INCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_END_INCL}" "${CVE_ID}"
fi
continue
fi
fi
if [[ -n "${CVE_VER_END_EXCL}" ]]; then
# if [[ "$(version "${BIN_VERSION_ONLY}")" -ge "$(version "${CVE_VER_END_EXCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '>=' "${CVE_VER_END_EXCL}"; then
# BIN_VERSION is ge CVE_VER_END_EXCL -> we can move on
continue
fi
# Case handling: if [[ "$(version "${BIN_VERSION_ONLY}")" -lt "$(version "${CVE_VER_END_EXCL}")" ]]; then
# print_output "[*] ${CVE_ID} - CVE_VER_END_EXCL - binary ${BIN_VERSION_} version $(version "${BIN_VERSION_ONLY}") is lower (excl) CVE version $(version "${CVE_VER_END_EXCL}")" "no_log"
# our version is le the needed version
if [[ -n "${CVE_VER_START_EXCL}" ]]; then
# if [[ "$(version "${BIN_VERSION_ONLY}")" -gt "$(version "${CVE_VER_START_EXCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '>' "${CVE_VER_START_EXCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_END_EXCL / CVE_VER_START_EXCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_START_EXCL}" "${CVE_ID}"
fi
continue
fi
fi
if [[ -n "${CVE_VER_START_INCL}" ]]; then
# if [[ "$(version "${BIN_VERSION_ONLY}")" -ge "$(version "${CVE_VER_START_INCL}")" ]]; then
if version_extended "${BIN_VERSION_ONLY}" '>=' "${CVE_VER_START_INCL}"; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_END_EXCL / CVE_VER_START_INCL" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_START_INCL}" "${CVE_ID}"
fi
continue
fi
fi
if ! [[ -n "${CVE_VER_START_INCL}" && -n "${CVE_VER_START_EXCL}" ]]; then
# print_output "[+] Vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} - source file ${CVE_VER_SOURCES_FILE} - CVE_VER_END_EXCL / CVE_VER_START_EXCL: ${ORANGE}NA${GREEN} / CVE_VER_START_INCL: ${ORANGE}NA${GREEN}" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
if [[ "${BIN_NAME}" == "linux_kernel" ]]; then
check_kernel_major_v "${BIN_VERSION_ONLY}" "${CVE_VER_END_EXCL}" "${CVE_ID}"
fi
continue
fi
fi
else
# if we have not found further version limitations, we assume that all versions are vulnerable:
# print_output "[+] CPE matches - vulnerability identified - CVE: ${CVE_ID} - binary ${BIN_VERSION_} version $(version "${BIN_VERSION_ONLY}") - no further version limitations detected" "no_log"
write_cve_log "${CVE_ID}" "${CVE_V2:-"NA"}" "${CVE_V31:-"NA"}" "${lFIRST_EPSS}" "${CVE_SUMMARY:-"NA"}" "${LOG_PATH_MODULE}"/"${VERSION_PATH}".txt &
fi
done
}
check_kernel_major_v() {
local lBIN_VERSION_ONLY="${1:-}"
local lKERNEL_CVE_VER="${2:-}"
local lCVE_ID="${3:-}"
if [[ "${lBIN_VERSION_ONLY:0:1}" != "${lKERNEL_CVE_VER:0:1}" ]]; then
# print_output is for printing to cli
# write_log is for writing the needed log file
local OUT_MESSAGE="[-] Info for CVE ${ORANGE}${lCVE_ID}${NC} - Major kernel version not matching ${ORANGE}${lKERNEL_CVE_VER}${NC} vs ${ORANGE}${lBIN_VERSION_ONLY}${NC} - Higher false positive risk"
print_output "${OUT_MESSAGE}" "no_log"
write_log "${OUT_MESSAGE}" "${LOG_PATH_MODULE}/kernel_cve_version_issues.log"
fi
}
write_cve_log() {
local lCVE_ID="${1:-}"
local lCVE_V2="${2:-}"
local lCVE_V31="${3:-}"
local lFIRST_EPSS="${4:-}"
local lCVE_SUMMARY="${5:-}"
local lCVE_LOG_FILE="${6:-}"
if [[ -s "${lCVE_LOG_FILE}" ]]; then
# check if we have already an entry for this CVE - if not, we will write it to the output file
if ! grep -q "^${lCVE_ID}:" "${lCVE_LOG_FILE}" 2>/dev/null; then
echo "${lCVE_ID}:${lCVE_V2:-"NA"}:${lCVE_V31:-"NA"}:${lFIRST_EPSS/;/:}:${lCVE_SUMMARY:-"NA"}" >> "${lCVE_LOG_FILE}" || true
fi
else
echo "${lCVE_ID}:${lCVE_V2:-"NA"}:${lCVE_V31:-"NA"}:${lFIRST_EPSS/;/:}:${lCVE_SUMMARY:-"NA"}" > "${lCVE_LOG_FILE}" || true
fi
}
cve_extractor() {
# VERSION_orig is usually the BINARY_NAME:VERSION
# in some cases it is only the CVE-Identifier
local VERSION_orig="${1:-}"
local VERSION=""
local BINARY=""
export CVE_VALUE=""
local CVSS_VALUE=""
local VSOURCE="unknown"
export EXPLOIT_AVAIL=()
export EXPLOIT_AVAIL_MSF=()
export EXPLOIT_AVAIL_TRICKEST=()
export EXPLOIT_AVAIL_ROUTERSPLOIT=()
export EXPLOIT_AVAIL_ROUTERSPLOIT1=()
export EXPLOIT_AVAIL_PACKETSTORM=()
export EXPLOIT_AVAIL_SNYK=()
export KNOWN_EXPLOITED_VULNS=()
local KNOWN_EXPLOITED=0
local LOCAL=0
local REMOTE=0
local DOS=0
local CVEs_OUTPUT=()
local CVE_OUTPUT=""
local KERNEL_VERIFIED_VULN=0
if ! [[ "${VERSION_orig}" == "CVE-"* ]]; then
# remove last : if it is there
VERSION=$(echo "${BIN_VERSION_%:}" | rev | cut -d':' -f1 | rev)
BINARY=$(echo "${BIN_VERSION_%:}" | rev | cut -d':' -f2 | rev)
export AGG_LOG_FILE="${VERSION_PATH}".txt
else
export AGG_LOG_FILE="${VERSION_orig}".txt
fi
# VSOURCE is used to track the source of version details, this is relevant for the
# final report. With this in place we know if it is from live testing via the network
# or if it is found via static analysis or via user-mode emulation
if [[ -v S06_LOG && -v S09_LOG ]]; then
if grep -q "${VERSION_orig}" "${S06_LOG}" 2>/dev/null || grep -q "${VERSION_orig}" "${S09_LOG}" 2>/dev/null; then
if [[ "${VSOURCE}" == "unknown" ]]; then
VSOURCE="STAT"
else
VSOURCE+="/STAT"
fi
fi
fi
if [[ -v S25_LOG ]]; then
if [[ "${BINARY}" == *"kernel"* ]]; then
if grep -q "kernel;${VERSION};" "${S25_LOG}" 2>/dev/null; then
if [[ "${VSOURCE}" == "unknown" ]]; then
VSOURCE="STAT"
elif ! [[ "${VSOURCE}" =~ .*STAT.* ]]; then
VSOURCE+="/STAT"
fi
fi
fi
fi
if [[ -v S24_LOG ]]; then
if [[ "${BINARY}" == *"kernel"* ]]; then
if tail -n +2 "${S24_LOG}" | grep -i -q "linux.*${VERSION}" 2>/dev/null; then
if [[ "${VSOURCE}" == "unknown" ]]; then
VSOURCE="STAT"
elif ! [[ "${VSOURCE}" =~ .*STAT.* ]]; then
VSOURCE+="/STAT"
fi
fi
fi
fi
if [[ -v S116_LOG ]]; then
if grep -q "${VERSION_orig}" "${S116_LOG}" 2>/dev/null; then
if [[ "${VSOURCE}" == "unknown" ]]; then
VSOURCE="UEMU"
else
VSOURCE+="/UEMU"
fi
fi
fi
if [[ -v S02_LOG ]]; then
if grep -q "${VERSION_orig}" "${S02_LOG}" 2>/dev/null; then
if [[ "${VSOURCE}" == "unknown" ]]; then
VSOURCE="FwHunt"
else
VSOURCE+="/FwHunt"
fi
BINARY="UEFI firmware"
VERSION="unknown"
fi
fi
if [[ -v L35_LOG ]]; then
if grep -q "${VERSION_orig}" "${L35_LOG}" 2>/dev/null; then
if [[ "${VSOURCE}" == "unknown" ]]; then
VSOURCE="MSF verified"