From: Eric Bollengier Date: Thu, 21 Apr 2022 15:51:59 +0000 (+0200) Subject: regress: Add malware-test X-Git-Tag: Beta-15.0.0~468 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6896382d597743a8ec14d29f981a720df8beebdc;p=thirdparty%2Fbacula.git regress: Add malware-test --- diff --git a/regress/scripts/malware.dump b/regress/scripts/malware.dump new file mode 100644 index 000000000..19eeefcf6 --- /dev/null +++ b/regress/scripts/malware.dump @@ -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 index 000000000..edceb084e --- /dev/null +++ b/regress/tests/malware-test @@ -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 <> $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 <$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 <$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 <$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