Virus Scanning¶
Complete guide to Mailborder's antivirus system powered by ClamAV.
Overview¶
Mailborder scans all email attachments and content for viruses, malware, and other threats using ClamAV - an open-source antivirus engine with:
- 500,000+ virus signatures
- Daily signature updates
- Archive scanning (ZIP, RAR, 7z, etc.)
- Heuristic detection
- Malware family identification
Scanning Process¶
Email Arrives
↓
Extract All Attachments
↓
Decompress Archives (recursive)
↓
Scan Each File with ClamAV
↓
Check Against Signatures
↓
Heuristic Analysis
↓
Verdict: Clean / Infected
↓
Action: Deliver / Quarantine / Reject
ClamAV Configuration¶
Service Status¶
Check ClamAV status:
Expected output:
● clamav-daemon.service - Clam AntiVirus userspace daemon
Loaded: loaded
Active: active (running) since Mon 2025-01-13 10:23:45 UTC
Main PID: 1234 (clamd)
Memory: 512.5M
CGroup: /system.slice/clamav-daemon.service
└─1234 /usr/sbin/clamd --foreground=true
View ClamAV version:
Signature Database¶
Check signature version:
Example output:
File: daily.cvd
Build time: 13 Jan 2025 10:15 +0000
Version: 27432
Signatures: 2,045,873
Functionality level: 90
Builder: neo
MD5: 8c4a5e9d2b1f3a6e7c8d9e0f1a2b3c4d
Update signatures manually:
Expected output:
ClamAV update process started at Mon Jan 13 14:30:15 2025
daily.cvd database is up-to-date (version: 27432, sigs: 2045873)
main.cvd database is up-to-date (version: 62, sigs: 6647427)
bytecode.cvd database is up-to-date (version: 334, sigs: 92)
Automatic Updates¶
Check freshclam configuration:
Key settings:
DatabaseDirectory /var/lib/clamav
UpdateLogFile /var/log/clamav/freshclam.log
LogTime yes
DatabaseOwner clamav
DNSDatabaseInfo current.cvd.clamav.net
DatabaseMirror database.clamav.net
Checks 24
Enable automatic updates:
Monitor update log:
Scan Configuration¶
Mailborder Integration¶
View antivirus settings:
Enable/disable virus scanning:
Scan action on detection:
Apply changes:
File Type Scanning¶
File extensions to scan:
Commonly scanned types: - Executables: .exe, .dll, .com, .bat, .cmd, .scr - Scripts: .js, .vbs, .ps1, .sh - Documents: .doc, .docx, .xls, .xlsx, .pdf - Archives: .zip, .rar, .7z, .tar.gz, .bz2 - Images: .jpg, .png (can contain exploits)
Archive Scanning¶
Enable recursive archive scanning:
sudo mb-config set antivirus.scan_archives true
sudo mb-config set antivirus.max_recursion 16
sudo mb-config set antivirus.max_files 10000
Maximum archive size to scan:
Scan nested archives:
Heuristic Detection¶
Enable heuristic scanning:
Heuristic sensitivity (0-4):
sudo mb-config set antivirus.heuristic_level 3
# 0 = disabled
# 1 = low (fewer false positives)
# 2 = medium (balanced)
# 3 = high (more aggressive)
# 4 = very high (may cause false positives)
Detect potentially unwanted applications (PUA):
Blocked File Extensions¶
Default Blocked Extensions¶
View blocked extensions:
Common blocked types:
.exe - Windows executable
.dll - Windows library
.scr - Screen saver (often malware)
.com - DOS executable
.bat - Batch script
.cmd - Command script
.pif - Program Information File
.vbs - Visual Basic Script
.js - JavaScript (can be malicious)
.jar - Java archive
Managing Blocked Extensions¶
Add extension to blocklist:
sudo mb-antivirus-block-ext add .exe
sudo mb-antivirus-block-ext add .scr
sudo mb-antivirus-block-ext add .vbs
Remove extension from blocklist:
Block with custom message:
Extension Blocking Best Practices¶
Balance Security and Usability
Blocking too many extensions can disrupt legitimate business operations. Work with users to identify necessary file types.
Recommended blocks: - High risk: .exe, .scr, .com, .bat, .cmd, .pif, .vbs - Medium risk: .jar, .js (unless required) - Context-dependent: .zip (if used for malware delivery)
Don't block blindly: - .pdf (very common, low risk with modern readers) - .docx, .xlsx (legitimate business documents) - .jpg, .png (images, very common)
Manual Virus Scanning¶
Scan Email File¶
Test single email:
Example output:
/path/to/email.eml: OK
----------- SCAN SUMMARY -----------
Infected files: 0
Time: 0.045 sec (0 m 0 s)
Start Date: 2025:01:13 14:35:22
End Date: 2025:01:13 14:35:22
Infected email example:
/path/to/infected.eml: Win.Trojan.Agent-1234567 FOUND
----------- SCAN SUMMARY -----------
Infected files: 1
Time: 0.052 sec (0 m 0 s)
Scan Directory¶
Scan mailbox directory:
Scan with file removal:
Scan and move infected:
Test Virus Detection¶
EICAR test file:
# Create EICAR test virus
echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > /tmp/eicar.txt
# Scan it
sudo clamdscan /tmp/eicar.txt
Expected output:
EICAR Test
EICAR is a safe test file recognized by all antivirus software. Use it to verify scanning is working.
Virus Whitelisting¶
By File Hash¶
Whitelist known-safe file:
# Calculate hash
sha256sum /path/to/safe-file.exe
# Output: d41d8cd98f00b204e9800998ecf8427e
sudo mb-antivirus-whitelist add-hash d41d8cd98f00b204e9800998ecf8427e
Whitelist by MD5:
By Sender¶
Whitelist attachments from trusted sender:
sudo mb-antivirus-whitelist add-sender trusted@partner.com
sudo mb-antivirus-whitelist add-sender @corporate-domain.com
Whitelist with reason:
sudo mb-antivirus-whitelist add-sender vendor@company.com \
--reason "Approved software vendor - ticket #12345"
By Detection Name¶
Whitelist false positive:
Use Carefully
Whitelisting by detection name can allow actual malware. Only use for confirmed false positives.
List Whitelist Entries¶
View all whitelist entries:
Example output:
Hash Whitelist:
d41d8cd98f00b204e9800998ecf8427e (SHA256) - Added 2025-01-10
Sender Whitelist:
trusted@partner.com - Added 2025-01-11
@corporate-domain.com - Added 2025-01-12
Signature Whitelist:
PUA.Win.Packer.Upx-1 - Added 2025-01-13
Performance Tuning¶
Scan Limits¶
Maximum file size to scan:
Maximum scan time:
Skip scan for large files:
ClamAV Optimization¶
Edit ClamAV config:
Performance settings:
MaxThreads 12 # Match CPU cores
MaxFileSize 25M # Skip files larger than this
MaxScanSize 100M # Maximum data to scan
MaxRecursion 16 # Archive recursion depth
MaxFiles 10000 # Maximum files in archive
StreamMaxLength 25M # Maximum stream size
Restart ClamAV:
Memory Management¶
Check ClamAV memory usage:
ClamAV typically uses 400-600 MB RAM for signature database.
If memory is constrained:
Add:
Monitoring and Statistics¶
Real-time Monitoring¶
Watch virus detection log:
Watch ClamAV log:
Statistics¶
View virus detection statistics:
Example output:
Period: Last 30 days
Total scans: 125,430
Infected: 243 (0.19%)
Clean: 125,187 (99.81%)
Top detections:
Win.Trojan.Agent-12345 45
Heur.Phishing.Email 32
Doc.Malware.Macro-678 28
Win.Ransomware.Bad 18
PUA.Win.Adware.Generic 15
By sender domain:
By virus family:
Signature Update Status¶
Check last update:
Update frequency:
Troubleshooting¶
ClamAV Not Starting¶
Check error logs:
Common issues:
-
Signature database missing:
-
Permission issues:
-
Port conflict:
Signature Updates Failing¶
Test connectivity:
Manual download:
cd /var/lib/clamav
sudo wget http://database.clamav.net/daily.cvd
sudo wget http://database.clamav.net/main.cvd
sudo chown clamav:clamav *.cvd
sudo systemctl restart clamav-daemon
Check freshclam config:
Scan Timeout Issues¶
Symptoms: - Emails stuck in queue - Timeout errors in logs
Solutions:
-
Increase timeout:
-
Reduce scan depth:
-
Skip large attachments:
False Positives¶
Symptoms: - Legitimate files detected as malware - Specific software always blocked
Solutions:
-
Verify detection:
-
Check detection name:
-
Whitelist by hash:
-
Report false positive: Visit: https://www.clamav.net/reports/fp
High Memory Usage¶
Check ClamAV memory:
If using >1GB:
-
Disable bytecode:
-
Reduce signature types:
-
Consider upgrading RAM (ClamAV needs 512MB minimum, 1GB+ recommended)
Best Practices¶
Initial Setup¶
-
Update signatures immediately:
-
Test with EICAR file:
-
Configure appropriate actions:
- Quarantine for review (recommended)
- Reject for high-security environments
-
Never use "discard" (no notification)
-
Enable automatic updates:
Ongoing Maintenance¶
-
Monitor signature updates daily:
-
Review detections weekly:
-
Check for false positives:
-
Update ClamAV monthly:
Security Recommendations¶
- Always scan archives - Malware often hidden in ZIP files
- Enable heuristics - Catches unknown threats
- Block dangerous extensions - .exe, .scr, .vbs, etc.
- Keep signatures updated - New threats appear daily
- Monitor quarantine - Review what's being caught
Performance Optimization¶
- Match MaxThreads to CPU cores
- Set reasonable file size limits (25 MB is typical)
- Use scan timeouts to prevent stalls
- Enable caching for frequently-scanned content
- Consider skipping images (low risk, high volume)
Integration with Other Systems¶
With Spam Detection¶
Virus scanning runs after spam detection:
Both must pass for email delivery.
With Quarantine System¶
Infected emails automatically quarantined:
Review and manage:
sudo mb-quarantine-extract <message-id> /tmp/for-analysis.eml
sudo mb-quarantine-delete <message-id>
With Reporting¶
Include in daily reports:
See Also¶
- Spam Detection - Spam filtering configuration
- Quarantine Management - Managing quarantined emails
- Email Flow - Complete processing pipeline
- Policy Enforcement - Email policies