Debian Codegraph @

manuals/en/main/antivirus.tex

raw
1 \section{Bacula Antivirus Verify Job Plugin}
2 \subsection{Distinction between Antivirus Plugin and Malware}
3
4 In an Antivirus Check, Bacula will transmit the files to the ClamAV Antivirus
5 Socket, which will perform the scan and report to Bacula if any viruses are
6 discovered. In the instance of \vref{MalwareDetection}, Bacula will retrieve
7 the Malware database signatures from https://abuse.ch/ and then do a file
8 verification with those signatures. If a Backup job finds malware in the backup
9 content, an error message is generated and the Job status is changed.
10
11 \subsection{Overview}
12
13 The Bacula Antivirus Plugin provides integration between the ClamAV Antivirus
14 daemon and Bacula verify jobs, allowing post-backup virus detection within
15 Bacula.
16
17 \subsection{ClamAV Installation}
18
19 ClamAV is an open source (GPLv2) anti-virus toolkit. It provides a flexible and
20 scalable multi-threaded daemon. For more information on ClamAV architecture,
21 best practices and options, please refer to https://docs.clamav.net/
22
23
24 \subsubsection{Debian / Ubuntu}
25
26 \subsubsection*{Installation}
27
28 Use the existing Debian packages:
29
30 \begin{bVerbatim}
31 sudo apt-get update
32 sudo apt-get install clamav clamav-daemon
33 \end{bVerbatim}
34
35 \subsubsection*{TCP Configuration}
36
37 The ClamAV 'clamd' daemon is configured with the clamav.conf file (located in /etc/clamav/).
38 By default, the ClamAV daemon listens on a Unix LocalSocket:
39
40 \begin{bVerbatim}
41 LocalSocket /var/run/clamav/clamd.ctl
42 FixStaleSocket true
43 LocalSocketGroup clamav
44 LocalSocketMode 666
45 \end{bVerbatim}
46
47 In order for Bacula to interact correctly with ClamAV, it is essential to
48 reconfigure the ClamAV daemon so it allows TCP connections instead.
49
50 On Debian you can do so automatically by running:
51
52 \begin{bVerbatim}
53 sudo dpkg-reconfigure clamav-daemon
54 \end{bVerbatim}
55
56 Answer "yes" to reconfigure automatically
57 Make sure to change the socket type to "TCP".
58 Choose the TCP port clamd will listen on (The default port 3310 will be assumed in the rest of the documentation).
59 Continue the reconfiguration according to your needs (press enter to keep the default settings)
60 At the end of the reconfiguration process, the ClamAV daemon restarts.
61 You can verify that the clamav.conf file now contains:
62
63 \begin{bVerbatim}
64 TCPSocket 3310
65 \end{bVerbatim}
66
67 Alternatively, you can reconfigure manually, by editing clamav.conf.
68 Replace:
69
70 \begin{bVerbatim}
71 LocalSocket /var/run/clamav/clamd.ctl
72 FixStaleSocket true
73 LocalSocketGroup clamav
74 LocalSocketMode 666
75 \end{bVerbatim}
76
77 with:
78
79 \begin{bVerbatim}
80 TCPSocket 3310
81 \end{bVerbatim}
82
83 and restart the ClamAV daemon:
84
85 \begin{bVerbatim}
86 sudo systemctl restart clamav-daemon
87 \end{bVerbatim}
88
89
90 \subsubsection{Fedora / Redhat / Centos}
91 \subsubsection*{Installation}
92
93 EPEL creates ClamAV packages for Fedora.
94 To enable the EPEL repository for CentOS:
95
96
97 \begin{bVerbatim}
98 sudo dnf install -y epel-release
99 \end{bVerbatim}
100
101 EPEL offers a selection of packages to install ClamAV:
102
103 \begin{bVerbatim}
104 clamd - The ClamAV Daemon
105 clamav - End-user tools for the ClamAV scanner
106 clamav-data - Virus signature data for the ClamAV scanner
107 clamav-devel - Header files and libraries for the ClamAV scanner
108 clamav-lib - Dynamic libraries for the ClamAV scanner
109 clamav-milter - Milter module for the ClamAV scanner
110 clamav-update - Auto-updater for the ClamAV scanner data-files
111 \end{bVerbatim}
112
113 Bacula minimally requires clamav, clamd, and clamav-update to run:
114
115
116 \begin{bVerbatim}
117 sudo dnf install -y clamav clamd clamav-update
118 \end{bVerbatim}
119
120 \subsubsection*{TCP Configuration}
121 The ClamAV daemon is configured with the clamav.conf file (located in /etc/clamav/).
122
123 Edit the configuration file:
124
125 \begin{bVerbatim}
126 sudo dnf install nano -y
127 sudo nano /etc/clamd.d/scan.conf
128 \end{bVerbatim}
129
130 Make sure the Example line is commented out:
131
132
133 \begin{bVerbatim}
134 #Example
135 \end{bVerbatim}
136
137 By default, the ClamAV daemon connects over Unix LocalSocket.
138 In order for Bacula to interact correctly with ClamAV, it is essential to reconfigure the ClamAV daemon so it allows TCP connections instead.
139 enable TCP connection instead by uncommenting the following line:
140
141 \begin{bVerbatim}
142 TCPSocket 3310
143 \end{bVerbatim}
144
145 Optionally, you can also restrain the TCP binding (by default the ClamAV daemon binds to INADDR\_ANY):
146
147 \begin{bVerbatim}
148 TCPAddr 127.0.0.1
149 \end{bVerbatim}
150
151 Once that’s done, you can run the virus definition database update:
152
153 \begin{bVerbatim}
154 sudo freshclam
155 \end{bVerbatim}
156
157 Lastly, start the clamd service and run it on boot:
158
159 \begin{bVerbatim}
160 sudo systemctl enable clamd@scan
161 sudo systemctl start clamd@scan
162 \end{bVerbatim}
163
164 \subsubsection{Bacula Antivirus Plugin Installation}
165
166 Installation of the Bacula Antivirus Plugin can be installed from community binary repository, or via the ./configure command line.
167
168 \subsection{Bacula Verify Job Configuration}
169
170 \subsubsection{Parameters}
171
172 The Bacula Antivirus Plugin accepts two parameters:
173
174 \begin{itemize}
175 \item \texttt{hostname} The binding address of the ClamAV daemon (specified in clamav.conf as TCPAddr). Can be any IP4 TCP address. Default is 'localhost'
176 \item \texttt{port} The ClamAV daemon port number (specified in clamav.conf as TCPSocket). Default port is 3310.
177 \end{itemize}
178
179 \subsubsection{Plugin Options}
180 Contrary to "classical" Bacula FD plugins, these parameters are configured in the Verify Job
181 as PluginOptions rather than a "Plugin =" in a FileSet.
182
183 There are three possible ways to instruct a Bacula Verify Job to run the antivirus plugin:
184
185 \begin{bVerbatim}
186 # Add a PluginOptions directive to the Verify Job configuration (recommended):
187
188 Job {
189 Name = Verify_and_AV_Scan
190 Type = Verify
191 Level = Data
192 Client = localhost-fd
193 FileSet = LinuxHome
194 Storage = File
195 Pool = Default
196 Messages = Standard
197 PluginOptions = "antivirus: hostname=127.0.0.1 port=3310" # <---- Add this line here
198 }
199
200 # Specify the ``pluginoptions`` as a parameter to the 'run' command in bconsole:
201
202 *run job=Verify_and_AV_Scan jobid=1 storage=File1 pluginoptions="antivirus: hostname=localhost port=3310"
203
204 # Dynamically modify the verify job within bconsole
205
206 *run job=Verify_and_AV_Scan jobid=1 storage=File1
207
208 JobName: Verify_and_AV_Scan
209 Level: Data
210 Client: localhost-fd
211 FileSet: LinuxHome
212 Pool: Default (From Job resource)
213 Storage: File1 (From Command input)
214 Verify Job: LinuxHome.2021-10-12_05.31.58_03
215 Verify List:
216 When: 2021-10-12 05:40:12
217 Priority: 10
218 OK to run? (yes/mod/no): m
219 Parameters to modify:
220 1: Level
221 2: Storage
222 3: Job
223 4: FileSet
224 5: Client
225 6: When
226 7: Priority
227 8: Pool
228 9: Verify Job
229 10: Plugin Options
230 Select parameter to modify (1-10): 10
231 Please Plugin Options string: antivirus: hostname=127.0.0.1 port=3310
232 Run Verify Job
233 JobName: Verify_and_AV_Scan
234 Level: Data
235 Client: localhost-fd
236 FileSet: LinuxHome
237 Pool: Default (From Job resource)
238 Storage: File1 (From Command input)
239 Verify Job: LinuxHome.2021-10-12_05.31.58_03
240 Verify List:
241 When: 2021-10-12 05:40:12
242 Priority: 10
243 Plugin Options: antivirus: hostname=127.0.0.1 port=3310
244 OK to run? (yes/mod/no): yes
245 \end{bVerbatim}
246
247
248 \subsection{Bacula Antivirus Plugin Behavior}
249
250 Under normal conditions, the Verify Job will silently scan existing files from the specified backup and should terminate with a "Verify OK" Job status:
251
252 \begin{bVerbatim}
253 run job=Verify_and_AV_Scan jobid=1 storage=File1
254
255 JobName: Verify_and_AV_Scan
256 Level: Data
257 Client: localhost-fd
258 FileSet: LinuxHome
259 Pool: Default (From Job resource)
260 Storage: File1 (From Command input)
261 Verify Job: LinuxHome.2021-10-12_06.04.11_03
262 Verify List:
263 When: 2021-10-12 06:04:17
264 Priority: 10
265 Plugin Options: antivirus: hostname=localhost port=3310
266 OK to run? (yes/mod/no): yes
267
268 12-Oct 06:04 localhost-dir JobId 2: Verifying against JobId=1 Job=LinuxHome.2021-10-12_06.04.11_03
269 12-Oct 06:04 localhost-dir JobId 2: Start Verify JobId=2 Level=Data Job=Verify_and_AV_Scan.2021-10-12_06.04.17_05
270 12-Oct 06:04 localhost-dir JobId 2: Connected to Storage "File1" at localhost:8103 with TLS
271 12-Oct 06:04 localhost-dir JobId 2: Using Device "FileStorage1" to read.
272 12-Oct 06:04 localhost-dir JobId 2: Connected to Client "localhost-fd" at localhost:8102 with TLS
273 12-Oct 06:04 localhost-fd JobId 2: Connected to Storage at localhost:8103 with TLS
274 12-Oct 06:04 localhost-sd JobId 2: Ready to read from volume "TestVolume001" on File device "FileStorage1" (/mnt/archive).
275 12-Oct 06:04 localhost-fd JobId 2: Got plugin command = antivirus: hostname=localhost port=3310
276 12-Oct 06:04 localhost-sd JobId 2: Forward spacing Volume "TestVolume001" to addr=228
277 12-Oct 06:05 localhost-sd JobId 2: End of Volume "TestVolume001" at addr=98844823 on device "FileStorage1" (/mnt/archive).
278 12-Oct 06:05 localhost-sd JobId 2: Elapsed time=00:00:51, Transfer rate=1.935 M Bytes/second
279 12-Oct 06:05 localhost-dir JobId 2: Bacula localhost-dir 12.9.2 (11Oct21):
280 Build OS: x86_64-pc-linux-gnu ubuntu 9.12
281 JobId: 2
282 Job: Verify_and_AV_Scan.2021-10-12_06.04.17_05
283 FileSet: LinuxHome
284 Verify Level: Data
285 Client: localhost-fd
286 Verify JobId: 1
287 Verify Job:
288 Start time: 12-Oct-2021 06:04:19
289 End time: 12-Oct-2021 06:05:21
290 Elapsed time: 1 min 2 secs
291 Accurate: no
292 Files Expected: 2,238
293 Files Examined: 2,238
294 Non-fatal FD errors: 0
295 SD Errors: 0
296 FD termination status: OK
297 SD termination status: OK
298 Termination: **Verify OK**
299
300 \end{bVerbatim}
301
302 When a virus is detected by ClamAV, an error is reported in the Bacula job log and the Job will continue
303 to verify the rest of the files, but it will terminate with a "Verify OK -- with warnings" Job status.
304
305 Within the job output, the antivirus plugin specifies the infected file(s) and the virus name(s) detected.
306
307 \begin{bVerbatim}
308 run job=Verify_and_AV_Scan jobid=3 storage=File1
309
310 JobName: Verify_and_AV_Scan
311 Level: Data
312 Client: localhost-fd
313 FileSet: LinuxHome
314 Pool: Default (From Job resource)
315 Storage: File1 (From Command input)
316 Verify Job: LinuxHome.2021-10-12_06.05.22_07
317 Verify List:
318 When: 2021-10-12 06:05:27
319 Priority: 10
320 Plugin Options: antivirus: hostname=localhost port=3310
321 OK to run? (yes/mod/no): yes
322
323 12-Oct 06:05 localhost-dir JobId 4: Verifying against JobId=3 Job=LinuxHome.2021-10-12_06.05.22_07
324 12-Oct 06:05 localhost-dir JobId 4: Start Verify JobId=4 Level=Data Job=Verify_and_AV_Scan.2021-10-12_06.05.27_09
325 12-Oct 06:05 localhost-dir JobId 4: Connected to Storage "File1" at localhost:8103 with TLS
326 12-Oct 06:05 localhost-dir JobId 4: Using Device "FileStorage1" to read.
327 12-Oct 06:05 localhost-dir JobId 4: Connected to Client "localhost-fd" at localhost:8102 with TLS
328 12-Oct 06:05 localhost-fd JobId 4: Connected to Storage at localhost:8103 with TLS
329 12-Oct 06:05 localhost-sd JobId 4: Ready to read from volume "TestVolume001" on File device "FileStorage1" (/mnt/archive).
330 12-Oct 06:05 localhost-fd JobId 4: Got plugin command = antivirus: hostname=localhost port=3310
331 12-Oct 06:05 localhost-sd JobId 4: Forward spacing Volume "TestVolume001" to addr=98844823
332 12-Oct 06:05 localhost-sd JobId 4: End of Volume "TestVolume001" at addr=98845442 on device "FileStorage1" (/mnt/archive).
333 12-Oct 06:05 localhost-sd JobId 4: Elapsed time=00:00:01, Transfer rate=197 Bytes/second
334 12-Oct 06:05 localhost-fd JobId 4: **Error: /home/nbizet/src/bacula-bee/regress/tmp/eicar Virus detected stream: Eicar-Signature FOUND**
335 12-Oct 06:05 localhost-dir JobId 4: Bacula localhost-dir 12.9.2 (11Oct21):
336 Build OS: x86_64-pc-linux-gnu ubuntu 9.12
337 JobId: 4
338 Job: Verify_and_AV_Scan.2021-10-12_06.05.27_09
339 FileSet: LinuxHome
340 Verify Level: Data
341 Client: localhost-fd
342 Verify JobId: 3
343 Verify Job:
344 Start time: 12-Oct-2021 06:05:29
345 End time: 12-Oct-2021 06:05:29
346 Elapsed time: 1 sec
347 Accurate: no
348 Files Expected: 1
349 Files Examined: 1
350 Non-fatal FD errors: 1
351 SD Errors: 0
352 FD termination status: OK
353 SD termination status: OK
354 Termination: **Verify OK -- with warnings**
355
356 \end{bVerbatim}
357
358 The Antivirus Plugin will record events into the catalog for each problem
359 that is detected. The \textbf{list fileevents} command can be used to list them.
360
361 \begin{bVerbatim}
362
363 *list fileevents jobid=3
364 Using Catalog "MyCatalog"
365 +-------+-------------------+----------+----------+------+-------------------------------+
366 | jobid | path | filename | severity | type | description |
367 +-------+-------------------+----------+----------+------+-------------------------------+
368 | 3 | /home/johndoe/mp/ | eicar | 100 | a | stream: Eicar-Signature FOUND |
369 +-------+-------------------+----------+----------+------+-------------------------------+
370
371 \end{bVerbatim}
372
373 The severity represents the level of threat, 0 behing harmless, 100 and above harmful.
374
375 The type indicates which kind of event is listed, here `a` meaning "antivirus".
376
377
378
379 \section{Bacula Malware Detection}
380 \label{MalwareDetection}
381
382 Bacula allows you to configure your jobs to detect known Malware. The detection
383 can be done at the end of the Backup job and/or with a Verify job.
384
385 The Job directive \texttt{Check Malware = yes/No} can control the behavior.
386
387 \begin{bVerbatim}
388 Job {
389 Name = MyBackup
390 Check Malware = yes
391 FileSet = FullSet
392 JobDefs = Default
393 }
394
395 FileSet {
396 Name = FullSet
397 Include {
398 Options {
399 Signature = md5
400 }
401 File = /home
402 }
403 }
404 \end{bVerbatim}
405
406 The FileSet of the Backup Job must use the \texttt{Signature = MD5} or
407 \texttt{Signature = SHA256} option to use the \texttt{Check Malware} directive.
408
409 By default, the Malware database is fetched from \texttt{abuse.ch}. If needed, it
410 can be adapted with the Director \texttt{MalwareDatabaseCommand} directive.
411
412 If a Backup job detects a malware in the backup content, an error is reported
413 and the Job status is adapted.
414
415 \begin{bVerbatim}
416
417 20-Sep 12:26 zog8-dir JobId 9: Start Backup JobId 9, Job=backup.2022-09-20_12.26.30_13
418 ...
419 20-Sep 12:26 zog8-dir JobId 9: [DI0002] Checking file metadata for Malwares
420 20-Sep 12:26 zog8-dir JobId 9: Error: [DE0007] Found Malware(s) on JobIds 9
421 Build OS: x86_64-pc-linux-gnu archlinux
422 JobId: 9
423 Job: backup.2022-09-20_12.26.30_13
424 Backup Level: Full
425 ...
426 Last Volume Bytes: 659,912,644 (659.9 MB)
427 Non-fatal FD errors: 1
428 SD Errors: 0
429 FD termination status: OK
430 SD termination status: OK
431 Termination: Backup OK -- with warnings
432 \end{bVerbatim}
433
434 The list of the Malware detected in a given Job can be displayed with the \texttt{list files type=malware}
435 command.
436
437 \begin{bVerbatim}
438
439 *list files type=malware jobid=1
440 +-------+-----------------------------+---------------+----------+
441 | jobid | filename | description | source |
442 +-------+-----------------------------+---------------+----------+
443 | 1 | /tmp/regress/build/po/fr.po | Malware found | abuse.ch |
444 +-------+-----------------------------+---------------+----------+
445
446 \end{bVerbatim}
447
448 A Verify Job with the level \texttt{VolumeToCatalog} or \texttt{Data} can be configured
449 with the \texttt{Check Malware=yes} directive to report malware in addition to
450 standard errors detected by the Verify Job feature.
451
452
453 \begin{bVerbatim}
454 *run job=VerifyVolCat jobid=1 yes
455 Job queued. JobId=7
456 *wait
457 You have messages.
458 *messages
459 20-Sep 12:26 zog8-dir JobId 7: Verifying against JobId=1 Job=backup.2022-09-20_12.25.48_03
460 20-Sep 12:26 zog8-dir JobId 7: [DI0002] Checking file metadata for Malwares
461 20-Sep 12:26 zog8-dir JobId 7: Error: [DE0007] Found Malware(s) on JobIds 1
462 20-Sep 12:26 zog8-sd JobId 7: Ready to read from volume "TestVolume001" on File device "FileChgr1-Dev1" (/tmp/regress/tmp).
463 20-Sep 12:26 zog8-sd JobId 7: Forward spacing Volume "TestVolume001" to addr=216
464 20-Sep 12:26 zog8-sd JobId 7: Elapsed time=00:00:01, Transfer rate=94.08 M Bytes/second
465 20-Sep 12:26 zog8-dir JobId 7: Bacula zog8-dir 14.1.1 (12Aug22):
466 Build OS: x86_64-pc-linux-gnu archlinux
467 JobId: 7
468 Job: VerifyVolCat.2022-09-20_12.26.14_09
469 FileSet: Full Set
470 Verify Level: VolumeToCatalog
471 Client: zog8-fd
472 Verify JobId: 1
473 Verify Job:
474 Start time: 20-Sep-2022 12:26:16
475 End time: 20-Sep-2022 12:26:25
476 Elapsed time: 9 secs
477 Accurate: yes
478 Files Expected: 3,640
479 Files Examined: 3,640
480 Non-fatal FD errors: 1
481 SD Errors: 0
482 FD termination status: OK
483 SD termination status: OK
484 Termination: Verify OK -- with warnings
485 \end{bVerbatim}