简介:ClamAV是一个开源防病毒工具包,专为邮件网关上的电子邮件扫描而设计。它提供了许多实用程序,包括一个灵活且可扩展的多线程守护进程、一个命令行扫描程序和用于自动数据库更新的高级工具。该软件包的核心是以共享库的形式提供的防病毒引擎。支持扫描各主流文件格式,如zip、tar、img、png、iso、pkg、html、pdf、邮件附件等等。
历史攻略:
Python:os.walk() 方法
Python:shutil模块使用
Python:glob模块使用
Python:浏览网页暴露多少信息?
代码质量管理平台SonarQube:002 - sonar-scanner扫描python代码
项目github地址:
https://github.com/Cisco-Talos/clamav
跨平台、支持不同OS:
GNU/Linux
# Alpine
3.17 (x86_64)
# Ubuntu
18.04 (x86_64, i386)
20.04 (x86_64)
# Debian
10 (x86_64, i386)
11 (x86_64, i386)
# CentOS
7 (x86_64, i386)
# Fedora
31 (x86_64)
33 (x86_64)
# openSUSE
15 Leap (x86_64)
# UNIX
FreeBSD
12 (x86_64)
13 (x86_64)
# macOS
10.13 High Sierra (Intel x86_64)
10.15 Catalina (Intel x86_64)
11.5 Big Sur (Intel x86_64, arm64 Apple M1)
# Windows
7 (x86_64, i386)
10 (x86_64, i386)
安装:以Ubuntu为例
# 更新系统软件包索引
sudo apt-get update
# 安装ClamAV
sudo apt-get install clamav
# 更新病毒数据库(请确保你的服务器可以正常连接到互联网)
sudo freshclam
# 扫描整个文件系统(根据需要,这可能需要一些时间)
sudo clamscan -r /
# 扫描指定文件夹
sudo clamscan -r /path/to/directory
# 扫描指定文件
sudo clamscan /path/to/file
# 扫描完成后,你可以设置定时任务自动执行病毒扫描
# 创建一个新的Cron任务
crontab -e
# 添加以下行以每天凌晨1点自动执行病毒扫描
0 1 * * * /usr/bin/freshclam --quiet
0 1 * * * /usr/bin/clamscan -r --quiet /
针对更新病毒库,抛出异常的解决办法:
# 查询 运行 clamav的进程
ps aux | grep "clamav"
# 将运行clamav的进程杀死
sudo kill -9 pid
# 重新更新病毒库
sudo freshclam
参考运行结果:
root@Labtsk-3FI0HAN5:/home/tom# freshclam
ERROR: /var/log/clamav/freshclam.log is locked by another process
ERROR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log).
ERROR: initialize: libfreshclam init failed.
ERROR: Initialization error!
root@Labtsk-3FI0HAN5:/home/tom# ps aux | grep "clamav"
clamav 1042 14.2 0.4 134428 18040 ? Ss 01:46 1:31 /usr/bin/freshclam -d --foreground=true
root 3236 0.0 0.0 4028 2160 pts/3 S+ 01:57 0:00 grep --color=auto clamav
root@Labtsk-3FI0HAN5:/home/tom# kill -9 1042
root@Labtsk-3FI0HAN5:/home/tom# freshclam
Sun Jun 16 01:57:16 2024 -> ClamAV update process started at Sun Jun 16 01:57:16 2024
Sun Jun 16 01:57:16 2024 -> daily.cvd database is up-to-date (version: 27307, sigs: 2063014, f-level: 90, builder: raynman)
Sun Jun 16 01:57:16 2024 -> main.cvd database is up-to-date (version: 62, sigs: 6647427, f-level: 90, builder: sigmgr)
Sun Jun 16 01:57:16 2024 -> bytecode.cvd database is up-to-date (version: 335, sigs: 86, f-level: 90, builder: raynman)
root@Labtsk-3FI0HAN5:/home/tom# sudo clamscan -r /home/tom/test_clamav
/home/tom/test_clamav/main.py: Empty file
/home/tom/test_clamav/project.yaml: Empty file
----------- SCAN SUMMARY -----------
Known viruses: 8694597
Engine version: 0.103.11
Scanned directories: 1
Scanned files: 0
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 313.790 sec (5 m 13 s)
Start Date: 2024:06:16 01:59:22
End Date: 2024:06:16 02:04:35
root@Labtsk-3FI0HAN5:/home/tom#