-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
clamav-unofficial-sigs.sh
executable file
·4509 lines (4218 loc) · 208 KB
/
clamav-unofficial-sigs.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
#!/usr/bin/env bash
# shellcheck disable=SC2119
# shellcheck disable=SC2120
# shellcheck disable=SC2128
# shellcheck disable=SC2154
################################################################################
# This is property of eXtremeSHOK.com
# You are free to use, modify and distribute, however you may not remove this notice.
# Copyright (c) Adrian Jon Kriel :: [email protected]
# License: BSD (Berkeley Software Distribution)
################################################################################
#
# Script updates can be found at: https://github.com/extremeshok/clamav-unofficial-sigs
#
# Originially based on Script provided by Bill Landry ([email protected]).
#
################################################################################
#
# THERE ARE NO USER CONFIGURABLE OPTIONS IN THIS SCRIPT
# ALL CONFIGURATION OPTIONS ARE LOCATED IN THE INCLUDED CONFIGURATION FILE
#
################################################################################
###### ####### # # ####### ####### ####### ###### ### #######
# # # # ## # # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # # # # # # ##### # # # #
# # # # # # # # # # # # # # #
# # # # # ## # # # # # # # #
###### ####### # # ####### # ####### ###### ### #
################################################################################
# Detect to make sure the entire script is avilable, fail if the script is missing contents
if [ "$(tail -n 1 "${0}" | head -n 1 | cut -c 1-7)" != "exit \$?" ] ; then
echo "FATAL ERROR: Script is incomplete, please redownload"
exit 1
fi
# Trap the keyboard interrupt (Ctrl + C)
trap xshok_control_c SIGINT
################################################################################
# HELPER FUNCTIONS
################################################################################
# Support user config settings for applying file and directory access permissions.
function perms() {
if [ -n "${clam_user}" ] && [ -n "${clam_group}" ] ; then
"${@:-}"
fi
}
# Prompt a user if they should complete an action with Y or N
# Usage: xshok_prompt_confirm
# if xshok_prompt_confirm ; then
# xshok_prompt_confirm && echo "accepted"
# xshok_prompt_confirm && echo "yes" || echo "no"
# shellcheck disable=SC2120
function xshok_prompt_confirm() { # optional_message
message="${1:-Are you sure?}"
while true; do
read -r -p "${message} [y/N]" response < /dev/tty
case "${response}" in
[yY]) return 0 ;;
[nN]) return 1 ;;
*) printf " \\033[31m %s \\n\\033[0m" "invalid input"
esac
done
}
# Create a pid file
function xshok_create_pid_file() { # pid.file
if [ "${1}" ] ; then
pidfile="${1}"
if ! echo $$ > "${pidfile}" ; then
xshok_pretty_echo_and_log "ERROR: Could not create PID file: ${pidfile}"
exit 1
fi
else
xshok_pretty_echo_and_log "ERROR: Missing value for option"
exit 1
fi
}
# Intercept ctrl+c and calls the cleanup function
function xshok_control_c() {
echo
xshok_pretty_echo_and_log "---------------| Exiting ... Please wait |---------------" "-"
xshok_cleanup
exit $?
}
# Cleanup function
function xshok_cleanup() {
# Wait for all processes to end
wait
xshok_pretty_echo_and_log " Powered By https://eXtremeSHOK.com " "#"
return $?
}
# Check if the current running user is the root user, otherwise return false
function xshok_is_root() {
if [ "$(uname -s)" == "SunOS" ] ; then
id_bin="/usr/xpg4/bin/id"
else
id_bin="$(command -v id 2> /dev/null)"
fi
if [ "$($id_bin -u)" == 0 ] ; then
return 0
else
return 1 # Not root
fi
}
# Check if its a file, otherwise return false
function xshok_is_file() { # filepath
filepath="${1}"
if [ -f "${filepath}" ] ; then
return 0 ;
else
return 1 ; # Not a file
fi
}
# Check if filepath is a subdir, otherwise return false
# Usage: xshok_is_subdir "filepath"
# xshok_is_subdir "/root/" - false
# xshok_is_subdir "/usr/local/etc" && echo "yes" - yes
function xshok_is_subdir() { # filepath
shopt -s extglob; filepath="${filepath%%+(/)}"
if [ -d "$filepath" ] ; then
res="${filepath//[^\/]}"
if [ "${#res}" -gt 1 ] ; then
return 0 ;
else
return 1 ; # Not a subdir
fi
else
return 1 ; # Not a dir
fi
}
# Create a dir and set the ownership
function xshok_mkdir_ownership() { # path
if [ "${1}" ] ; then
if ! mkdir -p "${1}" 2>/dev/null ; then
xshok_pretty_echo_and_log "ERROR: Could not create directory: ${1}"
exit 1
fi
perms chown -f "${clam_user}:${clam_group}" "${1}" > /dev/null 2>&1
else
xshok_pretty_echo_and_log "ERROR: Missing value for option"
exit 1
fi
}
# Check if a user and group exists on the system otherwise return false
# Usage:
# xshok_is_subdir "username" && echo "user found" || echo "no"
# xshok_is_subdir "username" "groupname" && echo "user and group found" || echo "no"
function xshok_user_group_exists() { # username groupname
if [ "$(uname -s)" == "SunOS" ] ; then
id_bin="/usr/xpg4/bin/id"
else
id_bin="$(command -v id 2> /dev/null)"
fi
if [ "${2}" ] ; then
if [ "$(uname -s)" == "Darwin" ] ; then
#use ruby, as this is the best way. Ruby is always avilable as brew uses ruby
ruby -e 'require "etc"; puts Etc::getgrnam("_clamav").gid' > /dev/null 2>&1
ret="$?"
else
getent_bin="$(command -v getent 2> /dev/null)"
$getent_bin group "${2}" >/dev/null 2>&1
ret="$?"
fi
fi
if [ "${1}" ] ; then
if $id_bin -u "${1}" > /dev/null 2>&1 ; then
if [ "${2}" ] ; then
if [ "$ret" -eq 0 ] ; then
return 0 ; # User and group exists
else
return 1 ; # Group does NOT exist
fi
else
return 0 ; # User exists
fi
else
return 1 ; # User does NOT exist
fi
else
xshok_pretty_echo_and_log "ERROR: Missing value for option"
exit 1
fi
}
# Handle comments with/out borders and logging.
# Usage:
# pretty_echo_and_log "one"
# one
# pretty_echo_and_log "two" "-"
# ---
# two
# ---
# pretty_echo_and_log "three" "=" "8"
# ========
# three
# ========
# pretty_echo_and_log "" "/\" "7"
# /\/\/\/\/\/\
# type: e = error, w= warning, a = alert, n = notice
# will auto detect using the first word "error,warning,alert,notice"
# type e will make a == border
# type w will make a -- border
# type a will make a ** border
# type n will make a ++ border
function xshok_pretty_echo_and_log() { # "string" "repeating" "count" "type"
#detect if running under cron and silence
mystring="$1"
myrepeating="$2"
mycount="$3"
mytype="$4"
if [ "$comment_silence" != "yes" ] && [ "$force_verbose" != "yes" ]; then
if [ ! -t 1 ] ; then
comment_silence="yes"
fi
fi
# always show errors and alerts
if [ -z "$mytype" ] ; then
shopt -s nocasematch
if [[ "$mystring" =~ "ERROR:" ]] || [[ "$mystring" =~ "ERROR " ]] ; then
mytype="e"
elif [[ "$mystring" =~ "WARNING:" ]] || [[ "$mystring" =~ "WARNING " ]] ; then
mytype="w"
elif [[ "$mystring" =~ "ALERT:" ]] || [[ "$mystring" =~ "ALERT " ]] ; then
mytype="a"
elif [[ "$mystring" =~ "NOTICE:" ]] || [[ "$mystring" =~ "NOTICE " ]] ; then
mytype="n"
fi
fi
if [ "$mytype" == "e" ] || [ "$mytype" == "a" ] ; then
comment_silence="no"
fi
# Handle comments is not silenced or type
if [ "$comment_silence" != "yes" ] ; then
if [ -z "$myrepeating" ] ; then
if [ "$mytype" == "e" ] ; then
myrepeating="="
elif [ "$mytype" == "w" ] ; then
myrepeating="-"
elif [ "$mytype" == "a" ] ; then
myrepeating="*"
elif [ "$mytype" == "n" ] ; then
myrepeating="+"
fi
fi
if [ -z "$myrepeating" ] ; then
echo "${mystring}"
else
myvar=""
if [ -z "$mycount" ] ; then
mycount="${#mystring}"
fi
for (( n = 0; n < mycount; n++ )) ; do
myvar="${myvar}${myrepeating}"
done
if [ -n "${mystring}" ] ; then
echo -e "${myvar}\\n${1}\\n${myvar}"
else
echo -e "${myvar}"
fi
fi
fi
# Handle logging
if [ "$enable_log" == "yes" ] ; then
#filter ===, ---
mystring=${1//===}
mystring=${mystring//---}
if [ -n "$mystring" ] ; then
if [ -n "$log_pipe_cmd" ] ; then
echo "${mystring}" | $log_pipe_cmd
else
if [ ! -e "${log_file_path}/${log_file_name}" ] ; then
# xshok_mkdir_ownership "$log_file_path"
mkdir -p "$log_file_path"
touch "${log_file_path}/${log_file_name}" 2>/dev/null
perms chown -f "${clam_user}:${clam_group}" "${log_file_path}/${log_file_name}"
fi
if [ ! -w "${log_file_path}/${log_file_name}" ] ; then
echo "WARNING: Logging Disabled, as file not writable: ${log_file_path}/${log_file_name}"
enable_log="no"
else
echo "$(date "+%b %d %T")" "${mystring}" >> "${log_file_path}/${log_file_name}"
fi
fi
fi
fi
}
# Check if the $2 value is not null and does not start with -
function xshok_check_s2() { # value1 value2
if [ "${1}" ] ; then
if [[ "${1}" =~ ^-.* ]] ; then
xshok_pretty_echo_and_log "ERROR: Missing value for option or value begins with -"
exit 1
fi
else
xshok_pretty_echo_and_log "ERROR: Missing value for option"
exit 1
fi
}
# Time remaining information function
function xshok_draw_time_remaining() { #time_remaining #update_hours #name
if [ "${1}" ] && [ "${2}" ] ; then
time_remaining="${1}"
hours_left="$((time_remaining / 3600))"
minutes_left="$((time_remaining % 3600 / 60))"
xshok_pretty_echo_and_log "${2} hours have not yet elapsed since the last ${3} update check"
xshok_pretty_echo_and_log "No update check was performed at this time" "-"
xshok_pretty_echo_and_log "Next check will be performed in approximately ${hours_left} hour(s), ${minutes_left} minute(s)"
fi
}
# Download function
function xshok_file_download() { #outputfile #url #notimestamp
if [ "$downloader_debug" == "yes" ] ; then
xshok_pretty_echo_and_log "url: ${2} >> outputfile: ${1} | ${3}"
fi
if [ "${1}" ] && [ "${2}" ] ; then
if [ -n "$curl_bin" ] ; then
if [ -f "${1}" ] ; then
# shellcheck disable=SC2086
$curl_bin --fail --compressed $curl_proxy $curl_insecure $curl_output_level --connect-timeout "${downloader_connect_timeout}" --remote-time --location --retry "${downloader_tries}" --max-time "${downloader_max_time}" --time-cond "${1}" --output "${1}" "${2}" 2>&11
result=$?
else
# shellcheck disable=SC2086
$curl_bin --fail --compressed $curl_proxy $curl_insecure $curl_output_level --connect-timeout "${downloader_connect_timeout}" --remote-time --location --retry "${downloader_tries}" --max-time "${downloader_max_time}" --output "${1}" "${2}" 2>&11
result=$?
fi
else
if [ ! "${3}" ] ; then
# the following is required because wget, cannot do --timestamping and --output-document together
this_dir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
output_file="$1"
url="$2"
output_dir="${output_file%/*}"
output_file="${output_file##*/}"
url_file="${url##*/}"
wget_output_link=""
cd "${output_dir}" || exit
if [ "$output_file" != "$url_file" ] ; then
if [ ! -f "$url_file" ] ; then
if [ ! -f "$output_file" ] ; then
touch "$output_file"
fi
ln -s "$output_file" "$url_file"
wget_output_link="$url_file"
fi
fi
# shellcheck disable=SC2086
$wget_bin $wget_compression $wget_proxy $wget_insecure $wget_output_level --connect-timeout="${downloader_connect_timeout}" --random-wait --tries="${downloader_tries}" --timeout="${downloader_max_time}" --timestamping "${2}" 2>&12
result=$?
if [ -z "$wget_output_link" ] ; then
if [ -L "$wget_output_link" ] ; then
rm -f "$wget_output_link"
fi
fi
cd "$this_dir" || exit
else
# shellcheck disable=SC2086
$wget_bin $wget_compression $wget_proxy $wget_insecure $wget_output_level --connect-timeout="${downloader_connect_timeout}" --random-wait --tries="${downloader_tries}" --timeout="${downloader_max_time}" --output-document="${1}" "${2}" 2>&12
result=$?
fi
fi
return $result
fi
}
# Handle list of database files
function clamav_files() {
echo "${clam_dbs}/${db}" >> "${current_tmp}"
if [ "$keep_db_backup" == "yes" ] ; then
echo "${clam_dbs}/${db}-bak" >> "${current_tmp}"
fi
}
# Manage the databases and allow multi-dimensions as well as global overrides
# Since the datbases are basically a multi-dimentional associative arrays in bash
# ratings: LOW | MEDIUM | HIGH | REQUIRED | LOWONLY | MEDIUMONLY | LOWMEDIUMONLY | DISABLED
function xshok_database() { # rating database_array
# Assign
current_rating="${1}"
declare -a current_dbs=( "${@:2}" )
# Zero
declare -a new_dbs=( )
if [ -n "${current_dbs[0]}" ] ; then
if [ ${#current_dbs} -ge 1 ] ; then
for db_name in "${current_dbs[@]}" ; do
# Checks
if [ "$enable_yararules" == "no" ] ; then # YARA rules are disabled
if [[ "$db_name" == *".yar"* ]] ; then # If it's the value you want to delete
continue # Skip to the next value
fi
fi
if [ -z "$current_rating" ] ; then
new_dbs+=( "$db_name" )
else
if [[ ! "$db_name" = *"|"* ]] ; then # This old format
new_dbs+=( "$db_name" )
else
db_name_rating="${db_name#*|}"
db_name="${db_name%|*}"
if [ "$db_name_rating" != "DISABLED" ] ; then
if [ "$db_name_rating" == "$current_rating" ] ; then
new_dbs+=( "$db_name" )
elif [ "$db_name_rating" == "REQUIRED" ] ; then
new_dbs+=( "$db_name" )
elif [ "$current_rating" == "LOW" ] ; then
if [ "$db_name_rating" == "LOWONLY" ] || [ "$db_name_rating" == "LOW" ] || [ "$db_name_rating" == "LOWMEDIUMONLY" ] ; then
new_dbs+=( "$db_name" )
fi
elif [ "$current_rating" == "MEDIUM" ] ; then
if [ "$db_name_rating" == "MEDIUMONLY" ] || [ "$db_name_rating" == "MEDIUM" ] || [ "$db_name_rating" == "LOW" ] || [ "$db_name_rating" == "LOWMEDIUMONLY" ] ; then
new_dbs+=( "$db_name" )
fi
elif [ "$current_rating" == "HIGH" ] ; then
if [ "$db_name_rating" == "HIGH" ] || [ "$db_name_rating" == "MEDIUM" ] || [ "$db_name_rating" == "LOW" ]; then
new_dbs+=( "$db_name" )
fi
fi
fi
fi
fi
done
fi
fi
echo "${new_dbs[@]}" | xargs # Remove extra whitespace
}
# Manage the databases to be removed and allow multi-dimensions as well as global overrides
# Since the datbases are basically a multi-dimentional associative arrays in bash
# ratings: LOW | MEDIUM | HIGH | REQUIRED | LOWONLY | MEDIUMONLY | LOWMEDIUMONLY | DISABLED
function xshok_remove_database() { # rating database_array
# Assign
current_rating="${1}"
declare -a current_dbs=( "${@:2}" )
# Zero
declare -a new_dbs=( )
if [ ${#current_dbs} -ge 1 ] ; then
for db_name in "${current_dbs[@]}" ; do
db_name_rating="${db_name#*|}"
db_name="${db_name%|*}"
removed="no"
# Checks
if [ "$current_rating" == "DISABLED" ] ; then
new_dbs+=( "$db_name" )
removed="yes"
elif [ "$current_rating" == "HIGH" ] ; then
if [ "$db_name_rating" == "LOWONLY" ] || [ "$db_name_rating" == "LOWMEDIUMONLY" ] ||[ "$db_name_rating" == "MEDIUMONLY" ] ; then
new_dbs+=( "$db_name" )
removed="yes"
fi
elif [ "$current_rating" == "MEDIUM" ] ; then
if [ "$db_name_rating" == "HIGH" ] || [ "$db_name_rating" == "LOWONLY" ] ; then
new_dbs+=( "$db_name" )
removed="yes"
fi
elif [ "$current_rating" == "LOW" ] ; then
if [ "$db_name_rating" == "MEDIUMONLY" ] || [ "$db_name_rating" == "MEDIUM" ] || [ "$db_name_rating" == "HIGH" ]; then
new_dbs+=( "$db_name" )
removed="yes"
fi
fi
if [ "$removed" == "no" ] ; then # not already removed, process futher
if [ "$enable_yararules" == "no" ] && [[ "$db_name" == *".yar"* ]] ; then # YARA rules are disabled AND it's the value you want to delete
new_dbs+=( "$db_name" )
fi
fi
done
fi
echo "${new_dbs[@]}" | xargs # Remove extra whitespace
}
################################################################################
# ADDITIONAL PROGRAM FUNCTIONS
################################################################################
# Generates a man config and installs it
function install_man() {
if [ -n "$pkg_mgr" ] || [ -n "$pkg_rm" ] ; then
xshok_pretty_echo_and_log "This script (clamav-unofficial-sigs) was installed on the system via ${pkg_mgr}"
exit 1
fi
xshok_pretty_echo_and_log ""
xshok_pretty_echo_and_log "Generating man file for install...."
# Use defined varibles or attempt to use default varibles
if [ ! -e "${man_dir}/${man_filename}" ] ; then
mkdir -p "$man_dir"
touch "${man_dir}/${man_filename}" 2>/dev/null
fi
if [ ! -w "${man_dir}/${man_filename}" ] ; then
xshok_pretty_echo_and_log "ERROR: man install aborted, as file not writable: ${man_dir}/${man_filename}"
else
BOLD="\\fB"
#REV=""
NORM="\\fR"
manresult="$(help_and_usage "man")"
# Our template..
cat << EOF > "${man_dir}/${man_filename}"
.\\" Manual page for eXtremeSHOK.com ClamAV Unofficial Signature Updater
.TH clamav-unofficial-sigs 8 "${script_version_date}" "Version: ${script_version}" "SCRIPT COMMANDS"
.SH NAME
clamav-unofficial-sigs \\- Download, test, and install third-party ClamAV signature databases.
.SH SYNOPSIS
.B clamav-unofficial-sigs
.RI [ options ]
.SH DESCRIPTION
\\fBclamav-unofficial-sigs\\fP provides a simple way to download, test, and update third-party signature databases provided by Sanesecurity, FOXHOLE, OITC, BOFHLAND, CRDF, Porcupine, Securiteinfo, MalwarePatrol, Yara-Rules Project, etc. It will also generate and install cron, logrotate, and man files.
.SH UPDATES
Script updates can be found at: \\fBhttps://github.com/extremeshok/clamav-unofficial-sigs\\fP
.SH OPTIONS
This script follows the standard GNU command line syntax.
.LP
$manresult
.SH SEE ALSO
.BR clamd (8),
.BR clamscan (1)
.SH COPYRIGHT
Copyright (c) Adrian Jon Kriel :: [email protected]
.TP
You are free to use, modify and distribute, however you may not remove this notice.
.SH LICENSE
BSD (Berkeley Software Distribution)
.SH BUGS
Report bugs to \\fBhttps://github.com/extremeshok/clamav-unofficial-sigs\\fP
.SH AUTHOR
Adrian Jon Kriel :: [email protected]
Originially based on Script provide by Bill Landry
EOF
fi
xshok_pretty_echo_and_log "Completed: man installed, as file: ${man_dir}/${man_filename}"
}
# Generate a logrotate config and install it
function install_logrotate() {
if [ -n "$pkg_mgr" ] || [ -n "$pkg_rm" ] ; then
xshok_pretty_echo_and_log "This script (clamav-unofficial-sigs) was installed on the system via ${pkg_mgr}"
exit 1
fi
xshok_pretty_echo_and_log ""
xshok_pretty_echo_and_log "Generating logrotate file for install...."
# Use defined varibles or attempt to use default varibles
if [ -z "$logrotate_user" ] ; then
logrotate_user="${clam_user}";
fi
if [ -z "$logrotate_group" ] ; then
logrotate_group="${clam_group}";
fi
if [ -z "$logrotate_log_file_full_path" ] ; then
logrotate_log_file_full_path="${log_file_path}/${log_file_name}"
fi
if [ ! -e "${logrotate_dir}/${logrotate_filename}" ] ; then
mkdir -p "$logrotate_dir"
touch "${logrotate_dir}/${logrotate_filename}" 2>/dev/null
fi
if [ ! -w "${logrotate_dir}/${logrotate_filename}" ] ; then
xshok_pretty_echo_and_log "ERROR: logrotate install aborted, as file not writable: ${logrotate_dir}/${logrotate_filename}"
else
# Our template..
cat << EOF > "${logrotate_dir}/${logrotate_filename}"
# https://eXtremeSHOK.com ######################################################
# This file contains the logrotate settings for clamav-unofficial-sigs.sh
###################
# This is property of eXtremeSHOK.com
# You are free to use, modify and distribute, however you may not remove this notice.
# Copyright (c) Adrian Jon Kriel :: [email protected]
##################
#
# Script updates can be found at: https://github.com/extremeshok/clamav-unofficial-sigs
#
# Originially based on:
# Script provide by Bill Landry ([email protected]).
#
# License: BSD (Berkeley Software Distribution)
#
##################
# Automatically Generated: $(date)
##################
#
# This logrotate file will rotate the logs generated by the clamav-unofficial-sigs.sh
#
# To Adjust the logrotate values, edit your configs and run
# bash clamav-unofficial-sigs.sh --install-logrotate to generate a new file.
$logrotate_log_file_full_path {
weekly
rotate 4
missingok
notifempty
compress
create 0640 ${logrotate_user} ${logrotate_group}
}
EOF
fi
xshok_pretty_echo_and_log "Completed: logrotate installed, as file: ${logrotate_dir}/${logrotate_filename}"
}
# Generate a cron config and install it
function install_cron() {
if [ -n "$pkg_mgr" ] || [ -n "$pkg_rm" ] ; then
xshok_pretty_echo_and_log "This script (clamav-unofficial-sigs) was installed on the system via {$pkg_mgr}"
exit 1
fi
xshok_pretty_echo_and_log ""
xshok_pretty_echo_and_log "Generating cron file for install...."
# Use defined varibles or attempt to use default varibles
if [ -z "$cron_minute" ] ; then
cron_minute="$(( ( RANDOM % 59 ) + 1 ))"
fi
if [ -z "$cron_user" ] ; then
cron_user="${clam_user}";
fi
if [ -z "$cron_bash" ] ; then
cron_bash="$(command -v bash 2> /dev/null)"
fi
if [ -z "$cron_script_full_path" ] ; then
cron_script_full_path="$this_script_full_path"
fi
if [ "$cron_sudo" == "yes" ] ; then
cron_sudo="sudo -u"
fi
if [ ! -e "${cron_dir}/${cron_filename}" ] ; then
mkdir -p "$cron_dir"
touch "${cron_dir}/${cron_filename}" 2>/dev/null
fi
if [ ! -w "${cron_dir}/${cron_filename}" ] ; then
xshok_pretty_echo_and_log "ERROR: cron install aborted, as file not writable: ${cron_dir}/${cron_filename}"
else
# Our template..
cat << EOF > "${cron_dir}/${cron_filename}"
# https://eXtremeSHOK.com ######################################################
# This file contains the cron settings for clamav-unofficial-sigs.sh
###################
# This is property of eXtremeSHOK.com
# You are free to use, modify and distribute, however you may not remove this notice.
# Copyright (c) Adrian Jon Kriel :: [email protected]
##################
#
# Script updates can be found at: https://github.com/extremeshok/clamav-unofficial-sigs
#
# Originially based on:
# Script provide by Bill Landry ([email protected]).
#
# License: BSD (Berkeley Software Distribution)
#
##################
# Automatically Generated: $(date)
##################
#
# This cron file will execute the clamav-unofficial-sigs.sh script that
# currently supports updating third-party signature databases provided
# by Sanesecurity, SecuriteInfo, MalwarePatrol, OITC, etc.
#
# The script is set to run hourly, at a random minute past the hour, and the
# script itself is set to randomize the actual execution time between
# 60 - 600 seconds. To Adjust the cron values, edit your configs and run
# bash clamav-unofficial-sigs.sh --install-cron to generate a new file.
# Uncomment to enable emails to the root user
#MAILTO=root
$cron_minute * * * * ${cron_sudo} ${cron_user} [ -x ${cron_script_full_path} ] && ${cron_bash} ${cron_script_full_path}
# https://eXtremeSHOK.com ######################################################
EOF
fi
xshok_pretty_echo_and_log "Completed: cron installed, as file: ${cron_dir}/${cron_filename}"
}
# Auto upgrade the master.conf and the
function xshok_upgrade() {
if [ "$allow_upgrades" == "no" ] ; then
xshok_pretty_echo_and_log "ERROR: --upgrade has been disabled, allow_upgrades=no"
exit 1
fi
if ! xshok_is_root ; then
xshok_pretty_echo_and_log "ERROR: Only root can run the upgrade"
exit 1
fi
xshok_pretty_echo_and_log "Checking for updates ..."
found_upgrade="no"
if [ -n "$curl_bin" ] ; then
# shellcheck disable=SC2086
latest_version="$($curl_bin --compressed $curl_proxy $curl_insecure $curl_output_level --connect-timeout "${downloader_connect_timeout}" --remote-time --location --retry "${downloader_tries}" --max-time "${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh" 2>&11 | $grep_bin "^script_version=" | head -n1 | cut -d '"' -f 2)"
# shellcheck disable=SC2086
latest_config_version="$($curl_bin --compressed $curl_proxy $curl_insecure $curl_output_level --connect-timeout "${downloader_connect_timeout}" --remote-time --location --retry "${downloader_tries}" --max-time "${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf" 2>&11 | $grep_bin "^config_version=" | head -n1 | cut -d '"' -f 2)"
else
# shellcheck disable=SC2086
latest_version="$($wget_bin $wget_compression $wget_proxy $wget_insecure $wget_output_level --connect-timeout="${downloader_connect_timeout}" --random-wait --tries="${downloader_tries}" --timeout="${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh" -O - 2>&12 | $grep_bin "^script_version=" | head -n1 | cut -d '"' -f 2)"
# shellcheck disable=SC2086
latest_config_version="$($wget_bin $wget_compression $wget_proxy $wget_insecure $wget_output_level --connect-timeout="${downloader_connect_timeout}" --random-wait --tries="${downloader_tries}" --timeout="${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf" -O - 2>&12 | $grep_bin "^config_version=" | head -n1 | cut -d '"' -f 2)"
fi
# config_dir/master.conf
if [ "$latest_config_version" ] ; then
# shellcheck disable=SC2183,SC2086
if [ "$(printf "%02d%02d%02d%02d" ${latest_config_version//./ })" -gt "$(printf "%02d%02d%02d%02d" ${config_version//./ })" ] ; then
found_upgrade="yes"
xshok_pretty_echo_and_log "ALERT: Upgrading config from v${config_version} to v${latest_config_version}"
if [ -w "${config_dir}/master.conf" ] && [ -f "${config_dir}/master.conf" ] ; then
echo "Downloading https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf"
xshok_file_download "${work_dir}/master.conf.tmp" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf" "notimestamp"
ret="$?"
if [ "$ret" -ne 0 ] ; then
xshok_pretty_echo_and_log "ERROR: Could not download https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf"
exit 1
fi
if ! $grep_bin -m 1 "config_version" "${work_dir}/master.conf.tmp" > /dev/null 2>&1 ; then
echo "ERROR: Downloaded master.conf is incomplete, please re-run"
exit 1
fi
# Copy over permissions from old version
OCTAL_MODE="$(stat -c "%a" "${config_dir}/master.conf" 2> /dev/null)"
if [ -z "$OCTAL_MODE" ]; then
OCTAL_MODE="$(stat -f '%p' "${config_dir}/master.conf")"
fi
xshok_pretty_echo_and_log "Running update process"
if ! mv -f "${work_dir}/master.conf.tmp" "${config_dir}/master.conf" ; then
xshok_pretty_echo_and_log "ERROR: failed moving ${work_dir}/master.conf.tmp to ${config_dir}/master.conf"
exit 1
fi
if ! chmod "$OCTAL_MODE" "${config_dir}/master.conf" ; then
xshok_pretty_echo_and_log "ERROR: unable to set permissions on ${config_dir}/master.conf"
exit 1
fi
xshok_pretty_echo_and_log "Completed"
else
xshok_pretty_echo_and_log "ERROR: ${config_dir}/master.conf is not a file or is not writable"
exit 1
fi
fi
fi
if [ "$latest_version" ] ; then
# shellcheck disable=SC2183,SC2086
if [ "$(printf "%02d%02d%02d%02d" ${latest_version//./ })" -gt "$(printf "%02d%02d%02d%02d" ${script_version//./ })" ] ; then
found_upgrade="yes"
xshok_pretty_echo_and_log "ALERT: Upgrading script from v${script_version} to v${latest_version}"
if [ -w "${config_dir}/master.conf" ] && [ -f "${config_dir}/master.conf" ] ; then
echo "Downloading https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh"
xshok_file_download "${work_dir}/clamav-unofficial-sigs.sh.tmp" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh" "notimestamp"
ret=$?
if [ "$ret" -ne 0 ] ; then
xshok_pretty_echo_and_log "ERROR: Could not download https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh"
exit 1
fi
# Detect to make sure the entire script is avilable, fail if the script is missing contents
if [ "$(tail -n 1 "${work_dir}/clamav-unofficial-sigs.sh.tmp" | head -n 1 | cut -c 1-7)" != "exit \$?" ] ; then
echo "ERROR: Downloaded clamav-unofficial-sigs.sh is incomplete, please re-run"
exit 1
fi
# Copy over permissions from old version
OCTAL_MODE="$(stat -c "%a" "${this_script_full_path}" 2> /dev/null)"
if [ -z "$OCTAL_MODE" ]; then
OCTAL_MODE="$(stat -f '%p' "${this_script_full_path}")"
fi
xshok_pretty_echo_and_log "Inserting update process..."
# Generate the update script
cat > "${work_dir}/xshok_update_script.sh" << EOF
#!/usr/bin/env bash
echo "Running update process"
# Overwrite old file with new
if ! mv -f "${work_dir}/clamav-unofficial-sigs.sh.tmp" "${this_script_full_path}" ; then
echo "ERROR: failed moving ${work_dir}/clamav-unofficial-sigs.sh.tmp to ${this_script_full_path}"
rm -f \$0
exit 1
fi
if ! chmod "$OCTAL_MODE" "${this_script_full_path}" ; then
echo "ERROR: unable to set permissions on ${this_script_full_path}"
rm -f \$0
exit 1
fi
echo "Completed"
# echo "---------------------"
# echo "Optional, run as root: "
# echo "clamav-unofficial-sigs.sh --install-all"
echo "---------------------"
echo "Run once as root: "
echo "clamav-unofficial-sigs.sh --force"
#remove the tmp script before exit
rm -f \$0
EOF
# Replaced with $0, so code will update and then call itself with the same parameters it had
#exec "${0}" "$@"
bash_bin="$(command -v bash 2> /dev/null)"
exec "$bash_bin" "${work_dir}/xshok_update_script.sh"
echo "Running once as root"
else
xshok_pretty_echo_and_log "ERROR: ${config_dir}/master.conf is not a file or is not writable"
exit 1
fi
fi
fi
if [ "$found_upgrade" == "no" ] ; then
xshok_pretty_echo_and_log "No updates available"
fi
}
# Decode a third-party signature either by signature name
function decode_third_party_signature_by_signature_name() {
xshok_pretty_echo_and_log ""
xshok_pretty_echo_and_log "Input a third-party signature name to decode (e.g: Sanesecurity.Junk.15248) or"
xshok_pretty_echo_and_log "a hexadecimal encoded data string and press enter:"
read -r input
# Remove quotes and .UNOFFICIAL from the whitelist input string
input="$(echo "${input}" | tr -d "'" | tr -d '"' | tr -d '`')"
input=${input/\.UNOFFICIAL/}
if echo "${input}" | $grep_bin "\\." > /dev/null ; then
cd "$clam_dbs" || exit
sig="$($grep_bin "${input}:" ./*.ndb)"
if [ -n "$sig" ] ; then
db_file="${sig%:*}"
xshok_pretty_echo_and_log "${input} found in: ${db_file}"
xshok_pretty_echo_and_log "${input} signature decodes to:"
xshok_pretty_echo_and_log "$sig" | cut -d ":" -f 5 | perl -pe 's/([a-fA-F0-9]{2})|(\{[^}]*\}|\([^)]*\))/defined $2 ? $2 : chr(hex $1)/eg'
else
xshok_pretty_echo_and_log "Signature ${input} could not be found."
xshok_pretty_echo_and_log "This script will only decode ClamAV 'UNOFFICIAL' third-Party,"
xshok_pretty_echo_and_log "non-image based, signatures as found in the *.ndb databases."
fi
else
xshok_pretty_echo_and_log "Here is the decoded hexadecimal input string:"
echo "${input}" | perl -pe 's/([a-fA-F0-9]{2})|(\{[^}]*\}|\([^)]*\))/defined $2 ? $2 : chr(hex $1)/eg'
fi
}
# Hexadecimal encode an entire input string
function hexadecimal_encode_entire_input_string() {
xshok_pretty_echo_and_log ""
xshok_pretty_echo_and_log "Input the data string that you want to hexadecimal encode and then press enter. Do not include"
xshok_pretty_echo_and_log "any quotes around the string unless you want them included in the hexadecimal encoded output:"
read -r input
xshok_pretty_echo_and_log "Here is the hexadecimal encoded input string:"
echo "${input}" | perl -pe 's/(.)/sprintf("%02lx", ord $1)/eg'
}
# Hexadecimal encode a formatted input string
function hexadecimal_encode_formatted_input_string() {
xshok_pretty_echo_and_log ""
xshok_pretty_echo_and_log "Input a formated data string containing spacing fields '{}, (), *' that you want to hexadecimal"
xshok_pretty_echo_and_log "encode, without encoding the spacing fields, and then press enter. Do not include any quotes"
xshok_pretty_echo_and_log "around the string unless you want them included in the hexadecimal encoded output:"
read -r input
xshok_pretty_echo_and_log "Here is the hexadecimal encoded input string:"
echo "${input}" | perl -pe 's/(\{[^}]*\}|\([^)]*\)|\*)|(.)/defined $1 ? $1 : sprintf("%02lx", ord $2)/eg'
}
# GPG verify a specific Sanesecurity database file
function gpg_verify_specific_sanesecurity_database_file() { # databasefile
xshok_pretty_echo_and_log ""
if [ "$enable_gpg" == "no" ] ; then
xshok_pretty_echo_and_log "GnuPG / signature verification disabled" "-"
else
if [ "${1}" ] ; then
db_file="$(echo "${1}" | awk -F "/" '{print $NF}')"
if [ -r "${work_dir_sanesecurity}/${db_file}" ] ; then
xshok_pretty_echo_and_log "GPG signature testing database file: ${work_dir_sanesecurity}/${db_file}"
if [ -r "${work_dir_sanesecurity}/${db_file}.sig" ] ; then
if ! "$gpg_bin" -q --trust-model always --no-default-keyring --homedir "${work_dir_gpg}" --keyring "${work_dir_gpg}/ss-keyring.gpg" --verify "${work_dir_sanesecurity}/${db_file}.sig" "${work_dir_sanesecurity}/${db_file}" ; then
if "$gpg_bin" -q --always-trust --no-default-keyring --homedir "${work_dir_gpg}" --keyring "${work_dir_gpg}/ss-keyring.gpg" --verify "${work_dir_sanesecurity}/${db_file}.sig" "${work_dir_sanesecurity}/${db_file}" ; then
exit 0
else
exit 1
fi
else
exit 0
fi
else
xshok_pretty_echo_and_log "Signature ${db_file}.sig cannot be found."
fi
else
xshok_pretty_echo_and_log "File ${db_file} cannot be found or is not a Sanesecurity database file."
xshok_pretty_echo_and_log "Only the following Sanesecurity and OITC databases can be GPG signature tested:"
ls --ignore "*.sig" --ignore "*.md5" --ignore "*.ign2" --ignore "*.fp" "${work_dir_sanesecurity}"
fi
else
xshok_pretty_echo_and_log "ERROR: Missing value for option"
exit 1
fi
exit 1
fi
}
# Output system and configuration information
function output_system_configuration_information() {
xshok_pretty_echo_and_log ""
xshok_pretty_echo_and_log "*** SCRIPT INFORMATION ***"
xshok_pretty_echo_and_log "${this_script_name} ${script_version} (${script_version_date})"
xshok_pretty_echo_and_log "Master.conf Version: ${config_version}"
xshok_pretty_echo_and_log "Minimum required config: ${minimum_required_config_version}"
xshok_pretty_echo_and_log "*** SYSTEM INFORMATION ***"
$uname_bin -a
xshok_pretty_echo_and_log "*** CLAMSCAN LOCATION & VERSION ***"
xshok_pretty_echo_and_log "${clamscan_bin}"
$clamscan_bin --version | head -1
xshok_pretty_echo_and_log "*** RSYNC LOCATION & VERSION ***"
xshok_pretty_echo_and_log "${rsync_bin}"
$rsync_bin --version | head -1
if [ -n "$curl_bin" ] ; then
xshok_pretty_echo_and_log "*** CURL LOCATION & VERSION ***"
xshok_pretty_echo_and_log "${curl_bin}"
$curl_bin --version | head -1
else
xshok_pretty_echo_and_log "*** WGET LOCATION & VERSION ***"
xshok_pretty_echo_and_log "${wget_bin}"
$wget_bin --version | head -1
fi
if [ "$enable_gpg" == "yes" ] ; then
xshok_pretty_echo_and_log "*** GPG LOCATION & VERSION ***"
xshok_pretty_echo_and_log "${gpg_bin}"
$gpg_bin --version | head -1
fi
xshok_pretty_echo_and_log "*** DIRECTORY INFORMATION ***"
xshok_pretty_echo_and_log "Working Directory: ${work_dir}"
xshok_pretty_echo_and_log "Clam Database Directory: ${clam_dbs}"
if [ "$custom_config" != "no" ] ; then
if [ -d "$custom_config" ] ; then
# Assign the custom config dir and remove trailing / (removes / and //)
xshok_pretty_echo_and_log "Custom Configuration Directory: ${custom_config}"
else
xshok_pretty_echo_and_log "Custom Configuration File: ${custom_config}"
fi
else
xshok_pretty_echo_and_log "Configuration Directory: ${config_dir}"
fi
xshok_pretty_echo_and_log ""
}
# Make a signature database from an ascii file
function make_signature_database_from_ascii_file() {
xshok_pretty_echo_and_log ""
echo "
The '-m' script flag provides a way to create a ClamAV hexadecimal signature database (*.ndb) file
from a list of data strings stored in a clear-text ascii file, with one data string entry per line.
- Hexadecimal encoding can be either 'full' or 'formatted' on a per line basis:
Full line encoding should be used if there are no formatted spacing entries [{}, (), *]
included on the line. Prefix unformatted lines with: '-:' (no quote marks).
Example:
-:This signature contains no formatted spacing fields
Encodes to:
54686973207369676e617475726520636f6e7461696e73206e6f20666f726d61747465642073706163696e67206669656c6473
Formatted line encoding should be used if there are user added spacing entries [{}, (), *]