]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: Add malware-test
authorEric Bollengier <eric@baculasystems.com>
Thu, 21 Apr 2022 15:51:59 +0000 (17:51 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
regress/scripts/malware.dump [new file with mode: 0644]
regress/tests/malware-test [new file with mode: 0755]

diff --git a/regress/scripts/malware.dump b/regress/scripts/malware.dump
new file mode 100644 (file)
index 0000000..19eeefc
--- /dev/null
@@ -0,0 +1,8 @@
+fd449524a57947b7ec3791ccf99ba724
+193b1f48fa36b2cad6b523b0e1b45d94
+d3b890d29142e152f98049b4da95a9b7
+1c41d0198adc92df0a83e60c27c76c78
+e758dfdd2f8decb547079e43a4ab8c79
+576fcef4e81db1632621052d33cde6d1
+1b53122352eb908d659a8f27cc23d3a2
+59fe49e18a0d7e34c341039b9e201a1b
diff --git a/regress/tests/malware-test b/regress/tests/malware-test
new file mode 100755 (executable)
index 0000000..edceb08
--- /dev/null
@@ -0,0 +1,155 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2000-2021 Kern Sibbald
+# Copyright (C) 2021-2022 Bacula Systems SA
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# Run a simple backup and test the malware features
+#
+TestName="malware-test"
+JobName=backup
+. scripts/functions
+
+scripts/cleanup
+scripts/copy-confs
+
+#
+# Zap out any schedule in default conf file so that
+#  it doesn't start during our test
+#
+outf="$tmp/sed_tmp"
+echo "s%  Schedule =%# Schedule =%g" >${outf}
+cp $scripts/bacula-dir.conf $tmp/1
+sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf
+
+change_jobname BackupClient1 $JobName
+start_test
+
+cat <<EOF >> $conf/bacula-dir.conf
+Job {
+  Name = VerifyData
+  Level = Data
+  Type = Verify
+  FileSet = "Full Set"
+  Storage = File1
+  Messages = Standard
+  Pool = File
+  Priority = 10
+  Client = zog8-fd
+}
+Job {
+  Name = VerifyVolCat
+  Level = VolumeToCatalog
+  Type = Verify
+  FileSet = "Full Set"
+  Storage = File1
+  Messages = Standard
+  Pool = File
+  Priority = 10
+  Client = zog8-fd
+}
+EOF
+
+$bperl -e "add_attribute('$conf/bacula-dir.conf', 'CheckMalware', 'yes', 'Job')"
+export REGRESS_MALWARE_URL=file:$tmp/malware.dump
+cat $cwd/scripts/malware.dump >  $tmp/malware.dump
+md5sum $cwd/build/po/fr.po | awk '{print $1}'   >> $tmp/malware.dump
+
+ts=`date +%s`
+ds=`expr $ts - 10000`
+d=`date --date="@$ds" +%m%d%H%M`
+
+ds2=`expr $ts - 90000`
+d2=`date --date="@$ds2" +%m%d%H%M`
+
+cat <<END_OF_DATA >$tmp/bconcmds
+@output /dev/null
+messages
+@$out $tmp/log1.out
+label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0
+run job=$JobName yes
+wait
+messages
+run job=$JobName level=full yes
+wait
+messages
+@exec "ls -l $working/malware-MD5.dat"
+@exec "touch -m -t '$d' $working/malware-MD5.dat"
+@exec "ls -l $working/malware-MD5.dat"
+run job=$JobName level=full yes
+wait
+messages
+@exec "ls -l $working/malware-MD5.dat"
+@exec "touch -m -t '$d2' $working/malware-MD5.dat"
+@exec "ls -l $working/malware-MD5.dat"
+run job=$JobName level=full yes
+wait
+messages
+@$out $tmp/log2.out
+run job=$JobName level=full comment="job with 0 files" yes
+wait
+messages
+@$out $tmp/log3.out
+run job=VerifyData jobid=1 yes
+wait
+messages
+run job=VerifyVolCat jobid=1 yes
+wait
+messages
+list files type=malware jobid=1
+@$out $tmp/log2.out
+sql
+select File.JobId, SourceJobId, Path.Path, Filename, Source from File JOIN Path USING (PathId) JOIN FileEvents USING (JobId, FileIndex);
+
+quit
+END_OF_DATA
+
+run_bacula
+
+$bperl -e "add_attribute('$conf/bacula-dir.conf', 'MalwareDatabaseCommand', '$tmp/get_malware_toto.ch', 'Director')"
+cp $bin/get_malware_abuse.ch $tmp/get_malware_toto.ch
+# We execute this command where the handler is located
+cp $bin/md5tobase64.py $tmp/
+
+cat <<END_OF_DATA >$tmp/bconcmds
+@output /dev/null
+reload
+messages
+@$out $tmp/log1.out
+run job=$JobName level=full yes
+wait
+messages
+sql
+select File.JobId, SourceJobId, Path.Path, Filename, Source from File JOIN Path USING (PathId) JOIN FileEvents USING (JobId, FileIndex) WHERE FileEvents.JobId = 6;
+
+END_OF_DATA
+
+rm -f $working/malware-MD5.dat
+
+run_bconsole
+
+$bperl -e "add_attribute('$conf/bacula-dir.conf', 'MalwareDatabaseCommand', 'get_malware_truc.ch', 'Director')"
+cp $bin/get_malware_abuse.ch $bin/get_malware_truc.ch
+
+cat <<END_OF_DATA >$tmp/bconcmds
+@output /dev/null
+reload
+messages
+@$out $tmp/log1.out
+run job=$JobName level=full yes
+wait
+messages
+sql
+select File.JobId, SourceJobId, Path.Path, Filename, Source from File JOIN Path USING (PathId) JOIN FileEvents USING (JobId, FileIndex) WHERE FileEvents.JobId = 7;
+
+END_OF_DATA
+
+rm -f $working/malware-MD5.dat
+
+# TODO: Need to check results
+
+run_bconsole
+check_for_zombie_jobs storage=File1
+stop_bacula
+
+end_test