ClamAV Anti Virus and Anti Malware
Installation
Section titled “Installation”Add a service user account (optional)
Section titled “Add a service user account (optional)”When running freshclam or clamd as a service, create a service
account.
- ClamAV Daemon (clamd) can scan for virues that uses libclamav using:
- clamdscan - scanner, command-line tool for simple scans
- on-access scanning via clamd
- clamdtop - resource monitoring interface for clamd
- These are some tools that allow for testing and management of
signatures:
- clambc - bytecode tester
- sigtool - general tests/analysis
- freshclam - update signature database to latest
Configuration
Section titled “Configuration”More complex tools ClamAV need some configuration.
ClamAV does provide example configurations:
- clamd.conf - for ClamAV Daemon and related tools
- freshclam.conf - for freshclam signature database updates
- clamav-milter can be attached to clamd for mail scanning
Uses can use clamconf to check configurations by each tool.
First Time Set up
Section titled “First Time Set up”- Example: clamav install on Ubuntu with apt install will place configs
in
/etc/clamav. - Compilation from source requires uses to create freshclam.conf, clamd.conf, and clamav-milter.conf manually. The install will place files is different directories.
# Unix/Linux: Generate example configurations if you do not have themclamconf -g freshclam.conf > freshclam.confclamconf -g clamd.conf > clamd.confclamconf -g clamav-milter.conf > clamav-milter.confSee First Time Set up for Windows as well
freshclam.conf
Section titled “freshclam.conf”- Automatic database update tool. Two modes are available:
- Interactive: on demand command line
- Daemon: runs in the background and updates automatically
See freshclam.conf for more details on requires to get freshclam running regularly:
- /var/log configuration and permissions
- Configuration file
- Start daemon
- crontab update to regularly get update
- Further settings in the example configuration and popular options
clamd.conf
Section titled “clamd.conf”Configuration for clamd daemon. Users need to edit the example configuration and at minimum comment out the example line.
See clamd.conf for details on:
- Minimum edits required
- Local socket configuration
- Popular options in configuration file
Use man clamd.conf for manual. Also read through the example
configuration file for comments and options.
- On-Access Scanning Can be configured
clamav-milter.conf
Section titled “clamav-milter.conf”- Mail filtering tool, requires clamd to be running
- Separate configuration and log files from clamd
Users and Privileges
Section titled “Users and Privileges”Requirements for users and privileges related to running freshclam, clamd, updates, and scanning. DatabaseOwner in freshclam.conf should own database directory to download signatures.
SELinux for ClamAV
Section titled “SELinux for ClamAV”Used in Linux distributions like Fedora with SELinux enabled use the
non-standard antivirus_can_scan_system option instead of
clamd_can_scan_system. You may need to manually enable the
non-standard option, otherwise there will be a freshclam message.
ClamConf
Section titled “ClamConf”clamconf is a CLI tool to check configuration files for ClamAV tools
and can generate example configuration files.
Signature Testing and Management
Section titled “Signature Testing and Management”-
Before you can start the ClamAV scanning engine (using either clamd or clamscan), you must first have ClamAV Virus Database (.cvd) file(s) installed
-
With a valid freshclam.conf configuration file, run
freshclam. It will connect to the ClamAV virus signature database network. -
Ubuntu specific possible error:
- Important: It is common on Ubuntu after a fresh install to see the following error the first time you use ClamAV:
freshclam: error while loading shared libraries: libclamav.so.7: cannot open shared object file: No such file or directory
You can fix this error by using ldconfig to rebuild the library search path.
sudo ldconfig
Other Signature Tools
Section titled “Other Signature Tools”See Signature management for further tools.
Scanning
Section titled “Scanning”- Make sure clamd is started with a valid configuration
ClamDScan
Section titled “ClamDScan”- Use command
clamdscanto scan files and directories. It will use the runningclamddaemon to scan files.
Example from Arch Wiki ClamAV
# Check Freshclam signatures databasesystemctl status clamav-freshclam
clamdscan --fdpass <directory># Multithread scan on justin's user directory while running as user "justin"clamdscan --multiscan --fdpass /home/justin
# Scan all files as rootclamdscan --multiscan --fdpass /
# 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, used when scan and running a different users than clamav# 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.ClamDTop
Section titled “ClamDTop”clamdtop is a tool to monitor one or multiple instances of clamd. It
has a colorized ncurses interface, which shows each job queued, memory
usage, and information about the loaded signature database for the
connected clamd instance(s). By default it will attempt to connect to
the local clamd as defined in clamd.conf
On-Access Scanning
Section titled “On-Access Scanning”- The “ClamOnAcc” applications provides on access canning for Linux and is real-time protection that uses clamd to scan files when they are accessed. Default only notifies the user and follows actions prompted by user at command line.
- If can be set up in
clamd.conf
ClamScan
Section titled “ClamScan”clamscanis a command line tool one time scanning of files and directories. It does not require a running clamd. It will create a new engine and load the virus database each time, scan the files and exit providing a report.
# Only scan files in current directoryclamscan .
# Scan all files in current and lower directoriesclamscan --recursive .
# Scan all files on the systemclamscan --recursive /# Similar to above with exclusionsclamscan --recursive / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --exclude-dir=/runProcess Memory Scanning
Section titled “Process Memory Scanning”clamscan and clamdscan are able to scan the virtual memory of currently executing processes. To do so, use the –memory option:
clamscan --memory
The --kill and --unload options allow for killing/unloading infected
loaded modules.
Ubuntu Specific Information
Section titled “Ubuntu Specific Information”-
Ubuntu default location for configuration files is
/etc/clamav -
When running
freshclam, you may received/var/log/clamav/freshclam.log is locked by another process.... > You don’t have to run it manually because it has been run automatically and is running in the background, that’s why you receive that message. -
See also ClamAV systemctl on start, stop services for daemon services