Difference between revisions of "ClamAV"

From ArchWiki
Jump to: navigation, search
m (Style fixes.)
(Adding more databases/signatures repositories: config file location updated)
 
(26 intermediate revisions by 19 users not shown)
Line 1: Line 1:
 
[[Category:Security]]
 
[[Category:Security]]
 
[[es:ClamAV]]
 
[[es:ClamAV]]
 +
[[fr:CLAMAV]]
 
[[it:ClamAV]]
 
[[it:ClamAV]]
 +
[[ja:ClamAV]]
 
[[ru:ClamAV]]
 
[[ru:ClamAV]]
 
[[sr:ClamAV]]
 
[[sr:ClamAV]]
Line 9: Line 11:
 
== Installation ==
 
== Installation ==
  
ClamAV can be [[pacman|installed]] with package {{Pkg|clamav}}, available in the [[official repositories]].
+
ClamAV can be [[install]]ed with package {{Pkg|clamav}}.
  
== Configuration ==
+
== Updating database ==
 +
Update the virus definitions with:
 +
# freshclam
 +
 
 +
The database files are saved in:
 +
/var/lib/clamav/daily.cvd
 +
/var/lib/clamav/main.cvd
 +
/var/lib/clamav/bytecode.cvd
  
Whether you are going to use ClamAV as a daemon or use it as a simple file checker you need to comment out the line that contains the word ''Example'', usually it is found at the beginning of {{ic|/etc/clamav/freshclam.conf}} and {{ic|/etc/clamav/clamd.conf}} files.
+
The virus definition updater service is called {{ic|freshclamd.service}}. Consider starting it and enabling it to start at boot so that the virus definitions are kept recent.
  
 
== Starting the daemon ==
 
== Starting the daemon ==
  
The service is called {{ic|clamd.service}}. Read [[Daemons]] for more information about starting it and enabling it to start at boot.
+
Consider updating the database before starting the service for the first time or you will run into troubles/errors which will prevent ClamAV to start correctly.
  
Also change the start options from {{ic|no}} to {{ic|yes}}:
+
The service is called {{ic|clamd.service}}. Read [[Daemons]] for more information about starting it and enabling it to start at boot. You will need to run {{ic|freshclam}} prior to starting the service.
  
{{hc|/etc/conf.d/clamav|<nowiki>
+
== Testing the software ==
# change these to "yes" to start
+
START_FRESHCLAM="yes"
+
START_CLAMD="yes"
+
</nowiki>}}
+
  
== Updating database ==
+
In order to make sure ClamAV and the definitions are installed correctly, scan the [http://www.eicar.org/86-0-Intended-use.html EICAR test file] (a harmless signature with no virus code) with clamscan.
  
Edit the below file and comment out the line saying {{ic|Example}}:
+
$ wget -O- http://www.eicar.org/download/eicar.com.txt | clamscan -
{{hc|/etc/clamav/freshclam.conf|
+
# Comment or remove the line below.
+
# Example
+
}}
+
  
Update the virus definitions with:
+
The output '''must''' include:
# freshclam
+
  
The database files are saved in:
+
stdin: Eicar-Test-Signature FOUND
/var/lib/clamav/daily.cvd
+
 
/var/lib/clamav/main.cvd
+
Otherwise; read the Troubleshooting part or ask for help in the [https://bbs.archlinux.org/ 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 {{AUR|clamav-unofficial-sigs}} and configure it in {{ic|/etc/clamav-unofficial-sigs/user.conf}}.
 +
 
 +
This will add signatures/databases from e.g. MalwarePatrol, SecuriteInfo, Yara, Linux Malware Detect,...
  
 
== Scan for viruses ==
 
== Scan for viruses ==
Line 47: Line 55:
  
 
  $ clamscan myfile
 
  $ clamscan myfile
  $ clamscan -r -i /home
+
  $ clamscan --recursive=yes --infected /home # or -r -i
  $ clamscan -r -i --exclude-dir='^/sys|^/proc|^/dev|^/lib|^/bin|^/sbin' /
+
  $ clamscan --recursive=yes --infected --exclude-dir='^/sys|^/proc|^/dev|^/lib|^/bin|^/sbin' /
  
If you would like {{ic|clamscan}} to remove the infected file use the {{ic|--remove}} option in the command.
+
If you would like {{ic|clamscan}} to remove the infected file add to the command the {{ic|--remove}} option, or you can use {{ic|1=--move=/dir}} to quarantine them.
 +
 
 +
Using the {{ic|1=-l /path/to/file}} option will print the {{ic|clamscan}} logs to a text  file for locating reported infections.
 +
 
 +
== Using the milter ==
 +
 
 +
Copy {{ic|/etc/clamav/clamav-milter.conf.sample}} to {{ic|/etc/clamav/clamav-milter.conf}} and adjust it to your needs. For example:
 +
 +
{{hc|/etc/clamav/clamav-milter.conf|2=<nowiki>
 +
MilterSocket /run/clamav/clamav-milter.sock
 +
MilterSocketMode 660
 +
FixStaleSocket yes
 +
User clamav
 +
PidFile /run/clamav/clamav-milter.pid
 +
TemporaryDirectory /tmp
 +
ClamdSocket unix:/var/lib/clamav/clamd.sock
 +
LogSyslog yes
 +
LogInfected Basic
 +
</nowiki>}}
 +
 
 +
Create {{ic|/etc/systemd/system/clamav-milter.service}}:
 +
 
 +
{{hc|/etc/systemd/system/clamav-milter.service|2=<nowiki>
 +
[Unit]
 +
Description='ClamAV Milter'
 +
After=clamd.service
 +
 
 +
[Service]
 +
Type=forking
 +
ExecStart=/usr/bin/clamav-milter --config-file /etc/clamav/clamav-milter.conf
 +
 
 +
[Install]
 +
WantedBy=multi-user.target
 +
</nowiki>}}
  
Using the {{ic|-l ''path/to/file''}} option will print the {{ic|clamscan}} logs to a text  file for locating reported infections.
+
Enable and start the service.
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 81: Line 122:
 
}}
 
}}
 
   
 
   
Generate the database as root:
+
This happens because of mismatch between {{ic|/etc/freshclam.conf}} setting {{ic|DatabaseDirectory}} and {{ic|/etc/clamd.conf}} setting {{ic|DatabaseDirectory}}.
# freshclam -v
+
{{ic|/etc/freshclam.conf}} pointing to {{ic|/var/lib/clamav}}, but {{ic|/etc/clamd.conf}} (default directory) pointing to {{ic|/usr/share/clamav}}, or other directory. Edit in {{ic|/etc/clamd.conf}} and replace with the same DatabaseDirectory like in {{ic|/etc/freshclam.conf}}. After that clamav will start up succesfully.
  
 
=== Error: Can't create temporary directory ===
 
=== Error: Can't create temporary directory ===

Latest revision as of 19:34, 16 May 2016

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.

Installation

ClamAV can be installed with package clamav.

Updating database

Update the virus definitions with:

# freshclam

The database files are saved in:

/var/lib/clamav/daily.cvd
/var/lib/clamav/main.cvd
/var/lib/clamav/bytecode.cvd

The virus definition updater service is called freshclamd.service. Consider starting it and enabling it to start at boot so that the virus definitions are kept recent.

Starting the daemon

Consider updating the database before starting the service for the first time or you will run into troubles/errors which will prevent ClamAV to start correctly.

The service is called clamd.service. Read Daemons for more information about starting it and enabling it to start at boot. You will need to run freshclam prior to starting the service.

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.

$ wget -O- http://www.eicar.org/download/eicar.com.txt | clamscan -

The output must include:

stdin: Eicar-Test-Signature FOUND

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 clamav-unofficial-sigsAUR and configure it in /etc/clamav-unofficial-sigs/user.conf.

This will add signatures/databases from e.g. MalwarePatrol, SecuriteInfo, Yara, Linux Malware Detect,...

Scan for viruses

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

$ clamscan myfile
$ clamscan --recursive=yes --infected /home # or -r -i
$ clamscan --recursive=yes --infected --exclude-dir='^/sys|^/proc|^/dev|^/lib|^/bin|^/sbin' /

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.

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

Using the milter

Copy /etc/clamav/clamav-milter.conf.sample to /etc/clamav/clamav-milter.conf and adjust it to your needs. For example:

/etc/clamav/clamav-milter.conf
MilterSocket /run/clamav/clamav-milter.sock
MilterSocketMode 660
FixStaleSocket yes
User clamav
PidFile /run/clamav/clamav-milter.pid
TemporaryDirectory /tmp
ClamdSocket unix:/var/lib/clamav/clamd.sock
LogSyslog yes
LogInfected Basic

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

/etc/systemd/system/clamav-milter.service
[Unit]
Description='ClamAV Milter'
After=clamd.service

[Service]
Type=forking
ExecStart=/usr/bin/clamav-milter --config-file /etc/clamav/clamav-milter.conf

[Install]
WantedBy=multi-user.target

Enable and start the service.

Troubleshooting

Error: Clamd was NOT notified

If you get the following messages after running freshclam:

WARNING: Clamd was NOT notified: Cannot connect to clamd through 
/var/lib/clamav/clamd.sock connect(): No such file or directory

Add a sock file for ClamAV:

# touch /var/lib/clamav/clamd.sock
# chown clamav:clamav /var/lib/clamav/clamd.sock

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

LocalSocket /var/lib/clamav/clamd.sock

Save the file and restart the daemon

Error: No supported database files found

If you get the next error when starting the daemon:

LibClamAV Error: cli_loaddb(): No supported database files found
in /var/lib/clamav ERROR: Not supported data format

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

Error: Can't create temporary directory

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

# can't create temporary directory

Correct permissions:

# chown UID:GID /var/lib/clamav & chmod 755 /var/lib/clamav