目录

一、clamAV介绍

二、安装ClamAV、clamdscan

三、手动更新数据库

四、用法

4.1、clamscan用法

4.2、clamdscan用法

五、python判定有无检测出病毒


一、clamAV介绍

ClamAV 杀毒是Linux平台最受欢迎的杀毒软件,ClamAV属于免费开源产品,支持多种平台,如:Linux/Unix、MAC OS X、Windows、OpenVMS。
ClamAV是基于病毒扫描的命令行工具,但同时也有支持图形界面的ClamTK工具
ClamAV主要用于邮件服务器扫描邮件。它有多种接口从邮件服务器扫描邮件,支持文件格式有如:ZIP、RAR、TAR、GZIP、BZIP2、HTML、DOC、PDF,、SIS CHM、RTF等等。
ClamAV可以自动升级病毒库,还可以从共享库中运行。命令行的界面让ClamAV运行流畅。
默认只能查出您计算机内的病毒,但是无法清除。
clamav 有两个命令:clamdscan、clamscan:
  • clamscan 命令:通用,不依赖服务,命令参数较多,执行速度稍慢
  • clamdscan 命令:是一个搭配clamd常驻服务的扫毒工具,功能非常类似clamscan,执行效率较高,但是可用的参数较少(因为部分功能是由 clamd 控制的)。不用带 -r ,默认会递归扫描子目录

二、安装ClamAV、clamdscan

apt -y install clamav clamtk clamav-daemon clamdscan device-tree-compiler
systemctl status clamav-daemon
重启服务:/etc/init.d/clamav-daemon restart
ps -ef| grep clamd
clamdscan依赖于clamd服务: /usr/sbin/clamd

三、手动更新数据库

病毒库位置/var/lib/clamav/*
1、暂时停止服务:sudo systemctl stop clamav-freshclam
2、运行freshclam:sudo freshclam 或者直接: /usr/bin/freshclam
3、重新启动服务:sudo systemctl start clamav-freshclam

四、用法

使用malware_scanner_eicar文件作为测试用例,文件内容如下:
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*

4.1、clamscan用法

1、clamscan --help
-i告诉ClamAV仅显示受感染的文件
-r`标志使扫描递归
--max-scansize=标志设置您希望ClamAV爬网的最大数据量。最大值是4000M请记住,这是正在读取的实际数据,而不是文件的大小。
--max-filesize=设置您要ClamAV扫描的文件的最大大小。

2、clamav的配置文件:/etc/clamav/freshclam.conf

# Automatically created by the clamav-freshclam postinst
# Comments will get lost when you reconfigure the clamav-freshclam package
DatabaseOwner clamav
UpdateLogFile /var/log/clamav/freshclam.log
LogVerbose false
LogSyslog false
LogFacility LOG_LOCAL6
LogFileMaxSize 0
LogRotate true
LogTime true
Foreground false
Debug false
MaxAttempts 5
DatabaseDirectory /var/lib/clamav  # 病毒库位置
DNSDatabaseInfo current.cvd.clamav.net
ConnectTimeout 30
ReceiveTimeout 0  # 增加ClamAV超时
TestDatabases yes
ScriptedUpdates yes
CompressLocalDatabase no
Bytecode true
NotifyClamd /etc/clamav/clamd.conf  # 配置
# Check for new database 24 times a day
Checks 24
DatabaseMirror db.local.clamav.net
DatabaseMirror database.clamav.net
3、扫描文件:clamscan eicar.com
4、扫描目录:clamscan -i -r --max-scansize=4000M --max-filesize=4000M ~/Downloads

4.2、clamdscan用法

1、 clamdscan --help
                      Clam AntiVirus: Daemon Client 0.103.5
           By The ClamAV Team: https://www.clamav.net/about.html#credits
           (C) 2022 Cisco Systems, Inc.
    clamdscan [options] [file/directory/-]
    --help              -h             Show this help
    --version           -V             Print version number and exit
    --verbose           -v             Be verbose
    --quiet                            Be quiet, only output error messages
    --stdout                           Write to stdout instead of stderr. Does not affect 'debug' messages.
                                       (this help is always written to stdout)
    --log=FILE          -l FILE        Save scan report in FILE
    --file-list=FILE    -f FILE        Scan files from FILE
    --ping              -p A[:I]       Ping clamd up to [A] times at optional interval [I] until it responds.
    --wait              -w             Wait up to 30 seconds for clamd to start. Optionally use alongside --ping to set attempts [A] and interval [I] to check clamd.
    --remove                           Remove infected files. Be careful!
    --move=DIRECTORY                   Move infected files into DIRECTORY
    --copy=DIRECTORY                   Copy infected files into DIRECTORY
    --config-file=FILE                 Read configuration from FILE.
    --allmatch            -z           Continue scanning within file after finding a match.
    --multiscan           -m           Force MULTISCAN mode
    --infected            -i           Only print infected files 只输出发现的病毒文件
    --no-summary                       Disable summary at end of scanning
    --reload                           Request clamd to reload virus database
    --fdpass                           Pass filedescriptor to clamd (useful if clamd is running as a different user)
    --stream                           Force streaming files to clamd (for debugging and unit testing)
2、示例
在使用 clamdscan 进行扫毒之前,可以先测试与 clamd 的连接是否正常:clamdscan -p 3
若显示 PONG 就表示与 clamd 的连接正常。
检查一下 ClamAV 与病毒码版本:clamdscan --version
   
26601是病毒码(signatures)的版本,而最后的日期则是病毒码的日期。
对指定文件进行扫毒:clamdscan archive.zip
指定目录路径扫毒: clamdscan /home/ubuntu
文件清单扫毒,先准备好文件清单 filelist.txt,格式为一行一个文件:clamdscan -f filelist.txt
对数据串流进行扫毒:cat myfile | clamscan -
报错:/home/malware_scanner_eicar: Can't open file or directory ERROR
网上解释
但我测试时发现加上好像也没用,暂时只能将待检测的病毒样本存放在/etc/apparmor.d/usr.sbin.clamd中列出的目录下。
下面这个方法可行,最后要重启机器
没有检测到:
 
检测到了:
 
Infected files的值为1,表示找到了。

五、python判定有无检测出病毒

import re
result = '''
----------- SCAN SUMMARY -----------
Infected files: 1
Time: 0.006 sec (0 m 0 s)
Start Date: 2022:07:15 13:34:40
End Date:   2022:07:15 13:34:40
'''
t = re.findall("Infec[\D]+([\d])", result)
print(t)  # ['1'] 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐