Clamav Daemon Mac

  1. Clamav For Mac
  2. Clamav Daemon Mac Os
  3. Clamav Mac Os

Clam AntiVirus is an open source (GPL) anti-virus toolkit for UNIX. It provides a number of utilities including a flexible and scalable multi-threaded daemon, a command line scanner and advanced tool for automatic database updates. Because ClamAV's main use is on file/mail servers for Windows desktops, it primarily detects Windows viruses and malware with its built-in signatures.

On the server side, ClamAV can operate in daemon mode, granting on-the-fly access to inspect files from remote locations as well as streamlined operation with suites like Sendmail through clamav-milter or qmail-scanner for qmail. Apparently clamav-daemon uses about 300MB of memory when all the virus libraries loaded. I'm running on a small VPS with 1GB of RAM and mysql-server-5.6 takes up a big chunk of that.

Installation

Install the clamav package.

Updating database

Update the virus definitions with:

If you are behind a proxy, edit /etc/clamav/freshclam.conf and update HTTPProxyServer, HTTPProxyPort, HTTPProxyUsername and HTTPProxyPassword.

The database files are saved in:

Start/enableclamav-freshclam.service so that the virus definitions are kept recent.

Starting the daemon

Note:
  • You will need to run freshclam before starting the service for the first time or you will run into trouble/errors which will prevent ClamAV from starting correctly.
  • The daemon is not needed if you only want to perform stand-alone scans. See Scan for viruses below.

The service is called clamav-daemon.service. Start it and enable it to start at boot.

Testing the software

In order to make sure ClamAV and the definitions are installed correctly, scan the EICAR test file (a harmless signature with no virus code) with clamscan.

The output must include:

Otherwise; read the Troubleshooting part or ask for help in the Arch Forums.

Adding more databases/signatures repositories

ClamAV can use databases/signature from other repositories or security vendors.

To add the most important ones in a single step, install either clamav-unofficial-sigsAUR (see GitHub description) or python-fangfrischAUR (see online documentation). Both will add signatures/databases from popular providers, e.g. MalwarePatrol, SecuriteInfo, Yara, Linux Malware Detect, etc.

Note: You still must have the clamav-freshclam.servicestarted in order to have official signature updates from ClamAV mirrors.

Option #1: Set up Fangfrisch

Fangfrisch was designed as a more secure, flexible and convenient replacement for clamav-unofficial-sigs, and requires very little configuration.

Most importantly, Fangfrisch never needs to be run with root permissions, unlike clamav-unofficial-sigs.

Clamav For Mac

Create database structure by running:

Enable the fangfrisch.timer.

Option #2: Set up clamav-unofficial-sigs

Enable the clamav-unofficial-sigs.timer.

This will regularly update the unofficial signatures based on the configuration files in the directory /etc/clamav-unofficial-sigs.

To update signatures manually, run the following:

To change any default settings, refer and modify /etc/clamav-unofficial-sigs/user.conf.

Clamav mac os

MalwarePatrol database

If you would like to use the MalwarePatrol database, sign up for an account at https://www.malwarepatrol.net/free-guard-upgrade-option.

In /etc/clamav-unofficial-sigs/user.conf, change the following to enable this functionality:

Source: https://www.malwarepatrol.net/clamav-configuration-guide/

Scan for viruses

There are two options for on-demand scanning:

using the stand-alone scanner

clamscan can be used to scan certain files, home directories, or an entire system:

If you would like clamscan to remove the infected file add to the command the --remove option, or you can use --move=/dir to quarantine them.

Machine

You may also want clamscan to scan larger files. In this case, append the options --max-filesize=4000M and --max-scansize=4000M to the command. '4000M' is the largest possible value, and may be lowered as necessary.

Using the -l /path/to/file option will print the clamscan logs to a text file for locating reported infections.

using the daemon

clamdscan is similar to the above but utilizes the daemon, which must be running for the command to work. Most options are ignored since the daemon reads the the settings specified in /etc/clamav/clamd.conf.

Using the milter

Milter will scan your sendmail server for email containing virus.Adjust the config /etc/clamav/clamav-milter.conf to your needs. For example:

Create /etc/systemd/system/clamav-milter.service:

Enable and startclamav-milter.service.

Clamav daemon mac downloadClamav Daemon Mac

For Postfix add the following lines to /etc/postfix/main.cf:

Check journalctl if the permission to access clamav-milter.socket for postfix is set accordingly, if not, add user postfix to group clamav.

OnAccessScan

This article or section is out of date.

Reason: The ScanOnAccess option is deprecated and no longer works. See upstream documentation[dead link 2020-12-20 ⓘ]. (Discuss in Talk:ClamAV#)

On-access scanning requires the kernel to be compiled with the fanotify kernel module (kernel >= 3.8). Check if fanotify has been enabled before enabling on-access scanning.

On-access scanning will scan the file while reading, writing or executing it.

First, edit the /etc/clamav/clamd.conf configuration file by adding the following to the end of the file (you can also change the individual options):

Next, create the file /etc/clamav/detected.sh and add the following. This allows you to change/specify the debug message when a virus has been detected by clamd's on-access scanning service:

If you are using AppArmor, it is also necessary to allow clamd to run as root:

Restart the clamav-daemon.service.

Source: http://blog.clamav.net/2016/03/configuring-on-access-scanning-in-clamav.html

Troubleshooting

Error: Clamd was NOT notified

If you get the following messages after running freshclam:

Add a sock file for ClamAV:

Then, edit /etc/clamav/clamd.conf - uncomment this line:

Save the file and restartclamav-daemon.service.

Error: No supported database files found

If you get the next error when starting the daemon:

This happens because of mismatch between /etc/clamav/freshclam.conf setting DatabaseDirectory and /etc/clamav/clamd.conf setting DatabaseDirectory. /etc/clamav/freshclam.conf pointing to /var/lib/clamav, but /etc/clamav/clamd.conf (default directory) pointing to /usr/share/clamav, or other directory. Edit in /etc/clamav/clamd.conf and replace with the same DatabaseDirectory like in /etc/clamav/freshclam.conf. After that clamav will start up successfully.

Error: Can't create temporary directory

If you get the following error, along with a 'HINT' containing a UID and a GID number:

Correct permissions:

Tips and tricks

Run in multiple threads

Using clamscan

When scanning a file or directory from command line using clamscan only single CPU thread is used. This may be ok in cases when timing is not critical or you do not want computer to become sluggish. If there is a need to scan large folder or USB drive quickly you may want to use all available CPUs to speed up the process.

clamscan is designed to be single-threaded, so xargs can be used to run the scan in parallel:

In this example the -P parameter for xargs runs clamscan in as many processes as there are CPUs (reported by nproc at the same time. --max-lines and --max-args options will allow even finer control of batching the workload across the threads.

Using clamdscan

If you already have clamd daemon running clamdscan can be used instead (see #Starting the daemon):

Clamav Daemon Mac Os

Here the --multiscan parameter enables clamd to scan the contents of the directory in parallel using available threads. --fdpass parameter is required to pass the file descriptor permissions to clamd as the daemon is running under clamav user and group.

The number of available threads for clamdscan is determined in /etc/clamav/clamd.conf via MaxThreads parameter clamd.conf(5). Even though you may see that the number of MaxThreads specified is more than one (current default is 10), when you start the scan using clamdscan from command line and do not specify --multiscan option, only one effective CPU thread will be used for scanning.

See also

Retrieved from 'https://wiki.archlinux.org/index.php?title=ClamAV&oldid=648860'

Dockerized open source antivirus daemons for use with

  • file sharing containers like Nextcloud or
  • to use it via a REST proxy like @solita made clamav-rest or
  • to directly connect to clamav via TCP port 3310

ClamAV daemon as a Docker image. It builds with a current virus database andrunsfreshclam in the background constantly updating the virus signature database. clamd itselfis listening on exposed port 3310.

Find the latest releases at the official docker hub registry. There are different releases for the different platforms.

The container run as user clamav with uid=101 and gid=102.

Debian (default, :latest, :buster-slim, :stretch-slim)

  • buster-slim
  • stretch-slim

Alpine (:alpine, :alpine-edge)

  • alpine
  • alpine-edge

Linked usage recommended, to not expose the port to “everyone”.

Environment VARs

Proxy

Thanks to @mchus proxy configuration is possible.

  • HTTPProxyServer: Allows to set a proxy server
  • HTTPProxyPort: Allows to set a proxy server port

Database Mirror

Specifying a particular mirror for freshclam is also possible.

  • DatabaseMirror: Hostname of the mirror web server.

Custom Configuration Files

Mount custom configuration files into the container.

  • FRESHCLAM_CONF_FILE: Path to custom freshclam.conf file, e.g. /mnt/freshclam.conf.
  • CLAMD_CONF_FILE: Set the path to a custom clamd.conf file, e.g. /mnt/clamd.conf.

Persistency

Virus update definitions are stored in /var/lib/clamav. To store the defintion just mount the directory as a volume, docker run -d -p 3310:3310 -v ./clamav:/var/lib/clamav mkodockx/docker-clamav:latest

docker-compose

See example with Nextcloud at docker-compose.yml. You still need to configure the AntiVirus files app in Nextcloud.

You can find a tutorial here: https://www.virtualconfusion.net/clamav-for-nextcloud-on-docker/

Healthcheck

The images provide with check.sh a file to check for the healthyness of the running container. To enable the health check configure your docker run or compose file. The start period should be adjusted to your system needs. Slow internet connection, with limited cpu and IO speed might require larger values.

Examples

Via docker run:

Via docker-compose

This image provides support for different platforms

  • x86
  • amd64
  • arm32v7
  • arm64v8
  • OpenShift support in kuanfandevops fork

Memory?

Some users are wondering about memory consumption of clamd. Here is an explanation of the reasons I found:

“ClamAV holds the search strings using the classic string (Boyer Moore) and regular expression (Aho Corasick) algorithms. Being algorithms from the 1970s they are extemely memory efficient.

Clamav Mac Os

The problem is the huge number of virus signatures. This leads to the algorithms’ datastructures growing quite large.

You can’t send those datastructures to swap, as there are no parts of the algorithms’ datastructures accessed less often than other parts. If you do force pages of them to swap disk, then they’ll be referenced moments later and just swap straight back in. (Technically we say “the random access of the datastructure forces the entire datastructure to be in the process’s working set of memory”.)

The datastructures are needed if you are scanning from the command line or scanning from a daemon.

You can’t use just a portion of the virus signatures, as you don’t get to choose which viruses you will be sent, and thus can’t tell which signatures you will need.” Source stackexchange.com

It is obvious that an antivirus engine based on virus signatures will raise memory consumption over the time as it always has to check for all signatures. As the number of virus signatures grows daily, the amount of necessary memory will increase as well.

Mac
This site is open source. Improve this page.