2018年10月02日 00:49:35 neo_will_mvp 閱讀數 359centos
版權聲明:精心研究,潛心學習,本文爲博主原創文章,未經博主容許不得轉載。 https://blog.csdn.net/qq_33468857/article/details/82920832安全
ClamAV是一個C語言開發的開源病毒掃描工具用於檢測木馬/病毒/惡意軟件等。能夠在線更新病毒庫,Linux系統的病毒較少,可是並不意味着病毒免疫,尤爲是對於諸如郵件或者歸檔文件中夾雜的病毒每每更加難以防範,而ClamAV則能起到很多做用。
ClamAV相關信息以下:bash
項目 | 詳細 |
---|---|
官方地址 | http://www.clamav.net/ |
下載地址 | http://www.clamav.net/downloads |
當前穩定版本 | 0.99.2 |
項目 | 詳細 |
---|---|
主要用途 | 郵件網關的病毒掃描,內建支持多種郵件格式 |
高性能 | 提供多線程的掃描進程 |
命令行 | 提供密令行掃描方式 |
掃描對象 | 能夠對要發送的郵件或者文件進行掃描 |
文件格式 | 支持多種文件格式 |
病毒庫更新頻度 | 一天屢次病毒庫的更新 |
歸檔文件 | 支持掃描多種歸檔文件,好比Zip, RAR, Dmg, Tar, Gzip, Bzip2, OLE2, Cabinet, CHM, BinHex, SIS等 |
文檔 | 支持流行的文檔文件,好比: MS Office文件,MacOffice文件, HTML, Flash, RTF,PDF |
項目 | 詳細 |
---|---|
CENTOS/RHEL | yum -y install clamav |
Ubuntu/Debian | apt-get install clamav |
注意:centos上的clamd是在epel-release下,須要現行安裝epel-release。 若是使用源碼安裝方式的話,保證C編譯器和ZLIB等存在的狀況下對源碼./configure->make->make install便可。多線程
[root@liumiaocn ~]# yum -y install epel-release
app
Loaded plugins: fastestmirror
工具
...
性能
Package : centos-release-7-3.1611.el7.centos.x86_64 (@anaconda)
學習
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
測試
Running transaction check
ui
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-9.noarch 1/1
Verifying : epel-release-7-9.noarch 1/1
Installed:
epel-release.noarch 0:7-9
Complete!
[root@liumiaocn ~]#
[root@liumiaocn ~]# yum -y install clamav
Loaded plugins: fastestmirror
...
Running transaction
Installing : clamav-filesystem-0.101.2-1.el7.noarch 1/5
Installing : pcre2-10.23-2.el7.x86_64 2/5
Installing : clamav-lib-0.101.2-1.el7.x86_64 3/5
Installing : clamav-update-0.101.2-1.el7.x86_64 4/5
Installing : clamav-0.101.2-1.el7.x86_64 5/5
Verifying : clamav-0.101.2-1.el7.x86_64 1/5
Verifying : clamav-update-0.101.2-1.el7.x86_64 2/5
Verifying : clamav-lib-0.101.2-1.el7.x86_64 3/5
Verifying : pcre2-10.23-2.el7.x86_64 4/5
Verifying : clamav-filesystem-0.101.2-1.el7.noarch 5/5
Installed:
clamav.x86_64 0:0.101.2-1.el7
Dependency Installed:
clamav-filesystem.noarch 0:0.101.2-1.el7 clamav-lib.x86_64 0:0.101.2-1.el7
clamav-update.x86_64 0:0.101.2-1.el7 pcre2.x86_64 0:10.23-2.el7
Complete!
[root@liumiaocn ~]#
[root@liumiaocn ~]# clamscan --version
ClamAV 0.101.2
[root@liumiaocn ~]#
使用clamscan命令行對某一目錄進行掃描,能夠確認結果是否OK,同時會給出一個掃描的整體信息,其中Infected files是掃描出來的被感染的文件個數。好比以下示例代表對/root目錄下的文件進行掃描,未發現感染文件的狀況。
[root@liumiaocn ~]# clamscan /root
LibClamAV Warning: **************************************************
LibClamAV Warning: *** The virus database is older than 7 days! ***
LibClamAV Warning: *** Please update it as soon as possible. ***
LibClamAV Warning: **************************************************
/root/.bash_logout: OK
/root/.bash_profile: OK
/root/.bashrc: OK
/root/.cshrc: OK
/root/.tcshrc: OK
/root/anaconda-ks.cfg: OK
/root/.bash_history: OK
----------- SCAN SUMMARY -----------
Known viruses: 4490129
Engine version: 0.99.2
Scanned directories: 1
Scanned files: 7
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 19.365 sec (0 m 19 s)
[root@liumiaocn ~]#
注意:此處提示「The virus database is older than 7 days!」的緣由在於病毒庫沒有及時更新。由於使用yum缺省安裝目前的版本彷佛不會自動安裝freshclam的病毒庫更新功能,後面咱們會使用源碼安裝方式來解決這個問題。
從eicar.org下載一個用於模擬病毒的文件,看一下clamav是否可以掃描出來
[root@liumiaocn ~]# wget http://www.eicar.org/download/eicar.com
--2017-08-02 23:03:10-- http://www.eicar.org/download/eicar.com
Resolving www.eicar.org (www.eicar.org)... 213.211.198.62
Connecting to www.eicar.org (www.eicar.org)|213.211.198.62|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 68 [application/octet-stream]
Saving to: ‘eicar.com’
100%[===============================================================================================================================>] 68 --.-K/s in 0s
2017-08-02 23:03:20 (318 KB/s) - ‘eicar.com’ saved [68/68]
[root@liumiaocn ~]# ls
anaconda-ks.cfg eicar.com
[root@liumiaocn ~]# pwd
/root
從新掃描看是否可以檢測出新下載的病毒測試文件。進過測試,發現結果中提示「/root/eicar.com: Eicar-Test-Signature FOUND」,同時「Infected files: 1」,說明此病毒文件被檢測出來了
[root@liumiaocn ~]# clamscan /root
LibClamAV Warning: **************************************************
LibClamAV Warning: *** The virus database is older than 7 days! ***
LibClamAV Warning: *** Please update it as soon as possible. ***
LibClamAV Warning: **************************************************
/root/.bash_logout: OK
/root/.bash_profile: OK
/root/.bashrc: OK
/root/.cshrc: OK
/root/.tcshrc: OK
/root/anaconda-ks.cfg: OK
/root/.bash_history: OK
/root/eicar.com: Eicar-Test-Signature FOUND
----------- SCAN SUMMARY -----------
Known viruses: 4490129
Engine version: 0.99.2
Scanned directories: 1
Scanned files: 8
Infected files: 1
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 21.129 sec (0 m 21 s)
[root@liumiaocn ~]#
可是缺省的方式下,clamscan只會檢測不會自動刪除文件
[root@liumiaocn ~]# ls
anaconda-ks.cfg eicar.com
[root@liumiaocn ~]#
使用–remove選項,會直接刪除檢測出來的文件。
[root@liumiaocn ~]# clamscan --remove /root
LibClamAV Warning: **************************************************
LibClamAV Warning: *** The virus database is older than 7 days! ***
LibClamAV Warning: *** Please update it as soon as possible. ***
LibClamAV Warning: **************************************************
/root/.bash_logout: OK
/root/.bash_profile: OK
/root/.bashrc: OK
/root/.cshrc: OK
/root/.tcshrc: OK
/root/anaconda-ks.cfg: OK
/root/.bash_history: OK
/root/eicar.com: Eicar-Test-Signature FOUND
/root/eicar.com: Removed.
----------- SCAN SUMMARY -----------
Known viruses: 4490129
Engine version: 0.99.2
Scanned directories: 1
Scanned files: 8
Infected files: 1
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 23.546 sec (0 m 23 s)
[root@liumiaocn ~]# ls
anaconda-ks.cfg
[root@liumiaocn ~]#
目前使用yum源安裝病毒庫的更新相關的仍需手動操做,因此能夠考慮使用源碼安裝方式。
項目 | 詳細 |
---|---|
下載命令 | wget http://www.clamav.net/downloads/production/clamav-0.99.2.tar.gz |
項目 | 詳細 |
---|---|
解壓命令 | tar xvpf clamav-0.99.2.tar.gz |
變動目錄 | cd clamav-0.99.2 |
項目 | 詳細 |
---|---|
安裝gcc | yum install gcc -y |
安裝openssl | yum install openssl openssl-devel -y |
建立目錄 | mkdir -p /usr/local/clamav |
項目 | 詳細 |
---|---|
config | ./configure –prefix=/usr/local/clamav |
make | make |
make install | make install |
[root@liumiaocn clamav-0.99.2]# ls /usr/local/clamav/bin
clamav-config clambc clamconf clamdscan clamscan freshclam sigtool
[root@liumiaocn clamav-0.99.2]# /usr/local/clamav/bin/clamscan --version
ClamAV 0.99.2
[root@liumiaocn clamav-0.99.2]#
注意:此時若是執行clamscan進行掃描,會提示以下問題。
[root@liumiaocn clamav-0.99.2]# /usr/local/clamav/bin/clamscan /root
LibClamAV Error: cl_load(): No such file or directory: /usr/local/clamav/share/clamav
ERROR: Can't get file status
----------- SCAN SUMMARY -----------
Known viruses: 0
Engine version: 0.99.2
Scanned directories: 0
Scanned files: 0
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 0.002 sec (0 m 0 s)
[root@liumiaocn clamav-0.99.2]#
查看源碼以後發現其實很簡單,此時須要有可用的病毒庫文件,同時用戶和組的權限也須要設定。總體的順序按照:
項目 | 詳細 |
---|---|
Step 1 | 建立用戶和組 |
Step 2 | 建立目錄並設定權限 |
Step 3 | 拷貝和更新設定文件 |
Step 4 | 更新病毒庫 |
Step 5 | 掃描病毒 |
項目 | 詳細 |
---|---|
建立group | groupadd clamav |
建立用戶 | useradd -g clamav clamav |
目錄 | 詳細 |
---|---|
logs | 存放日誌信息 |
database | 存放更新病毒庫信息 |
worktmp | 存放pid等臨時文件或狀態文件信息 |
[root@liumiaocn clamav]# pwd
/usr/local/clamav
[root@liumiaocn clamav]# ls
bin etc include lib64 sbin share
[root@liumiaocn clamav]# mkdir -p logs database worktmp
[root@liumiaocn clamav]#
[root@liumiaocn clamav]# pwd
/usr/local/clamav
[root@liumiaocn clamav]# chown clamav:clamav database
[root@liumiaocn clamav]#
目錄 | 源文件 | 目標文件 |
---|---|---|
/usr/local/clamav/etc | clamd.conf.sample | clamd.conf |
/usr/local/clamav/etc | freshclam.conf.sample | freshclam.conf |
[root@liumiaocn etc]# pwd
/usr/local/clamav/etc
[root@liumiaocn etc]# cp clamd.conf.sample clamd.conf
[root@liumiaocn etc]# cp freshclam.conf.sample freshclam.conf
[root@liumiaocn etc]# ls
clamd.conf clamd.conf.sample freshclam.conf freshclam.conf.sample
[root@liumiaocn etc]#
生成病毒庫更新日誌文件
[root@liumiaocn etc]# touch /usr/local/clamav/logs/freshclam.log
[root@liumiaocn etc]# chown clamav:clamav /usr/local/clamav/logs/freshclam.log
[root@liumiaocn etc]#
[root@liumiaocn etc]# ls
clamd.conf clamd.conf.sample freshclam.conf freshclam.conf.sample
[root@liumiaocn etc]# vi clamd.conf
[root@liumiaocn etc]# vi freshclam.conf
[root@liumiaocn etc]# diff clamd.conf clamd.conf.sample
14c14
< LogFile /usr/local/clamav/logs/clamd.log
---
> #LogFile /tmp/clamd.log
66c66
< PidFile /var/clamav/worktmp/clamd.pid
---
> #PidFile /var/run/clamd.pid
74c74
< DatabaseDirectory /var/lib/clamav/database
---
> #DatabaseDirectory /var/lib/clamav
[root@liumiaocn etc]#
[root@liumiaocn etc]# diff freshclam.conf freshclam.conf.sample
8c8
< #Example
---
> Example
13c13
< DatabaseDirectory /usr/local/clamav/database/
---
> #DatabaseDirectory /var/lib/clamav
17c17
< UpdateLogFile /usr/local/clamav/logs/freshclam.log
---
> #UpdateLogFile /var/log/freshclam.log
51c51
< PidFile /usr/local/clamav/worktmp/freshclam.pid
---
> #PidFile /var/run/freshclam.pid
[root@liumiaocn etc]#
其實本次示例中只需保證freshclam.conf文件正確設定便可保證ClamAV正常動做。
在設定freshclam.conf以後,使用freshclam命令便可聯網更新病毒庫至database目錄了, 首次更新稍微會花一點時間。
[root@liumiaocn etc]# /usr/local/clamav/bin/freshclam
ClamAV update process started at Fri Aug 4 22:39:40 2017
Trying host database.clamav.net (69.12.162.28)...
Downloading main.cvd [100%]
main.cvd updated (version: 58, sigs: 4566249, f-level: 60, builder: sigmgr)
Downloading daily.cvd [100%]
daily.cvd updated (version: 23629, sigs: 1741893, f-level: 63, builder: neo)
Downloading bytecode.cvd [100%]
bytecode.cvd updated (version: 308, sigs: 66, f-level: 63, builder: anvilleg)
Database updated (6308208 signatures) from database.clamav.net (IP: 69.12.162.28)
[root@liumiaocn etc]#
更新以後
[root@liumiaocn clamav]# pwd
/usr/local/clamav
[root@liumiaocn clamav]# ls database/
bytecode.cvd daily.cvd main.cvd mirrors.dat
[root@liumiaocn clamav]#
[root@liumiaocn ~]# ls
anaconda-ks.cfg
[root@liumiaocn ~]# wget http://www.eicar.org/download/eicar.com
--2017-08-04 23:00:41-- http://www.eicar.org/download/eicar.com
Resolving www.eicar.org (www.eicar.org)... 213.211.198.62
Connecting to www.eicar.org (www.eicar.org)|213.211.198.62|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 68 [application/octet-stream]
Saving to: ‘eicar.com’
100%[===============================================================================================================================>] 68 --.-K/s in 0.001s
2017-08-04 23:00:43 (92.3 KB/s) - ‘eicar.com’ saved [68/68]
[root@liumiaocn ~]# ls
anaconda-ks.cfg eicar.com
[root@liumiaocn ~]#
[root@liumiaocn ~]# /usr/local/clamav/bin/clamscan --remove /root
/root/.bash_logout: OK
/root/.bash_profile: OK
/root/.bashrc: OK
/root/.cshrc: OK
/root/.tcshrc: OK
/root/anaconda-ks.cfg: OK
/root/.bash_history: OK
/root/eicar.com: Eicar-Test-Signature FOUND
/root/eicar.com: Removed.
----------- SCAN SUMMARY -----------
Known viruses: 6123265
Engine version: 0.101.2
Scanned directories: 1
Scanned files: 3
Infected files: 0
Data scanned: 0.12 MB
Data read: 0.06 MB (ratio 1.88:1)
Time: 49.224 sec (0 m 49 s)
[root@liumiaocn ~]#
ClamAV提供和方便的命令行方式進行集成,保持更新的病毒庫,給開源的安全方案提供了一種選擇。