杀毒软件 clamav 的安装和使用

目录

一、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'] 

  • 21
    点赞
  • 94
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Linux 中,杀毒软件通常被称为防病毒软件,因为它们不仅可以检测和清除病毒,还可以检测和清除其他恶意软件。ClamAV 是一个流行的开源防病毒引擎,它可以用于 Linux、Windows 和 macOS 等多个操作系统。 要检查 Linux 中是否安装ClamAV,请按照以下步骤操作: 1. 打开终端。 2. 输入以下命令并按回车键: ``` which clamscan ``` 3. 如果输出结果为 `/usr/bin/clamscan`,则表示 ClamAV 已经安装。 如果 ClamAV 没有安装,可以按照以下步骤安装: 1. 打开终端。 2. 输入以下命令并按回车键,以更新软件包列表: ``` sudo apt-get update ``` 3. 安装 ClamAV: ``` sudo apt-get install clamav ``` 4. 安装完成后,可以使用以下命令检查 ClamAV 是否已正确安装: ``` clamscan --version ``` 此时,终端应该会输出 ClamAV 版本信息。 使用 ClamAV 进行扫描和清除恶意软件也很简单。以下是一些常用命令: - 扫描整个文件系统: ``` sudo clamscan -r / ``` - 扫描指定目录: ``` sudo clamscan -r /path/to/directory ``` - 扫描并删除感染文件: ``` sudo clamscan -r --remove / ``` - 扫描并将感染文件移动到指定目录: ``` sudo clamscan -r --move=/path/to/directory / ``` - 扫描并将感染文件复制到指定目录: ``` sudo clamscan -r --copy=/path/to/directory / ``` 请注意,在扫描系统之前最好先更新 ClamAV 的病毒数据库。可以使用以下命令手动更新: ``` sudo freshclam ``` 如此一来,ClamAV 就可以帮助您保护 Linux 系统免受恶意软件的威胁了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值