|
| 1 | +================================================== |
| 2 | +ClamAV Installation and Configuration |
| 3 | +================================================== |
| 4 | + |
| 5 | +.. contents:: Table of Contents |
| 6 | + :depth: 2 |
| 7 | + :local: |
| 8 | + |
| 9 | +Introduction |
| 10 | +============ |
| 11 | + |
| 12 | +ClamAV is an open-source antivirus engine designed to detect trojans, viruses, malware, and other |
| 13 | +malicious threats on Linux systems. It provides a robust scanning mechanism that can identify and |
| 14 | +quarantine infected files by comparing them against continuously updated virus signature databases. |
| 15 | +ClamAV supports scanning of various file formats including compressed files, executables, documents, |
| 16 | +and email attachments. |
| 17 | + |
| 18 | +The primary purpose of ClamAV is to protect systems from malware infections that could compromise |
| 19 | +system integrity, steal sensitive data, or disrupt operations. By scanning files and directories for known |
| 20 | +malicious patterns, ClamAV helps identify threats before they can execute or spread, reducing the risk |
| 21 | +of data breaches, ransomware attacks, or system compromise. |
| 22 | + |
| 23 | +You might want to use ClamAV if you need to: |
| 24 | + |
| 25 | +- scan files and directories for viruses and malware on embedded Linux systems. |
| 26 | +- verify the integrity of files transferred via USB, network, or other external sources. |
| 27 | +- detect malicious code before it can execute on critical industrial control systems. |
| 28 | +- maintain compliance with security policies that require antivirus protection. |
| 29 | + |
| 30 | +ClamAV is especially valuable in environments where file transfers occur frequently or where systems |
| 31 | +process data from external sources. Its command-line interface, low resource footprint, and flexible |
| 32 | +scanning options make it well-suited for embedded Linux Real-Time systems like NI's industrial controllers. |
| 33 | + |
| 34 | +.. note:: |
| 35 | + This guide covers NILRT-specific installation and configuration. For comprehensive documentation |
| 36 | + on all ClamAV commands, options, and advanced usage, refer to the official |
| 37 | + `ClamAV User Manual <https://docs.clamav.net/manual/Usage.html>`_. |
| 38 | + |
| 39 | +Installation |
| 40 | +============ |
| 41 | + |
| 42 | +ClamAV requires the NI Linux RT System Image version 11.4 (build 26.0.0) or newer. |
| 43 | + |
| 44 | +Installing ClamAV |
| 45 | +----------------- |
| 46 | + |
| 47 | +To install ClamAV on your NILRT system, use the opkg package manager: |
| 48 | + |
| 49 | +.. code:: bash |
| 50 | +
|
| 51 | + opkg update |
| 52 | + opkg install clamav clamav-freshclam |
| 53 | +
|
| 54 | +This will install: |
| 55 | +- ``clamav``: The core ClamAV antivirus engine and scanner |
| 56 | +- ``clamav-freshclam``: The utility for updating virus signature databases |
| 57 | + |
| 58 | +After installation, you'll need to configure ClamAV according to your requirements. See the Configuration section below for details. |
| 59 | + |
| 60 | + |
| 61 | +Verifying Installation |
| 62 | +---------------------- |
| 63 | + |
| 64 | +After installation, verify that ClamAV is properly installed and configured: |
| 65 | + |
| 66 | +**Quick Version Check:** |
| 67 | + |
| 68 | +.. code:: bash |
| 69 | +
|
| 70 | + clamscan --version |
| 71 | +
|
| 72 | +You should see output showing the ClamAV version (1.4.3 or newer) and configuration paths. |
| 73 | + |
| 74 | +Configuration |
| 75 | +============= |
| 76 | + |
| 77 | +ClamAV uses configuration files to control its behavior for virus scanning and signature updates. |
| 78 | +The main configuration files are: |
| 79 | + |
| 80 | +- ``/usr/etc/freshclam.conf``: Configuration for the freshclam signature updater |
| 81 | +- ``/etc/clamav/clamd.conf``: Configuration for the ClamAV daemon (optional) |
| 82 | +- ``/var/lib/clamav/``: Directory containing virus signature databases |
| 83 | + |
| 84 | +Updating Virus Signatures |
| 85 | +-------------------------- |
| 86 | + |
| 87 | +Before scanning files, you need to download the latest virus signature databases. ClamAV provides the following methods to update signatures: |
| 88 | + |
| 89 | +**Method 1: Online Update (Recommended)** |
| 90 | + |
| 91 | +If your target has internet connectivity, update signatures using freshclam with superuser permissions: |
| 92 | + |
| 93 | +.. code:: bash |
| 94 | +
|
| 95 | + freshclam |
| 96 | +
|
| 97 | +This downloads the latest virus definitions from ClamAV's mirror servers. |
| 98 | + |
| 99 | +**Method 2: Offline Update (For Systems Without Internet Access)** |
| 100 | + |
| 101 | +For systems without internet connectivity, you need to manually download the signature databases on a system with internet access, then transfer them to your NILRT target. |
| 102 | + |
| 103 | +**Option A: Using freshclam on another system** |
| 104 | + |
| 105 | +On a Linux system with internet access and ClamAV installed: |
| 106 | + |
| 107 | +.. code:: bash |
| 108 | +
|
| 109 | + # Download signatures to a specific directory |
| 110 | + freshclam --datadir=/tmp/clamav-db |
| 111 | + |
| 112 | + # Copy the downloaded files to your NILRT target |
| 113 | + # Transfer these files: bytecode.cvd, daily.cvd, main.cvd |
| 114 | +
|
| 115 | +**Option B: Using cvdupdate (Python utility)** |
| 116 | + |
| 117 | +CVDUpdate is a python utility to download and update ClamAV Virus Databases and database patch files for the purposes of supporting the offline systems. |
| 118 | +This utility is provided and recommended by the ClamAV project and licensed under Apache-2.0 license. Refer to the Additional Resources section for more information. |
| 119 | +User can use cvdupdate utility on any system with internet access and then copy the downloaded signature files to the NILRT target. |
| 120 | + |
| 121 | +.. code:: bash |
| 122 | +
|
| 123 | + # Install cvdupdate |
| 124 | + python -m pip install --user cvdupdate |
| 125 | +
|
| 126 | + # (optional) You may wish to customize where the databases are stored |
| 127 | + cvd config set --dbdir <your path> |
| 128 | + |
| 129 | + # Download the latest signatures |
| 130 | + cvd update |
| 131 | +
|
| 132 | + # Signatures are downloaded to: ~/.cvdupdate/database/ |
| 133 | + # Copy these .cvd files to your NILRT target |
| 134 | +
|
| 135 | +**Transferring Signatures to NILRT Target** |
| 136 | + |
| 137 | +Once you have the signature files (.cvd or .cld files), copy them to your NILRT target's ClamAV database directory: |
| 138 | + |
| 139 | +.. code:: bash |
| 140 | +
|
| 141 | + # Copy files to the target (via SCP, USB, or other method) |
| 142 | + # Then on the NILRT target: |
| 143 | + cp *.cvd /var/lib/clamav/ |
| 144 | + chown clamav:clamav /var/lib/clamav/*.cvd |
| 145 | + chmod 644 /var/lib/clamav/*.cvd |
| 146 | +
|
| 147 | +The typical signature files you need are: |
| 148 | + - ``main.cvd`` or ``main.cld`` - Main virus database |
| 149 | + - ``daily.cvd`` or ``daily.cld`` - Daily updates |
| 150 | + - ``bytecode.cvd`` or ``bytecode.cld`` - Bytecode signatures |
| 151 | + |
| 152 | + |
| 153 | +Scanning Files and Directories |
| 154 | +=============================== |
| 155 | + |
| 156 | +ClamAV can be used for Scheduled periodic scan or Manual scan. |
| 157 | + |
| 158 | +To schedule periodic automated scans on your NILRT system, configure the ``/etc/cron.d/clamav-scan`` file. |
| 159 | +For more information on scheduling and cron configuration, refer to the `ClamAV User Manual <https://docs.clamav.net/manual/Usage.html>`_. |
| 160 | + |
| 161 | +ClamAV is configured for manual operation on NILRT systems. Use the following commands to scan files and directories for malware. |
| 162 | + |
| 163 | +Using the NILRT's Wrapper Script |
| 164 | +--------------------------------------- |
| 165 | + |
| 166 | +The ``clamav-scan`` wrapper script handles memory management automatically and provides a simplified interface: |
| 167 | + |
| 168 | +**Basic Usage:** |
| 169 | + |
| 170 | +.. code:: bash |
| 171 | +
|
| 172 | + # Scan current directory |
| 173 | + clamav-scan . |
| 174 | + |
| 175 | + # Scan a specific directory |
| 176 | + clamav-scan /path/to/scan |
| 177 | + |
| 178 | + # Scan a specific file |
| 179 | + clamav-scan /path/to/file.txt |
| 180 | +
|
| 181 | +**Advanced Options:** |
| 182 | + |
| 183 | +.. code:: bash |
| 184 | +
|
| 185 | + # Set custom swap file size (in MB) |
| 186 | + clamav-scan --swap-size 2048 /path/to/scan |
| 187 | +
|
| 188 | +All standard ``clamscan`` options can be passed to the wrapper script. |
| 189 | + |
| 190 | +The wrapper script automatically: |
| 191 | + |
| 192 | +- Creates temporary swap files (default size is 1024 MB) if system memory is insufficient (< 3GB) |
| 193 | +- Passes through any additional ``clamscan`` options |
| 194 | + |
| 195 | +Using clamscan Directly |
| 196 | +----------------------- |
| 197 | + |
| 198 | +For more control over scanning options, use ``clamscan`` directly: |
| 199 | + |
| 200 | +.. code:: bash |
| 201 | +
|
| 202 | + # Recursive scan of a directory |
| 203 | + clamscan -r /path/to/scan |
| 204 | + |
| 205 | + # Scan and show only infected files |
| 206 | + clamscan -r -i /path/to/scan |
| 207 | + |
| 208 | + # Scan with verbose output |
| 209 | + clamscan -r -v /path/to/scan |
| 210 | + |
| 211 | + # Scan with custom log file |
| 212 | + clamscan -r --log=/tmp/my-scan.log /path/to/scan |
| 213 | +
|
| 214 | +Common clamscan options: |
| 215 | + |
| 216 | +- ``-r`` : Recursive scan |
| 217 | +- ``-i`` : Show only infected files |
| 218 | +- ``-v`` : Verbose output |
| 219 | +- ``--log=FILE`` : Save results to log file |
| 220 | +- ``--max-filesize=SIZE`` : Skip files larger than SIZE |
| 221 | +- ``--exclude-dir=PATTERN`` : Exclude directories matching pattern |
| 222 | + |
| 223 | +.. note:: |
| 224 | + All commands require root privileges to access all files and directories on the system. |
| 225 | + |
| 226 | +Additional Resources |
| 227 | +==================== |
| 228 | + |
| 229 | +**Official ClamAV Documentation:** |
| 230 | + |
| 231 | +- `ClamAV User Manual <https://docs.clamav.net/manual/Usage.html>`_ - Complete guide to all ClamAV commands and options |
| 232 | +- `ClamAV Official Documentation <https://docs.clamav.net/>`_ - Main documentation portal |
| 233 | +- `Scanning Usage Guide <https://docs.clamav.net/manual/Usage/Scanning.html>`_ - Comprehensive scanning options and examples |
| 234 | +- `Freshclam Configuration <https://docs.clamav.net/manual/Usage/Configuration.html#freshclamconf>`_ - Signature update configuration |
| 235 | +- `Signature Management <https://docs.clamav.net/manual/Usage/SignatureManagement.html>`_ - Managing virus definition databases |
| 236 | +- `ClamAV FAQ <https://docs.clamav.net/faq/index.html>`_ - Frequently asked questions and troubleshooting tips |
| 237 | +- `CVDUpdate Utility <https://pypi.org/project/cvdupdate/>`_ - Python utility for offline signature updates |
0 commit comments