ClamAV (virus scan)
ClamAV from Debian for the virus scan of uploads: clamd on the Unix socket /run/clamav/clamd.ctl only (the app streams a file to it, INSTREAM), signatures kept current by freshclam. Needs about 2 GB of RAM more than the app (1 GB in use, 2 GB for a minute while it reloads new signatures)
Add to a guest
In the guest as root – container and VM alike:
update --add-modules clamavRuns a normal update and installs the module on the way.
From the Proxmox node, without logging in:
pct exec <ID> -- update --add-modules clamav # container
ssh root@<IP> update --add-modules clamavChoose when creating a guest
Without a dialog, on the Proxmox node:
IAC_NONINTERACTIVE=1 var_modules=auto-update,clamav \
bash -c "$(curl -fsSL https://haypack.dev/<app>/ct.sh)"var_modules replaces the app's preselection – keep auto-update in the list if you want it. Interactive: choose “advanced” in the dialog, or tick the module in the generator on the app page.
Remove
update --remove-modules clamavRemoves the module's packages, services, firewall rules and configuration again. Data stays.
Details
ClamAV from Debian scans uploads for malware. clamd listens on the
Unix socket /run/clamav/clamd.ctl only – no TCP port, nothing reachable from the network. The app
in the same guest streams a file to it and gets OK or the name of the finding; freshclam keeps
the signatures current (several times a day, about 110 MB on disk).
How much memory it needs
clamd keeps all signatures in memory: about 1 GB while it runs, up to 2 GB for a minute
whenever freshclam brings new signatures and clamd reloads them (measured with 3.6 million
signatures in Debian 13). Plan 2 GB more than the app needs – set defaults.ram in the iac.json
of the app accordingly. With too little memory the kernel stops clamd during a reload.
The first install downloads the signatures (about 110 MB) and waits for them – up to 15 minutes;
clamd loads them in a minute or two, until then a scan waits at the socket.
Use it in an app
The socket belongs to the group clamav, mode 0660. The user of the app joins the group:
- name: The user of the app may use clamd
ansible.builtin.user:
name: myapp
groups: clamav
append: true
Then stream the file to the socket (INSTREAM) – clamd needs no rights to the files of the app.
Libraries exist for every language (e.g. clamd for Python, clamscan for Node.js). Read the
answer of clamd and take only a reply that ends in OK as clean: … FOUND is a finding,
… ERROR (clamd not ready, INSTREAM size limit exceeded, …) means the file was not scanned.
By hand, for a look:
clamdscan --ping 10:5 # PONG: clamd is ready (10 tries, 5 s apart)
clamdscan --stream --no-summary document.pdf # OK, or: document.pdf: <name> FOUND
Do not use clamdscan as the check of an app: in version 1.4.6 it prints OK and exits 0 for a
file over the size limit, although clamd answered size limit exceeded. ERROR.
Settings
In /etc/iac/settings.env, then update:
clamav_max_size=100 # MB: largest file to scan (StreamMaxLength, MaxFileSize, MaxScanSize)
clamav_max_scan_time=120 # seconds one scan may take (MaxScanTime)
clamav_alert_encrypted=no # yes: report an encrypted archive or PDF as a finding
Debian limits a stream to 25 MB – larger uploads would end with size limit exceeded, so the
default is 100 MB. An encrypted PDF or archive cannot be scanned; by default it is not a finding
(it is normal in business mail). The app should mark it as “not scannable” instead of “clean”.
Everything else in /etc/clamav/clamd.conf stays as Debian ships it; iac only sets the keys above
and LocalSocketMode.
Limits
ClamAV finds known malware. It does not find new, unpublished malware, and it cannot look into encrypted files. It is one layer – the app should also limit file types and sizes.
Checks
systemctl status clamav-daemon clamav-freshclam
journalctl -u clamav-freshclam -n 20 # signature updates
tail /var/log/clamav/clamav.log # clamd
When the module is removed, ClamAV and its signatures are removed.
ClamAV aus Debian prüft Uploads auf Schadsoftware. clamd lauscht nur
auf dem Unix-Socket /run/clamav/clamd.ctl – kein TCP-Port, nichts aus dem Netz erreichbar. Die App
im selben Gast schickt eine Datei an den Socket und bekommt OK oder den Namen des Fundes zurück;
freshclam hält die Signaturen aktuell (mehrmals am Tag, etwa 110 MB auf der Platte).
Wie viel Arbeitsspeicher es braucht
clamd hält alle Signaturen im Speicher: etwa 1 GB im Betrieb, bis zu 2 GB für eine Minute,
wenn freshclam neue Signaturen bringt und clamd sie neu lädt (gemessen mit 3,6 Millionen
Signaturen unter Debian 13). Rechne mit 2 GB mehr, als die App braucht – defaults.ram in der
iac.json der App entsprechend setzen. Bei zu wenig Speicher beendet der Kernel clamd während des
Neuladens.
Die erste Installation lädt die Signaturen herunter (etwa 110 MB) und wartet darauf – bis zu 15
Minuten. clamd lädt sie in ein bis zwei Minuten, bis dahin wartet ein Scan am Socket.
In einer App nutzen
Der Socket gehört der Gruppe clamav, Modus 0660. Der Benutzer der App tritt der Gruppe bei:
- name: The user of the app may use clamd
ansible.builtin.user:
name: myapp
groups: clamav
append: true
Danach die Datei an den Socket streamen (INSTREAM) – clamd braucht keine Rechte an den Dateien
der App. Für jede Sprache gibt es Bibliotheken (z. B. clamd für Python, clamscan für Node.js).
Die Antwort von clamd lesen und nur eine Antwort, die auf OK endet, als sauber werten:
… FOUND ist ein Fund, … ERROR (clamd nicht bereit, INSTREAM size limit exceeded, …) heißt:
die Datei wurde nicht geprüft.
Von Hand, zum Ansehen:
clamdscan --ping 10:5 # PONG: clamd ist bereit (10 Versuche, 5 s Abstand)
clamdscan --stream --no-summary dokument.pdf # OK oder: dokument.pdf: <Name> FOUND
clamdscan ist keine Prüfung für eine App: In Version 1.4.6 zeigt es OK und endet mit 0, wenn die
Datei über dem Größenlimit liegt, obwohl clamd mit size limit exceeded. ERROR geantwortet hat.
Einstellungen
In /etc/iac/settings.env, danach update:
clamav_max_size=100 # MB: größte Datei, die geprüft wird (StreamMaxLength, MaxFileSize, MaxScanSize)
clamav_max_scan_time=120 # Sekunden, die ein Scan dauern darf (MaxScanTime)
clamav_alert_encrypted=no # yes: verschlüsseltes Archiv oder PDF als Fund melden
Debian begrenzt einen Stream auf 25 MB – größere Uploads enden mit size limit exceeded, deshalb
ist der Standard 100 MB. Ein verschlüsseltes PDF oder Archiv lässt sich nicht prüfen; standardmäßig
ist es kein Fund (im Geschäftsverkehr ist es normal). Die App sollte es als „nicht prüfbar“
ausweisen, nicht als „sauber“. Alles Übrige in /etc/clamav/clamd.conf bleibt, wie Debian es
ausliefert; iac setzt nur die genannten Schlüssel und LocalSocketMode.
Grenzen
ClamAV findet bekannte Schadsoftware. Neue, unveröffentlichte erkennt es nicht, und in verschlüsselte Dateien kann es nicht hineinsehen. Es ist eine Schicht – die App sollte zusätzlich Dateitypen und Größen begrenzen.
Prüfen
systemctl status clamav-daemon clamav-freshclam
journalctl -u clamav-freshclam -n 20 # Signatur-Updates
tail /var/log/clamav/clamav.log # clamd
Wird das Modul entfernt, verschwinden ClamAV und seine Signaturen.