ClamAV ist ein Open-Source-Antivirus für Unix-Systeme. Er wird hauptsächlich für E-Mail-Scanning und Datei-Server eingesetzt.

Installation

Debian/Ubuntu

apt update
apt install clamav clamav-daemon clamav-freshclam

CentOS/RHEL

dnf install epel-release
dnf install clamav clamd clamav-update

Services aktivieren

systemctl enable --now clamav-daemon
systemctl enable --now clamav-freshclam

Signaturen aktualisieren

Automatisch mit freshclam

# Service läuft automatisch
systemctl status clamav-freshclam

Manuell

# Service stoppen
systemctl stop clamav-freshclam

# Manuell aktualisieren
freshclam

# Service starten
systemctl start clamav-freshclam

freshclam-Konfiguration

# /etc/clamav/freshclam.conf

# Update-Server
DatabaseMirror database.clamav.net

# Update-Intervall (12 pro Tag)
Checks 12

# Logging
UpdateLogFile /var/log/clamav/freshclam.log
LogVerbose yes

# Proxy (falls nötig)
# HTTPProxyServer proxy.example.com
# HTTPProxyPort 3128

Dateien scannen

Manueller Scan

# Einzelne Datei
clamscan /path/to/file

# Verzeichnis
clamscan -r /home/user/downloads/

# Mit Fortschritt
clamscan -r --bell -i /var/www/

# Infizierte Dateien löschen
clamscan -r --remove /path/to/scan/

# In Quarantäne verschieben
clamscan -r --move=/quarantine /path/to/scan/

Optionen

# Nur infizierte anzeigen
clamscan -r -i /var/www/

# Bestimmte Dateitypen
clamscan -r --include='\.exe$|\.zip$' /uploads/

# Dateien ausschließen
clamscan -r --exclude='\.log$' /var/

# Größenlimit
clamscan --max-filesize=100M -r /uploads/

Mit clamd (schneller)

# Über Socket
clamdscan /path/to/file

# Multithreaded
clamdscan --multiscan /var/www/

# Stream-Scan
clamdscan --stream /path/to/file

Daemon-Konfiguration

clamd.conf

# /etc/clamav/clamd.conf

# Socket
LocalSocket /var/run/clamav/clamd.ctl
LocalSocketMode 660

# Logging
LogFile /var/log/clamav/clamav.log
LogTime yes
LogVerbose yes

# Scanning
ScanPE yes
ScanELF yes
ScanOLE2 yes
ScanPDF yes
ScanHTML yes
ScanMail yes
ScanArchive yes

# Limits
MaxScanSize 100M
MaxFileSize 50M
MaxRecursion 16
MaxFiles 10000

# User
User clamav

Daemon neu starten

systemctl restart clamav-daemon

E-Mail-Integration

Mit Amavis

apt install amavisd-new
# /etc/amavis/conf.d/15-av_scanners

@av_scanners = (
  ['ClamAV-clamd',
    \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd.ctl"],
    qr/\bOK$/m, qr/\bFOUND$/m,
    qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ],
);

Mit Postfix

# /etc/postfix/main.cf

content_filter = smtp-amavis:[127.0.0.1]:10024

On-Access-Scanning

Kernel-Modul

# ClamAV On-Access-Scanning (nur neuere Versionen)
apt install clamav-daemon

# In clamd.conf
OnAccessIncludePath /home
OnAccessIncludePath /var/www
OnAccessExcludeUname clamav
OnAccessPrevention yes
OnAccessExtraScanning yes

Aktivieren

clamonacc --config-file=/etc/clamav/clamd.conf &

Geplante Scans

Cron-Job

# /etc/cron.d/clamav-scan

# Täglich um 3:00 Uhr
0 3 * * * root /usr/local/bin/clamav-scan.sh

Scan-Skript

#!/bin/bash
# /usr/local/bin/clamav-scan.sh

SCAN_DIR="/var/www /home"
LOG_FILE="/var/log/clamav/scan-$(date +\%Y\%m\%d).log"
QUARANTINE="/var/quarantine"

mkdir -p $QUARANTINE

# Scan durchführen
clamdscan --multiscan --quiet --infected --move=$QUARANTINE $SCAN_DIR >> $LOG_FILE 2>&1

# Bei Fund benachrichtigen
if [ $(grep -c "FOUND" $LOG_FILE) -gt 0 ]; then
    mail -s "ClamAV: Malware gefunden!" admin@example.com < $LOG_FILE
fi

# Alte Logs löschen
find /var/log/clamav -name "scan-*.log" -mtime +30 -delete
chmod +x /usr/local/bin/clamav-scan.sh

Quarantäne verwalten

Quarantäne-Verzeichnis

mkdir -p /var/quarantine
chmod 700 /var/quarantine
chown clamav:clamav /var/quarantine

Quarantäne prüfen

ls -la /var/quarantine/

# Datei-Info
file /var/quarantine/suspicious-file

Quarantäne bereinigen

# Ältere als 30 Tage löschen
find /var/quarantine -type f -mtime +30 -delete

Signaturen erweitern

Inoffizielle Signaturen

# SecuriteInfo
wget https://www.securiteinfo.com/get/signatures/securiteinfopub.hdb -O /var/lib/clamav/securiteinfo.hdb

# SaneSecurity (manuell oder mit clamav-unofficial-sigs)
apt install clamav-unofficial-sigs

Eigene Signaturen

# /var/lib/clamav/custom.ndb

# Format: Malware_Name:TargetType:Offset:Signatur
TestSig:0:*:68656c6c6f776f726c64
# Signatur-Datenbank neu laden
clamdscan --reload

Hash-basierte Signatur

# MD5-Hash erstellen
sigtool --md5 /path/to/malware > /var/lib/clamav/custom.hdb

# SHA256
sigtool --sha256 /path/to/malware > /var/lib/clamav/custom.hsb

Performance-Optimierung

Memory

# /etc/clamav/clamd.conf

# Weniger Speicher
MaxScanSize 50M
MaxFileSize 25M
MaxRecursion 10

Threads

# /etc/clamav/clamd.conf

# Mehr Threads
MaxThreads 20

Excludes

# Große Dateien ausschließen
clamscan --max-filesize=50M -r /var/www/

# Verzeichnisse ausschließen
clamscan -r --exclude-dir=/var/www/cache /var/www/

Monitoring

Status prüfen

# Daemon-Status
systemctl status clamav-daemon

# Verbindung testen
clamdscan --ping

# Version
clamscan --version
clamdscan --version

Log-Analyse

tail -f /var/log/clamav/clamav.log
tail -f /var/log/clamav/freshclam.log

Statistiken

# Scan-Statistiken
clamdscan --stats

Troubleshooting

Daemon startet nicht

# Logs prüfen
journalctl -u clamav-daemon -f

# Socket-Berechtigungen
ls -la /var/run/clamav/

# Manuell starten
clamd --foreground

freshclam-Fehler

# Manuell testen
freshclam -v

# DNS prüfen
dig database.clamav.net

# Proxy-Probleme
# HTTPProxyServer in freshclam.conf

Speicherprobleme

# clamd braucht viel RAM für Signaturen
# Min. 2-4 GB RAM empfohlen

# Oder Limits anpassen
MaxScanSize 50M
MaxFileSize 25M

Zusammenfassung

| Befehl | Funktion | |--------|----------| | clamscan -r /path | Verzeichnis scannen | | clamdscan /path | Mit Daemon scannen | | freshclam | Signaturen aktualisieren | | clamdscan --reload | Signaturen neu laden | | clamdscan --ping | Daemon-Status |

| Datei | Beschreibung | |-------|--------------| | /etc/clamav/clamd.conf | Daemon-Konfiguration | | /etc/clamav/freshclam.conf | Update-Konfiguration | | /var/lib/clamav/ | Signaturen | | /var/log/clamav/ | Logs |

Fazit

ClamAV ist der Standard-Antivirus für Linux-Server. Die Integration mit Mailservern über Amavis schützt vor E-Mail-Malware. Regelmäßige Signatur-Updates sind essentiell. Für Web-Server empfehlen sich geplante Scans und On-Access-Scanning. Beachten Sie den Speicherbedarf des clamd-Daemons bei der Server-Dimensionierung.