DFIR · Malware scanning · Detection rules

ClamAV & YARA
command reference

Comprehensive overview of functions, commands and flags for both tools — tailored to Linux (Zorin / Ubuntu). Click a code example to copy it.

9core commands
60+flags & options
2integration methods
v1.x / v4.xClamAV / YARA
01

Installation

Packages from the Ubuntu/Zorin repo. clamav-daemon provides background scanning; clamtk is a GUI.

Install ClamAV + YARA + GUIapt
sudo apt update
sudo apt install clamav clamav-daemon clamtk yara -y
Packages: clamav (clamscan/freshclam), clamav-daemon (clamd/clamdscan), clamtk (GUI), yara (standalone engine).
02

freshclam

update

Fetches and updates virus definitions (main.cvd, daily.cvd, bytecode.cvd). Normally runs as a background service.

Manual update
# Stop the service first — otherwise it locks the database
sudo systemctl stop clamav-freshclam
sudo freshclam
sudo systemctl start clamav-freshclam
FlagFunktion
-vVerbose output during download
--daemon / -dRun as a background daemon with periodic checks
--checks=N / -c NNumber of database checks per day (daemon mode)
--datadir=PATHPath to the database directory (default /var/lib/clamav)
--config-file=PATHUse an alternative freshclam.conf
--show-progressShow a progress bar during download
--on-update-execute=CMDRun a command after a successful update
--list-mirrorsShow the status of known mirrors
03

clamscan

on-demand scanner

Standalone scanner. Loads the entire signature database into RAM on every run — thorough, but slow. Use clamdscan for frequent scanning.

Scan a folder, show finds only
clamscan -ri ~/Downloads
-r recursive · -i infected only
Scan with a beep on a find
clamscan -ri --bell ~
Move finds to quarantine
mkdir -p ~/quarantine
clamscan -ri --move=~/quarantine ~
Prefer --move over --remove
Scan the entire system
sudo clamscan -ri / --exclude-dir="^/sys|^/proc"
FlagFunktion
-r / --recursiveScan subdirectories recursively
-i / --infectedShow infected files only
-oSuppress OK results (errors/finds only)
--bellAudible signal on a find
--remove[=yes/no]Delete infected files (destructive — be careful)
--move=DIRMove finds to a quarantine folder
--copy=DIRCopy finds to a folder (keep the original)
-l FILE / --log=FILEWrite the scan result to a log file
-d FILE/DIR / --database=Use a custom signature database or YARA rule
--exclude=REGEXSkip files by regex on the path
--exclude-dir=REGEXSkip directories by regex
--include=REGEXScan matching files only
--max-filesize=NSkip files larger than N (e.g. 100M)
--max-scansize=NMax data scanned per file
--max-recursion=NMax depth in archive/compression layers
--scan-archive[=yes/no]Scan inside zip/rar/tar etc. (default yes)
--detect-pua[=yes]Detect Potentially Unwanted Applications
--scan-pe / --scan-elf / --scan-ole2Toggle scanning of specific file types on/off
--alert-encrypted[=yes]Flag encrypted archives/documents as suspicious
--alert-broken[=yes]Flag broken executable files
--alert-macros[=yes]Warn about macros in Office documents
--bytecode[=yes]Enable bytecode signatures (advanced detection)
--gen-jsonGenerate JSON metadata about scanned objects
-z / --allmatchContinue scanning a file after the first match
--stdoutSend all output to stdout (including errors)
-V / --versionShow version + database info
Exit codes: 0 = no finds · 1 = malware found · 2 = error. Useful in scripts: clamscan -ri ~ || echo "found!"
04

clamdscan

daemon client

Sends scan jobs to the running clamd daemon, which already has the database in memory. Markedly faster for repeated scans.

Fast scan via the daemon
clamdscan -r ~/Downloads
Multithreaded file passing
clamdscan --multiscan --fdpass ~
FlagFunktion
-m / --multiscanScan in parallel with multiple threads
--fdpassPass the file descriptor to the daemon (works around permission issues)
--streamStream file content to the daemon over the socket
-i / --infectedShow finds only
--move=DIR / --removeQuarantine / deletion as in clamscan
--config-file=PATHAlternative clamd.conf
-l FILELog file
05

clamd & service

daemon

The background daemon that keeps the database in RAM and offers on-access scanning (real-time monitoring of the file system via fanotify).

Enable & start the daemon
sudo systemctl enable --now clamav-daemon
On-access (real-time) scan
# requires OnAccess* in clamd.conf
sudo clamonacc -v
clamd.conf optionFunktion
OnAccessIncludePathDirectory monitored in real time
OnAccessPreventionBlock access to infected files (not just alert)
OnAccessExtraScanningAlso scan on create/move events
MaxThreadsNumber of scan threads in the daemon
LocalSocketUnix socket path for client communication
LogFile / LogTimeLog destination and timestamping
clamconf dumps the entire active configuration for troubleshooting: clamconf -n
06

sigtool

signatures

A tool to inspect databases and build your own signatures — useful when you create custom detection in DFIR cases.

CommandFunction
sigtool --info FILE.cvdShow metadata about a database file (version, signature count)
sigtool --unpack FILE.cvdUnpack the database into raw signature files
sigtool --md5 FILEGenerate an MD5 hash signature of a file
sigtool --sha256 FILEGenerate a SHA256 hash signature
sigtool --hex-dumpConvert input to hex for use in signatures
sigtool --find-sigs=REGEXFind signatures matching a pattern in the database
sigtool --vba FILEExtract VBA macros from Office documents
Custom hash signature: sigtool --sha256 malware.bin > min.hsb → place .hsb in /var/lib/clamav/ and scan with clamscan -d min.hsb
07

yara

detection rules

Pattern-based classification of files and processes from rules you write yourself. Standalone YARA supports all modules (pe, elf, hash, math, cuckoo and more) — unlike ClamAV's built-in YARA support.

Run a rule against a folder
yara -r rules.yar ~/case
Show matching strings
yara -r -s rules.yar ~/case
Compile rules (faster)
yarac rules.yar rules.cmp
yara -r rules.cmp ~/case
Scan a running process
sudo yara rules.yar $(pidof suspect_process)
YARA can scan PIDs directly — powerful for memory forensics
Ready-made rule sets: Neo23x0/signature-base (Florian Roth, motoren bag LOKI/THOR), Elastic protections-artifacts, Yara-Rules/rules. Clone and run recursively: yara -r signature-base/yara/ ~/case 2>/dev/null
08

YARA flag-reference

Complete flag overview for yara CLI.

FlagFunktion
-r / --recursiveScan directories recursively
-s / --print-stringsShow the strings that matched
-m / --print-metaShow metadata from the rule (author, ref, desc)
-g / --print-tagsShow rule tags
-e / --print-namespaceShow the namespace for a matched rule
-L / --print-statsShow statistics after scanning
-c / --countShow only the number of matches per rule
-d VAR=VALUEDefine an external variable for the rule
-t TAG / --tag=TAGShow only rules with this tag
-i ID / --identifier=Run only the rule with this name
-n / --negateShow files that do not match
-w / --no-warningsSuppress warnings
-f / --fast-scanFast scan (stop at the first match per string)
-x MODULE=FILEPass module data (e.g. cuckoo report) to the rule
-p N / --threads=NNumber of threads for parallel scanning
-a N / --timeout=NAbort scanning after N seconds
-z N / --max-strings-per-ruleCap on strings per rule
--max-process-memory-chunkChunk size for process scanning
-X N / --skip-larger=NSkip files larger than N bytes
--scan-listTreat the input as a file with a list of paths
-v / --versionShow the YARA version
Anatomy of a rule: rule name { meta: … strings: $a = "x" condition: $a } — the sections meta, strings and condition. Modules are imported at the top with import "pe".
09

YARA in ClamAV

integration

ClamAV can load YARA rules natively alongside its own signatures.

Place YARA rules in ClamAV's database
sudo cp rules.yar /var/lib/clamav/
# or scan ad hoc with -d:
clamscan -r -d rules.yar ~/case
Limitations: ClamAV's YARA engine does not support all features. Modules such as pe, hash, math and external variables don't work, and rules using them are rejected on load. For full functionality — including signature-base — use standalone YARA.
10

Automation

systemd / cron

Schedule weekly scanning and logging.

Weekly cron scan with logging
# crontab -e  → run every Sunday at 02:00
0 2 * * 0 clamdscan -r --fdpass /home \
  -l /var/log/clamav/weekly-$(date +\%F).log -i
Combined ClamAV + YARA wrapper
#!/usr/bin/env bash
TARGET="${1:-$HOME}"
TS=$(date +%F_%H%M)
clamdscan -r --fdpass -i "$TARGET" | tee "clam_$TS.log"
yara -r -m ~/yara/signature-base/yara/ "$TARGET" \
  2>/dev/null | tee "yara_$TS.log"