Debian Codegraph @

docs/fangfrisch.adoc

raw
1 = Fangfrisch
2 Ralph Seichter <[email protected]>
3 :doctype: article
4 :revdate: {docdate}
5 :revnumber: 1.9.2
6 :version-label!:
7 :copyright: © 2020-2025 Ralph Seichter
8 :encoding: UTF-8
9 :hyphens: en
10 :lang: en
11 :keywords: antivirus, clamav, fangfrisch, freshclam, refresh, update
12 :media: screen
13 :pagenums!:
14 :pdf-version: 1.7
15 :reproducible:
16 :sectanchors:
17 :sectnums:
18 :subject: Update and verify unofficial Clam Anti-Virus signatures
19 :xrefstyle: short
20
21 Fangfrisch (German for "freshly caught") is a sibling of the https://www.clamav.net[Clam Anti-Virus] freshclam utility.
22 It allows downloading virus definition files that are not official ClamAV canon, e.g. from https://sanesecurity.com[Sanesecurity] and https://urlhaus.abuse.ch[URLhaus].
23 Fangfrisch was designed with security in mind, to be run by an unprivileged user only.
24 For those curious about the development history, a https://github.com/rseichter/fangfrisch/blob/master/CHANGELOG.rst[changelog] is available online.
25
26 == License
27
28 Copyright {copyright}
29
30 This file is part of "Fangfrisch".
31
32 Fangfrisch is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
33
34 Fangfrisch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 See the GNU General Public License for more details.
36
37 You should have received a copy of the GNU General Public License along with Fangfrisch.
38 If not, see <https://www.gnu.org/licenses/>.
39
40 == Update strategy
41
42 Fangfrisch is expected to run periodically, e.g. using https://en.wikipedia.org/wiki/Cron[cron].
43 Fangfrisch will attempt to download digests first (if available upstream), and only retrieve corresponding signature files when their recorded digest changes, minimising transfer volumes.
44
45 I recommend running Fangfrisch at 10 minute intervals.
46 There is no need to worry about overburdening your machine, the network or remote signature providers.
47 Each individual download is recorded in the database, and whenever Fangfrisch is run, it checks those recorded timestamps against the preconfigured provider intervals.
48 No network connections are made for downloaded signature files which are considered "too young to update".
49
50 Imagine a provider interval setting of 45 minutes.
51 Even if launched every 10 minutes, Fangfrisch will not attempt to download related signature files before 45 minutes have passed since the last recorded successful download.
52 Provider intervals are set to reasonable defaults internally, but you can override them if necessary.
53
54 == Installation
55
56 Fangfrisch requires Python version 3.9 or newer.
57 While Fangfrisch was initially written for Python 3.7, security support (the final lifecycle stage) for that version was terminated by the Python Software Foundation in 2023. Python 3.8 reached its EOL in 2024.
58
59 The recommended installation method is using the https://packaging.python.org/tutorials/installing-packages/[pip command] in a virtual Python environment.
60 Here is an example listing of commands for BASH, to be executed as root, assuming that you will be running Fangfrisch as an unprivileged user who is member of the *clamav* group:
61
62 === Create home directory
63
64 ----
65 mkdir -m 0770 -p /var/lib/fangfrisch
66 chgrp clamav /var/lib/fangfrisch
67 ----
68
69 This will grant group members the necessary write access to create the database (see <<dbsetup>>).
70
71 === Prepare and activate venv
72
73 ----
74 cd /var/lib/fangfrisch
75 python3 -m venv venv
76 source venv/bin/activate
77 ----
78
79 === Install via https://pypi.org/project/fangfrisch/[PyPI]
80
81 ----
82 pip install fangfrisch
83 ----
84
85 This step will also create an executable launcher script `venv/bin/fangfrisch`.
86
87 == Installation packages
88
89 As an alternative to pip-based installation, there are packages available for the following Linux distributions:
90
91 * Arch Linux: https://aur.archlinux.org/packages/python-fangfrisch/[packages/python-fangfrisch].
92 Support contact: Arch package maintainer.
93
94 * Clear Linux: https://github.com/clearlinux-pkgs/fangfrisch[clearlinux-pkgs/fangfrisch].
95 Support contact: Clear Linux package maintainers.
96
97 * Debian Linux: https://packages.debian.org/sid/fangfrisch[fangfrisch (utils)].
98 Support contact: Debian package maintainers.
99
100 * Gentoo Linux: https://packages.gentoo.org/packages/app-antivirus/fangfrisch[app-antivirus/fangfrisch].
101 Support contact: Gentoo package maintainers.
102
103 * NixOS: https://search.nixos.org/packages?type=packages&query=fangfrisch[fangfrisch]
104 Support contact: NixOS package maintainers.
105
106 == Configuration
107
108 A configuration file is mandatory, uses an INI-File-like structure and must contain a `db_url` entry.
109 All other settings are optional.
110 However, unless you enable one signature file provider section, Fangfrisch naturally won't do much.
111
112 Use the `--conf` command line argument (see <<usage>>) to specify the path to your configuration file.
113 Note that there is no default location.
114
115 ----
116 # Minimal example configuration, meant for testing.
117
118 [DEFAULT]
119 db_url = sqlite:////var/lib/fangfrisch/db.sqlite
120 local_directory = /var/lib/clamav
121
122 [urlhaus]
123 enabled = yes
124 ----
125
126 * *cleanup*: Cleanup method used for provider sections.
127 Default: `automatic`, alternative: `disabled`.
128 In automatic mode, Fangfrisch will attempt to delete obsolete virus definition files whenever you disable a provider section.
129 Should you disable this option, orphaned files will be left behind, and you need to ensure cleanup by different means.
130 * *connection_timeout*: Timeout in seconds, used when establishing network connections to download signature files.
131 Default: `30`.
132 Be aware that longer timeouts increase the risk of multiple Fangfrisch instances running concurrently.
133 This could, in turn, cause database access problems, and network socket congestion.
134 If your Internet connection is fast, I even suggest testing timeout values lower than the default 30 seconds.
135 * *db_url*: Database URL in https://docs.sqlalchemy.org/en/13/core/engines.html#supported-databases[SQLAlchemy syntax].
136 Mandatory, no default.
137 Typically, a local https://www.sqlite.org[SQLite] database will suffice.
138 * *enabled*: Scan this section for URLs?
139 Default: `false`.
140 * *integrity_check*: Mechanism for integrity checks.
141 Default: `sha256`.
142 You can use `disabled` if the signature file provider offers no checksums.
143 * *interval*: Interval between downloads.
144 Defaults are provider-dependent.
145 Values can be expressed in human-readable form (e.g. `12h` or `45m`).
146 Please respect the limits set by each provider.
147 * *local_directory*: Downloaded files are stored here.
148 No default, so the current working directory of the Python process is used.
149 As this can vary depending on how you launch Fangfrisch, it is highly recommended to define an absolute path like `/var/lib/clamav` instead.
150 You can override this option in provider sections to separate downloads based on origin.
151 * *log_format*: See https://docs.python.org/3/library/logging.html#logging.Formatter[Formatter class] documentation for details.
152 Fangfrisch uses sensible defaults depending on the selected log method.
153 * *log_level*: Choose one of `DEBUG`, `INFO`, `WARNING` (default), `ERROR` or `FATAL`.
154 * *log_method*: Either `console` (default, meaning stdout/stderr) or `syslog`.
155 For the latter, you can also specify a *log_target*.
156 * *log_target*: The https://tools.ietf.org/html/rfc5424[syslog] target address.
157 Typical values are `/dev/log` (local Linux domain socket), `localhost` or `host.domain.tld:udpport`.
158 If no target is specified, `localhost` is assumed.
159 The UDP port number defaults to 514.
160 * *max_size*: Maximum expected file size.
161 The default is `10MB`, but all predefined providers have individual size limits (see <<internalconf>>).
162 Values are can be expressed in human-readable form (e.g. `250KB` or `3MB`).
163 Fangfrisch attempts to inspect the content length before downloading virus signature files so as not to download files larger than the defined limit.
164 If providers don't respond with content length information, Fangfrisch will log a warning but download the data anyway.
165 * *on_update_exec*: If any files were downloaded during a pass, a command can be executed in after the pass finishes.
166 No default.
167 A typical value is `clamdscan --reload`.
168 Starting with Fangfrisch 1.9.0, this option may be overridden in individual sections, permitting per-provider actions.
169 * *on_update_timeout*: Timeout for the `on_update_exec` command, in seconds.
170 Default: 30.
171 This option may also be overridden in individual sections.
172
173 https://docs.python.org/3/library/configparser.html[See here] for details about the configuration parser and extended interpolation.
174 <<Semantics>> provides additional information on how configuration options are interpreted.
175
176 === Default providers
177
178 Fangfrisch contains internal defaults for the following providers, listed in alphabetical order:
179
180 * http://sigs.interserver.net/[InterServer]
181 * https://www.malwarepatrol.net[Malwarepatrol]
182 * https://sanesecurity.com[Sanesecurity]
183 * https://www.securiteinfo.com/services/anti-spam-anti-virus/improve-detection-rate-of-zero-day-malwares-for-clamav.shtml[SecuriteInfo]
184 * https://urlhaus.abuse.ch[URLhaus]
185
186 I have also included "Fangfrisch News" (see <<ffnews>>).
187 Providers can be enabled by specifiying `enabled = yes` in the desired configuration file sections.
188
189 IMPORTANT: Please make sure to examine the respective settings for yourself before enabling providers.
190
191 The defaults may not suit your personal preferences, and some providers require additional configuration, e.g. an access token.
192
193 ----
194 include::example.conf[]
195 ----
196
197 === User-defined providers
198
199 Fangfrisch is of course not limited to the internal defaults.
200 You can define as many additional virus definition providers as you like.
201 The following defines a fictional provider:
202
203 ----
204 [fictionalprovider]
205 enabled = yes
206 integrity_check = md5
207 interval = 90m
208 prefix = http://fictional-provider.tld/clamav-unofficial/
209
210 # Reference the defined prefix in URL definitions. Values in
211 # other sections can be referenced using ${section:option}.
212 url_eggs = ${prefix}eggs.ndb
213 url_spam = ${prefix}spam.hdb
214
215 # Override local file name for url_spam
216 filename_spam = spam_spam_spam_lovely_spam.db
217
218 # Execute command after each fresh download from url_eggs
219 on_update_eggs = echo Fresh eggs in {path}
220 ----
221
222 === Semantics
223
224 Fangfrisch will scan enabled sections for lines prefixed with `url_` to determine download sources for virus definition files.
225
226 * The value of `integrity_check` determines both the expected filename suffix for digests and the hashing mechanism used for verification.
227 * Local file names will be determined by parsing URLs, but can be manually overridden.
228 To change the file name for `url_xyz`, set `filename_xyz` to the desired value.
229 * To launch a command after data was downloaded for `url_xyz`, define `on_update_xyz`.
230 The command string may contain a `{path}` placeholder, which will be substituted with the full path of the downloaded file.
231
232 You can disable refresh operations for selected URLs by assigning either an empty value or setting it to `url_xyz = disabled`.
233 Note that disabling URLs in this manner does _not_ delete any previously downloaded files.
234
235 === Proxy support
236
237 Fangfrisch relies on the _requests_ library to download files, which supports environment variables like `HTTPS_PROXY`.
238 Please refer to https://requests.readthedocs.io/en/latest/user/advanced/#proxies[section Advanced Usage, subsection Proxies] in the _requests_ online documentation for details.
239
240 [[dbsetup]]
241 == Preparing the database
242
243 After completing the configuration, make sure to create the database structure by running the `initdb` command in a root shell as shown below.
244 Running `--force initdb` will drop existing database tables.
245 For SQLite, deleting the database file is a viable alternative.
246
247 ----
248 sudo -u clamav -- fangfrisch --conf /etc/fangfrisch.conf initdb
249 ----
250
251 IMPORTANT: Fangfrisch need never be run as root.
252 Choose an unprivileged user instead (typically *clamav*).
253
254 [[usage]]
255 == Usage
256
257 Command line arguments are as follows:
258
259 [%unbreakable]
260 ----
261 include::usage.txt[]
262 ----
263
264 You can choose among following actions:
265
266 * *dumpconf*: Dump the effective configuration to stdout, combining both internal defaults and your own settings.
267 The effective configuration for the example shown in <<Configuration>> is available in <<sampleeff>>.
268
269 * *dumpmappings*: Dump URL-to-filepath mappings, as recorded in the database refresh log, to stdout.
270 See <<dbstructure>> for details.
271
272 * *initdb*: Create the database structure.
273 This needs to be run only once, before the first refresh.
274 Using the `--force` option will drop existing tables from the database.
275
276 * *refresh*: Refresh the configured URLs.
277 The `--force` option can be used to override download interval settings.
278
279 As stated before, Fangfrisch is typically run using cron.
280 Depending on your host OS, you may use a systemd timer as an alternative.
281 An example crontab looks like this:
282
283 ----
284 HOME=/var/lib/fangfrisch
285 LOG_LEVEL=INFO
286 # minute hour day-of-month month day-of-week user command
287 */10 * * * * clamav sleep $((RANDOM \% 42)); venv/bin/fangfrisch --conf /etc/fangfrisch.conf refresh
288 ----
289
290 == Support
291
292 The project is hosted on https://github.com/rseichter/fangfrisch[GitHub].
293 Before opening tickets or contacting the author, _always_ check https://github.com/rseichter/fangfrisch/issues[existing issues] first, including closed ones.
294 This is not meant to discourage you; it just saves time and effort for all involved.
295 Please contact the author mailto:{email}[{author}] only after having done your own research.
296 Thank you.
297
298 === Reporting possible problems
299
300 If you experience problems, please start by trying to figure out underlying issues on your own.
301 Running with DEBUG level logging helps with that.
302 Should your efforts fail, consider filing a GitHub issue.
303 Each issue needs to answer the questions listed below.
304
305 If you answer question number 1, 2 or 3 with "no", do not file an issue.
306 Please answer all other questions as detailed as you can, within reason.
307
308 1. Have you checked the documentation?
309 2. Have you checked all existing issues, including closed ones?
310 3. Have you done your personal best to resolve the issue on your own?
311 4. What exactly did you do?
312 5. What did you expect to happen?
313 6. What happened instead?
314 7. What was your exact setup (operating system, Python core version, Python module versions)?
315
316 === Offering suggestions
317
318 The list of questions is shorter, but important nonetheless:
319
320 1. Have you checked the documentation?
321 2. Have you checked all existing issues, including closed ones?
322 3. Do you consider the suggested feature helpful for more people than just yourself?
323
324 If you answered "yes" for all questions, please explain your idea in a sufficiently thorough manner.
325 Use examples, graphics, and whatever else you think would help others to understand your suggestion.
326
327 === Discussion precedes contribution
328
329 I do not accept any code or documentation contributions which have not been previously agreed upon.
330 This means the order of steps is as follows:
331
332 1. Open an issue or discussion topic first.
333 2. Have a conversation about the matter at hand.
334 3. Reach a consensus about both form and content of the contribution.
335 4. Wait for a yay/nay signal from me.
336
337 Please do _not_ submit any pull requests before I ask for them, as they will be closed.
338 This outlined, proven practice will save time for all involved.
339 See Heather McNamee's blog https://about.gitlab.com/blog/2016/03/03/start-with-an-issue/[Always start with an issue] for more information.
340
341 [[internalconf]]
342 [appendix]
343 == Default configuration
344
345 Fangfrisch contains the following internal configuration settings as defaults.
346 As a safety measure, all sections are disabled by default.
347 Entries with the `!url_` prefix are included for reference only.
348 These represent data sources which are not recommended for general use.
349 Possible reasons: Some sources have an elevated risk of false positives, are not free to use, or contain legacy data.
350 Enabling a section will not enable these specially prefixed entries.
351
352 ----
353 include::internal.conf[]
354 ----
355
356 [[sampleeff]]
357 [appendix]
358 == Effective configuration
359
360 The following effective configuration is the result of combining internal defaults (see <<internalconf>>) with the example settings shown in <<Configuration>>.
361
362 ----
363 include::combined.conf[]
364 ----
365
366 [[ffnews]]
367 [appendix]
368 == Fangfrisch News
369
370 This pseudo provider does not offer antivirus signature files.
371 It is only meant for me to pass news about Fangfrisch to you, the user, in lieu of a mailing list.
372 Don't expect this to happen on a regular basis.
373 I am only thinking about release notifications at this point in time.
374 Still, I kindly ask you to please enable this service by adding the following to your configuration file:
375 ----
376 [fangfrischnews]
377 enabled = yes
378 # Uncomment/adapt the following to trigger a script in case of news.
379 # script = /path/to/script/fangfrisch-has-news.sh
380 ----
381 This will only enable Fangfrisch to occasionally download small text files, nothing more.
382 You will not need to read the content, nor will anything else happen, unless you modify the `script` option.
383 Here is an example script which you could use to have downloaded news items mailed to you.
384 It needs to be readable for the user account running Fangfrisch, and the sender/recipient addresses obviously have to be adapted.
385 For your convenience, the latest version of the script can be https://raw.githubusercontent.com/rseichter/fangfrisch/master/contrib/fangfrisch-has-news.sh[downloaded here].
386 ----
387 include::../contrib/fangfrisch-has-news.sh[]
388 ----
389
390 [[dbstructure]]
391 [appendix]
392 == Database structure
393
394 While users can technically access the Fangfrisch backend database directly, its structure and content are considered *private*.
395 They may change at any time, without notice.
396
397 === Accessing mappings
398
399 In contrast to direct database access, the *dumpmappings* action allows accessing selected parts of database entries in a stable manner.
400 Specifically, it returns 3-tuples (provider name, URL, local file path).
401 Elements are separated by horizontal tabulators to facilitate piping the output into `awk` or similar utilities.
402 If specified, the `provider` option is interpreted as a regular expression, and only DB records with matching provider column are returned.
403 That means if you have providers _foo_ and _foobar_, you need to use anchoring (e.g. `^foo$`) if you only wish to match entries for the former provider.
404 Make sure to use quoting as required by your shell.
405 Example usage:
406
407 ----
408 # Print all recorded mappings for the [example] provider section.
409 fangfrisch --conf /etc/fangfrisch.conf --provider '^example$' dumpmappings
410 ----
411
412 ----
413 # Delete all files that were downloaded by Fangfrisch.
414 # DON'T EXECUTE THIS UNLESS YOU REALLY MEAN IT!
415 fangfrisch --conf /etc/fangfrisch.conf dumpmappings | awk '{print $3}' | xargs /bin/rm
416 ----