| 1 |
# ClamFS |
| 2 |
|
| 3 |
ClamFS - User-space fs with on-access antivirus scanning |
| 4 |
|
| 5 |
## Description |
| 6 |
|
| 7 |
ClamFS is a [FUSE-based user-space file system](https://en.wikipedia.org/wiki/Filesystem_in_Userspace) |
| 8 |
for Linux and [BSD](https://www.freshports.org/security/clamfs/) |
| 9 |
with on-access anti-virus file scanning through [clamd daemon](https://manpages.debian.org/testing/clamav-daemon/clamd.8.en.html) |
| 10 |
(a file scanning service developed by [ClamAV Project](https://www.clamav.net/)). |
| 11 |
|
| 12 |
### Features |
| 13 |
|
| 14 |
* Scans files using ClamAV |
| 15 |
* User-space file system (no kernel patches, modules, recompilations, etc.) |
| 16 |
* Based on libFUSE version 3 (until version 1.1.0 on libFUSE v2) |
| 17 |
* Implements all clamd scan modes: fname, fdpass and stream |
| 18 |
* Supports remote clamd instances in stream mode over TCP/IP socket |
| 19 |
* Caches scan results in a LRU cache with time-based and out-of-memory expiration |
| 20 |
* Configuration stored in XML files |
| 21 |
* Supports ulockmgr |
| 22 |
* Sends mails to administrator when detects virus |
| 23 |
|
| 24 |
## Table of contents |
| 25 |
|
| 26 |
* [Description](#description) |
| 27 |
* [Features](#features) |
| 28 |
* [Getting Started](#getting-started) |
| 29 |
* [Installing packages](#installing-packages) |
| 30 |
* [Arch](#arch) |
| 31 |
* [Debian, Ubuntu, etc.](#debian-ubuntu-etc) |
| 32 |
* [Gentoo](#gentoo) |
| 33 |
* [FreeBSD, DragonFly BSD](#freebsd-dragonfly-bsd) |
| 34 |
* [Building from sources](#building-from-sources) |
| 35 |
* [Prerequisites](#prerequisites) |
| 36 |
* [Installing dependencies](#installing-dependencies) |
| 37 |
* [Downloading](#downloading) |
| 38 |
* [Building](#building) |
| 39 |
* [Installing](#installing) |
| 40 |
* [Usage](#usage) |
| 41 |
* [Sample output](#sample-output) |
| 42 |
* [Configuration](#configuration) |
| 43 |
* [Different scan modes](#different-scan-modes) |
| 44 |
* [Additional configuration steps for FreeBSD](#additional-configuration-steps-for-freebsd) |
| 45 |
* [Mounting and unmounting ClamFS file systems](#mounting-and-unmounting-clamfs-file-systems) |
| 46 |
* [Fine tuning](#fine-tuning) |
| 47 |
* [Starting without clamd available](#starting-without-clamd-available) |
| 48 |
* [Mounting file systems from /etc/fstab](#mounting-file-systems-from-etcfstab) |
| 49 |
* [Using remote clamd instances](#using-remote-clamd-instances) |
| 50 |
* [Read-only mounts](#read-only-mounts) |
| 51 |
* [Program name reported as unknown when virus found](#program-name-reported-as-unknown-when-virus-found) |
| 52 |
* [Using ClamFS with WINE](#using-clamfs-with-wine) |
| 53 |
* [Installing FUSE v3 from sources](#installing-fuse-v3-from-sources) |
| 54 |
* [License](#license) |
| 55 |
* [Historical repositories at SourceForge](#historical-repositories-at-sourceforge) |
| 56 |
|
| 57 |
## Getting Started |
| 58 |
|
| 59 |
These instructions will get you a copy of the project up and running on your |
| 60 |
local machine. |
| 61 |
|
| 62 |
### Installing packages |
| 63 |
|
| 64 |
#### Arch |
| 65 |
|
| 66 |
[ClamFS package](https://aur.archlinux.org/packages/clamfs/) |
| 67 |
is available from [AUR](https://aur.archlinux.org/) repository. |
| 68 |
|
| 69 |
#### Debian, Ubuntu, etc. |
| 70 |
|
| 71 |
[Debian GNU/Linux](https://packages.debian.org/clamfs), |
| 72 |
[Ubuntu](https://packages.ubuntu.com/clamfs) and |
| 73 |
[Devuan](https://pkginfo.devuan.org/cgi-bin/d1pkgweb-query?search=clamfs) |
| 74 |
have `clamfs` package in their repositories. |
| 75 |
|
| 76 |
``` |
| 77 |
sudo apt install clamfs clamav-daemon clamav-freshclam |
| 78 |
``` |
| 79 |
|
| 80 |
#### Gentoo |
| 81 |
|
| 82 |
Gentoo provides [sys-fs/clamfs package](https://packages.gentoo.org/packages/sys-fs/clamfs). |
| 83 |
|
| 84 |
#### FreeBSD, DragonFly BSD |
| 85 |
|
| 86 |
[FreeBSD](https://www.freshports.org/security/clamfs/) and [DragonFly BSD]() has `security/clamfs` in ports. |
| 87 |
|
| 88 |
Install package... |
| 89 |
``` |
| 90 |
pkg install clamfs |
| 91 |
``` |
| 92 |
|
| 93 |
... or install from ports. |
| 94 |
``` |
| 95 |
cd /usr/ports/security/clamfs ; make install clean |
| 96 |
``` |
| 97 |
|
| 98 |
### Building from sources |
| 99 |
|
| 100 |
#### Prerequisites |
| 101 |
|
| 102 |
To build ClamFS on any GNU/Linux or *BSD you need: |
| 103 |
* [FUSE](https://github.com/libfuse/libfuse) >= 3 |
| 104 |
* [POCO](https://pocoproject.org/) >= 1.2.9 |
| 105 |
* [Boost](https://www.boost.org/) >= 1.33 |
| 106 |
* [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/), |
| 107 |
[autoconf](https://www.gnu.org/software/autoconf/), |
| 108 |
[automake](https://www.gnu.org/software/automake/), |
| 109 |
[make](https://www.gnu.org/software/make/)... |
| 110 |
|
| 111 |
To run ClamFS `clamd` service from [ClamAV project](https://www.clamav.net/) |
| 112 |
is required. |
| 113 |
|
| 114 |
Note 1: POCO versions up to 1.2.8 contain 4-BSDL licensed files and thus you |
| 115 |
should avoid linking it against any GPL licensed code. I strongly advise using |
| 116 |
version 1.2.9 or newer (as license issues has been fixed). |
| 117 |
|
| 118 |
Note 2: ClamFS version up to 1.0.1 required also |
| 119 |
[GNU CommonCPP](https://www.gnu.org/software/commoncpp/) |
| 120 |
library. This dependency was dropped in version 1.1.0 (with commit 3bdb8ec). |
| 121 |
|
| 122 |
#### Installing dependencies |
| 123 |
|
| 124 |
##### Arch |
| 125 |
|
| 126 |
Sync following packages to build ClamFS: |
| 127 |
``` |
| 128 |
pacman -Syu base-devel fuse3 poco boost |
| 129 |
``` |
| 130 |
|
| 131 |
##### Debian, Ubuntu, etc. |
| 132 |
|
| 133 |
To build ClamFS on Debian GNU/Linux and Ubuntu install these packages: |
| 134 |
* libfuse3-dev |
| 135 |
* libpoco-dev |
| 136 |
* libboost-dev |
| 137 |
* pkg-config |
| 138 |
|
| 139 |
As a run-time dependency install: |
| 140 |
* clamav-daemon |
| 141 |
* fuse |
| 142 |
|
| 143 |
Run following command to install all dependencies. |
| 144 |
``` |
| 145 |
sudo apt-get -y --no-install-recommends install \ |
| 146 |
build-essential pkg-config autoconf automake \ |
| 147 |
libfuse3-dev libpoco-dev libboost-dev \ |
| 148 |
clamav-daemon clamav-freshclam |
| 149 |
``` |
| 150 |
|
| 151 |
##### Fedora |
| 152 |
|
| 153 |
To build ClamFS on Fedora you need those packages: |
| 154 |
* fuse3-devel |
| 155 |
* poco-devel |
| 156 |
* boost-devel |
| 157 |
* pkg-config |
| 158 |
|
| 159 |
As a run-time dependency install: |
| 160 |
* clamd |
| 161 |
|
| 162 |
Run following command to install all dependencies. |
| 163 |
``` |
| 164 |
sudo dnf install automake boost-devel poco-devel fuse3-devel \ |
| 165 |
pkg-config clamd |
| 166 |
``` |
| 167 |
|
| 168 |
##### FreeBSD, DragonFly BSD |
| 169 |
|
| 170 |
To build ClamFS on FreeBSD and DragonFly BSD you need those ports: |
| 171 |
* [sysutils/fusefs-libs3](https://www.freshports.org/sysutils/fusefs-libs3/) |
| 172 |
* [devel/poco](https://www.freshports.org/devel/poco/) |
| 173 |
* [devel/boost-libs](https://www.freshports.org/devel/boost-libs/) |
| 174 |
* [devel/pkgconf](https://www.freshports.org/devel/pkgconf/) |
| 175 |
* [devel/autoconf](https://www.freshports.org/devel/autoconf/) |
| 176 |
* [devel/automake](https://www.freshports.org/devel/automake/) |
| 177 |
|
| 178 |
As a run-time dependency you need: |
| 179 |
* [security/clamav](https://www.freshports.org/security/clamav/) |
| 180 |
|
| 181 |
Note: FreeBSD >= 6.0 & < 10.0 use `sysutils/fusefs-kmod` port. FreeBSD |
| 182 |
>= 10.0 & < 12.1 use fuse kernel module. In FreeBSD >= 12.1 module |
| 183 |
was renamed to fusefs for consistency with other filesystems. |
| 184 |
|
| 185 |
#### Downloading |
| 186 |
|
| 187 |
Just download the release package and extract it with `tar`. |
| 188 |
|
| 189 |
``` |
| 190 |
tar xf clamfs-<version>.tar.gz |
| 191 |
``` |
| 192 |
|
| 193 |
Or clone repository. |
| 194 |
|
| 195 |
``` |
| 196 |
git clone https://github.com/burghardt/clamfs.git |
| 197 |
``` |
| 198 |
|
| 199 |
#### Building |
| 200 |
|
| 201 |
If using cloned repository rebuild autotools configuration with `autogen.sh` |
| 202 |
script. If using release tarballs skip this step. |
| 203 |
``` |
| 204 |
sh autogen.sh |
| 205 |
``` |
| 206 |
|
| 207 |
Configure package with `configure` script. |
| 208 |
``` |
| 209 |
sh configure |
| 210 |
``` |
| 211 |
|
| 212 |
Finally build sources with `make`. |
| 213 |
``` |
| 214 |
make -j |
| 215 |
``` |
| 216 |
|
| 217 |
#### Installing |
| 218 |
|
| 219 |
Run `make install` (as root) to install binaries. |
| 220 |
``` |
| 221 |
sudo make install |
| 222 |
``` |
| 223 |
|
| 224 |
### Usage |
| 225 |
|
| 226 |
ClamFS requires only one argument - configuration file name. Configuration is |
| 227 |
stored as XML document. Sample configuration is available in `doc` directory, |
| 228 |
in file named [clamfs.xml](doc/clamfs.xml). |
| 229 |
|
| 230 |
#### Sample output |
| 231 |
|
| 232 |
``` |
| 233 |
17:11:44 (clamfs.cxx:993) ClamFS v1.1.0-snapshoot (git-7d4beda) |
| 234 |
17:11:44 (clamfs.cxx:994) Copyright (c) 2007-2019 Krzysztof Burghardt <[email protected]> |
| 235 |
17:11:44 (clamfs.cxx:995) https://github.com/burghardt/clamfs |
| 236 |
17:11:44 (clamfs.cxx:1004) ClamFS need to be invoked with one parameter - location of configuration file |
| 237 |
17:11:44 (clamfs.cxx:1005) Example: src/clamfs /etc/clamfs/home.xml |
| 238 |
``` |
| 239 |
|
| 240 |
#### Configuration |
| 241 |
|
| 242 |
Please refer to [clamfs.xml](doc/clamfs.xml) for comprehensive list of |
| 243 |
configuration options. Only three options are mandatory: |
| 244 |
* `<clamd socket="" />` to set path to `clamd` socket |
| 245 |
* `<filesystem root="" />` to set place from ClamFS will read files |
| 246 |
* `<filesystem mountpoint="" />` to set mount point where virtual filesystem |
| 247 |
will be attached in directory tree |
| 248 |
|
| 249 |
#### Different scan modes |
| 250 |
|
| 251 |
ClamFS versions up to 1.1.0 use `fname` mode and pass only file name (with |
| 252 |
`SCAN` command) to clamd. |
| 253 |
|
| 254 |
In ClamFS versions after 1.1.0 three different modes are available to pass |
| 255 |
files to clamd. Default method is `fdpass`. |
| 256 |
|
| 257 |
##### mode="fname" - pass file name (with SCAN command) |
| 258 |
|
| 259 |
This is the simplest mode. In this mode clamd opens and reads file by itself. |
| 260 |
Permissions have to be set to allow clamd to access the file. Also this mode |
| 261 |
works only when clamd and ClamFS are no the same machine and both have access |
| 262 |
to files. Using this mode might require permissions or ACLs setup for clamd |
| 263 |
user. Please note that attempts to run clamd as root to bypass permissions |
| 264 |
is usually a bad idea. |
| 265 |
|
| 266 |
##### mode="fdpass" - pass file descriptor (with FILDES command) |
| 267 |
|
| 268 |
This is the default mode when BSD 4.4 / RFC2292 style fd passing is available |
| 269 |
in the operating system. In this mode ClamFS opens file and passes file |
| 270 |
descriptor to clamd over UNIX domain socket. Finally clamd reads file by |
| 271 |
itself. This mode works only when clamd and ClamFS are no the same machine |
| 272 |
and operating system supports file descriptor sharing. |
| 273 |
|
| 274 |
##### mode="stream" - pass file stream (with INSTREAM command) |
| 275 |
|
| 276 |
Last mode offers ability to use remote clamd instances. In this mode ClamFS |
| 277 |
opens and reads file. Than sends it to clamd over the UNIX domain or TCP/IP |
| 278 |
socket. This works for local and remote clamd instances, but for local clamd |
| 279 |
instance `fdpass` is preferred scanning method. |
| 280 |
|
| 281 |
#### Additional configuration steps for FreeBSD |
| 282 |
|
| 283 |
FreeBSD's `fusefs` kernel module has to be loaded before starting ClamFS. This |
| 284 |
can be done ad-hoc with `kldload fusefs` command. |
| 285 |
|
| 286 |
To have it loaded at boot time, add the following line to `/boot/loader.conf`. |
| 287 |
```sh |
| 288 |
fusefs_load="YES" |
| 289 |
``` |
| 290 |
|
| 291 |
Or append fuse module to `kld_list` in `/etc/rc.conf`. |
| 292 |
```sh |
| 293 |
kld_list="fusefs" |
| 294 |
``` |
| 295 |
|
| 296 |
Note: before FreeBSD 12.1 `fusefs` module was named `fuse`. |
| 297 |
|
| 298 |
Also configure ClamAV daemon and signature downloader service to start during |
| 299 |
boot with following options appended to `/etc/rc.conf`. |
| 300 |
```sh |
| 301 |
clamav_clamd_enable="YES" |
| 302 |
clamav_freshclam_enable="YES" |
| 303 |
``` |
| 304 |
|
| 305 |
Finally start required services with following commands. |
| 306 |
```sh |
| 307 |
service kld start |
| 308 |
service clamav-freshclam start |
| 309 |
service clamav-clamd start |
| 310 |
``` |
| 311 |
|
| 312 |
#### Mounting and unmounting ClamFS file systems |
| 313 |
|
| 314 |
To mount ClamFS filesystem run ClamFS with configuration filename as a parameter. |
| 315 |
```sh |
| 316 |
clamfs /etc/clamfs/netshare.xml |
| 317 |
``` |
| 318 |
|
| 319 |
To unmount ClamFS use `fusermount` with `-u` flag and |
| 320 |
`<filesystem mountpoint="/net/share" />` value as a parameter. |
| 321 |
```sh |
| 322 |
sudo fusermount -u /net/share |
| 323 |
``` |
| 324 |
|
| 325 |
## Fine tuning |
| 326 |
|
| 327 |
### Starting without clamd available |
| 328 |
|
| 329 |
A new “check” option was added to allow you to mount a ClamFS file system when |
| 330 |
clamd is not available, such as during an early stage of the boot process. |
| 331 |
To disable ClamAV Daemon (clamd) check on ClamFS startup set option check to |
| 332 |
no: |
| 333 |
```xml |
| 334 |
<clamd socket="/var/run/clamav/clamd.ctl" check="no" /> |
| 335 |
``` |
| 336 |
|
| 337 |
### Mounting file systems from /etc/fstab |
| 338 |
|
| 339 |
With `check=no` mounting ClamFS file systems form /etc/fstab is possible using |
| 340 |
fuse mount helper (/sbin/mount.fuse). ClamFS will be started on boot with |
| 341 |
configuration file defined here provided as its argument. Simple definition |
| 342 |
of ClamFS mount point in /etc/fstab looks like: |
| 343 |
``` |
| 344 |
clamfs#/etc/clamfs/share.xml /clamfs/share fuse defaults 0 0 |
| 345 |
``` |
| 346 |
|
| 347 |
### Using remote clamd instances |
| 348 |
|
| 349 |
ClamFS can reach remote clamd instances using TCP/IP sockets. This type of |
| 350 |
connection requires `mode="stream"` settings and use clamd's `INSTREAM` |
| 351 |
command to scan files smaller than `StreamMaxLength` which defaults to 25 MiB. |
| 352 |
```xml |
| 353 |
<clamd socket="<IP>:<port>" mode="stream" /> |
| 354 |
``` |
| 355 |
|
| 356 |
Default clamd port is `3310`. For server running at address `192.168.1.101` |
| 357 |
configuration is: |
| 358 |
```xml |
| 359 |
<clamd socket="192.168.1.101:3310" mode="stream" /> |
| 360 |
``` |
| 361 |
|
| 362 |
### Read-only mounts |
| 363 |
|
| 364 |
The “readonly” option was added to the filesystem options allowing you to |
| 365 |
create a read-only protected file system. Just extend filesystem definition |
| 366 |
in config file with `readonly` option set to `yes`: |
| 367 |
```xml |
| 368 |
<filesystem root="/share" mountpoint="/clamfs/share" readonly="yes" /> |
| 369 |
``` |
| 370 |
|
| 371 |
### Program name reported as unknown when virus found |
| 372 |
|
| 373 |
``` |
| 374 |
16:33:24 (clamav.cxx:152) (< unknown >:19690) (root:0) /tmp/eicar.com: Eicar-Test-Signature FOUND |
| 375 |
``` |
| 376 |
|
| 377 |
To see program name instead of `< unknown >` in log messages on FreeBSD one |
| 378 |
need to mount `/proc` filesystem. Add following line to `/etc/fstab`. |
| 379 |
``` |
| 380 |
proc /proc procfs rw 0 0 |
| 381 |
``` |
| 382 |
And mount `/proc` with `mount /proc`. |
| 383 |
|
| 384 |
Program name should be reported correctly with mounted `/proc`. |
| 385 |
``` |
| 386 |
16:37:31 (clamav.cxx:152) (hexdump:19740) (root:0) /tmp/eicar.com: Eicar-Test-Signature FOUND |
| 387 |
``` |
| 388 |
|
| 389 |
### Using ClamFS with WINE |
| 390 |
|
| 391 |
Following steps setups on-access file scanning with ClamAV for WINE instance. |
| 392 |
|
| 393 |
1. Install ClamFS runtime dependencies. |
| 394 |
```sh |
| 395 |
sudo apt install clamav-freshclam clamav-daemon |
| 396 |
``` |
| 397 |
2. Move original `C:\` drive to new location. |
| 398 |
```sh |
| 399 |
mv ~/.wine/drive_c ~/.wine/raw_drive_c |
| 400 |
mkdir ~/.wine/drive_c |
| 401 |
``` |
| 402 |
3. Copy [clamfs.xml](doc/clamfs.xml) to `~/.wine/clamfs.xml`. |
| 403 |
4. Set following options in `clamfs.xml`. Make sure `mode="fdpass"` and |
| 404 |
`public="no"` are set. |
| 405 |
```xml |
| 406 |
<clamd socket="/var/run/clamav/clamd.ctl" mode="fdpass" check="yes" /> |
| 407 |
<filesystem root="/home/user/.wine/raw_drive_c" mountpoint="/home/user/.wine/drive_c" public="no" /> |
| 408 |
``` |
| 409 |
5. Mount ClamFS filesystem as normal user with this command. |
| 410 |
```sh |
| 411 |
clamfs ~/.wine/clamfs.xml |
| 412 |
``` |
| 413 |
6. Run any WINE software and check logs with. |
| 414 |
```sh |
| 415 |
sudo tail -F /var/log/clamav/clamav.log /var/log/syslog |
| 416 |
``` |
| 417 |
|
| 418 |
For legacy configuration without `mode=fdpass` enabled please refer to my blog |
| 419 |
post [Wine with on-access ClamAV scanning](https://blog.burghardt.pl/2007/11/wine-with-on-access-clamav-scanning/) |
| 420 |
if you are interested in running ClamFS version <= 1.1.0 to protect WINE |
| 421 |
installation. |
| 422 |
|
| 423 |
### Installing FUSE v3 from sources |
| 424 |
|
| 425 |
If your operating system does not provide binary package for `libfuse3` (like |
| 426 |
Ubuntu 18.04 LTS) installing `fuse3` from sources into `/usr/local` might be |
| 427 |
simplest method to install this dependency. Following commands installs current |
| 428 |
`master` branch from Github `libfuse` repository: |
| 429 |
|
| 430 |
```sh |
| 431 |
sudo apt-get -y --no-install-recommends install meson ninja-build |
| 432 |
mkdir /tmp/fuse3 ; cd /tmp/fuse3 |
| 433 |
git clone --depth 1 https://github.com/libfuse/libfuse.git . |
| 434 |
mkdir build ; cd build |
| 435 |
meson .. |
| 436 |
ninja |
| 437 |
sudo ninja install |
| 438 |
``` |
| 439 |
|
| 440 |
Please note that Debian 9 (codename "Stretch") is unable to build fuse3 as |
| 441 |
meson version provided in stretch repository is too old (package version is |
| 442 |
0.37.1, but fuse requires >= 0.42). |
| 443 |
|
| 444 |
## License |
| 445 |
|
| 446 |
This project is licensed under the GPLv2 License - see the |
| 447 |
[COPYING](COPYING) file for details. |
| 448 |
|
| 449 |
## Historical repositories at SourceForge |
| 450 |
|
| 451 |
Long time ago [ClamFS](http://clamfs.sourceforge.net/) was developed on |
| 452 |
[SourceForge](https://sourceforge.net/projects/clamfs/) and some CVS and |
| 453 |
SVN repositories still resides there. Right now all development takes place |
| 454 |
on GitHub. |