ClamAVを使ってウイルス対策をしよう!
ここでは、アンチウィルスソフト(Clam AntiVirus)のインストール手順を掲載しています。
Clam AntiVirusとは…
Clam AntiVirusはオープンソースで開発が進められているアンチウィルスソフトです。オープンソースなので、Linuxだけでなく、Windows版、Mac版のように様々なOSに移植され、使われています。
Clam AntiVirusのインストール
Clam AntiVirusは公式のリポジトリにないので、EPELリポジトリを使ってインストールします。
EPELリポジトリの設定をしていない方は初期設定ページをご覧ください。
[root@co ~]# yum -y --enablerepo=epel install clamd
Loaded plugins: downloadonly, fastestmirror, security
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package clamd.x86_64 0:0.97.7-1.el5 set to be updated
--> Processing Dependency: clamav = 0.97.7-1.el5 for package: clamd
--> Processing Dependency: libclamav.so.6(CLAMAV_PUBLIC)(64bit) for package: clamd
--> Processing Dependency: libclamav.so.6(CLAMAV_PRIVATE)(64bit) for package: clamd
--> Processing Dependency: libclamav.so.6()(64bit) for package: clamd
--> Running transaction check
---> Package clamav.x86_64 0:0.97.7-1.el5 set to be updated
--> Processing Dependency: clamav-db = 0.97.7-1.el5 for package: clamav
--> Running transaction check
---> Package clamav-db.x86_64 0:0.97.7-1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
clamd x86_64 0.97.7-1.el5 epel 184 k
Installing for dependencies:
clamav x86_64 0.97.7-1.el5 epel 11 M
clamav-db x86_64 0.97.7-1.el5 epel 52 M
Transaction Summary
================================================================================
Install 3 Package(s)
Upgrade 0 Package(s)
Total download size: 63 M
Downloading Packages:
(1/3): clamd-0.97.7-1.el5.x86_64.rpm | 184 kB 00:00
(2/3): clamav-0.97.7-1.el5.x86_64.rpm | 11 MB 00:40
(3/3): clamav-db-0.97.7-1.el5.x86_64.rpm | 52 MB 02:56
--------------------------------------------------------------------------------
Total 294 kB/s | 63 MB 03:39
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : clamav-db 1/3
Installing : clamav 2/3
Installing : clamd 3/3
Installed:
clamd.x86_64 0:0.97.7-1.el5
Dependency Installed:
clamav.x86_64 0:0.97.7-1.el5 clamav-db.x86_64 0:0.97.7-1.el5
Complete!
Clam AntiVirusの設定
[root@co ~]# vi /etc/clamd.conf
TCPSocket 3310
↓
#TCPSocket 3310
User clamav
↓
#User clamav
DetectBrokenExecutables yes
↓
#DetectBrokenExecutables yes
[root@co ~]# vi /etc/freshclam.conf
DatabaseOwner clam
↓
DatabaseOwner root
Clam AntiVirusの動作確認(1)
動かすための準備が出来たら早速起動します。
[root@co ~]# /etc/rc.d/init.d/clamd start
Starting Clam AntiVirus Daemon: LibClamAV Warning: **************************************************
LibClamAV Warning: *** The virus database is older than 7 days! ***
LibClamAV Warning: *** Please update it as soon as possible. ***
LibClamAV Warning: **************************************************
[ OK ]
[root@co ~]# chkconfig clamd on
[root@co ~]# chkconfig --list clamd
yum-cron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Warningとか言ってますが、気にしなくて大丈夫です。
次にウィルス定義ファイルの更新をしてみましょう。
定義ファイルはかなり容量があるので、終わるまで時間かかるかも知れません。
[root@co ~]# sed -i 's/Example/#Example/g' /etc/freshclam.conf
[root@co ~]# freshclam
ClamAV update process started at Wed Jun 12 20:22:28 2013
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 0.97.7 Recommended version: 0.97.8
DON'T PANIC! Read http://www.clamav.net/support/faq
main.cvd is up to date (version: 54, sigs: 1044387, f-level: 60, builder: sven)
WARNING: getpatch: Can't download daily-16870.cdiff from db.jp.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
Downloading daily.cvd [100%]
daily.cvd updated (version: 17343, sigs: 1343281, f-level: 63, builder: neo)
Downloading bytecode.cvd [100%]
bytecode.cvd updated (version: 214, sigs: 41, f-level: 63, builder: neo)
Database updated (2387709 signatures) from db.jp.clamav.net (IP: 120.29.176.126)
更新サーバにつながらなかった場合、次のサーバへどんどん接続していくので、そのまま待っていれば大丈夫です。
定義ファイルの更新が終わったら、実際にスキャンをしてみます。
[root@co ~]# clamscan --infected --remove --recursive
----------- SCAN SUMMARY -----------
Known viruses: 2382293
Engine version: 0.97.7
Scanned directories: 1
Scanned files: 10
Infected files: 0
Data scanned: 0.04 MB
Data read: 0.03 MB (ratio 1.43:1)
Time: 5.281 sec (0 m 5 s)
Clam AntiVirusの動作確認(2)
無害なウィルスデータをダウンロードし、スキャンされるかどうかを確認します。
まず、無害なテスト用ウィルスデータをダウンロードします。
[root@co ~]# wget http://www.eicar.org/download/eicar.com.txt http://www.eicar.org/download/eicar.com
--2013-06-12 20:35:25-- http://www.eicar.org/download/eicar.com.txt
www.eicar.org をDNSに問いあわせています... 188.40.238.250
www.eicar.org|188.40.238.250|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 68 [application/octet-stream]
`eicar.com.txt' に保存中
100%[======================================>] 68 --.-K/s 時間 0s
2013-06-12 20:35:26 (8.11 MB/s) - `eicar.com.txt' へ保存完了 [68/68]>
--2013-06-12 20:35:26-- http://www.eicar.org/download/eicar.com
www.eicar.org|188.40.238.250|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 68 [application/octet-stream]
`eicar.com' に保存中
100%[======================================>] 68 --.-K/s 時間 0s
2013-06-12 20:35:27 (13.0 MB/s) - `eicar.com' へ保存完了 [68/68]
終了しました --2013-06-12 20:35:27--
ダウンロード完了: 2 ファイル、136 バイトを 0s で取得 (8.65 MB/s)
再度ウィルススキャンをかけてみます。
[root@co ~]# clamscan --infected --remove --recursive
/root/eicar.com.txt: Eicar-Test-Signature FOUND
/root/eicar.com.txt: Removed
/root/eicar.com: Eicar-Test-Signature FOUND
/root/eicar.com: Removed
Known viruses: 2382293
Engine version: 0.97.7
Scanned directories: 1
Scanned files: 12
Infected files: 2
Data scanned: 0.04 MB
Data read: 0.03 MB (ratio 1.43:1)
Time: 4.980 sec (0 m 4 s)
上のように、"Infected files"が"2"になっていれば、きちんと動作しています。
[root@co ~]# vi /etc/cron.daily/clamscan
#!/bin/bash
PATH=/usr/bin:/bin
# clamd update
yum -y --enablerepo=rpmforge update clamd > /dev/null 2>&1
# excludeopt setup
excludelist=/root/clamscan.exclude
if [ -s $excludelist ]; then
for i in `cat $excludelist`
do
if [ $(echo "$i"|grep \/$) ]; then
i=`echo $i|sed -e 's/^\([^ ]*\)\/$/\1/p' -e d`
excludeopt="${excludeopt} --exclude-dir=$i"
else
excludeopt="${excludeopt} --exclude=$i"
fi
done
fi
# signature update
freshclam > /dev/null
# virus scan
CLAMSCANTMP=`mktemp`
clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1
[ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \
# report mail send
grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" root
rm -f $CLAMSCANTMP
[root@co ~]# chmod +x /etc/cron.daily/clamscan
ログローテーションの設定
[root@co ~]# vi /etc/logrotate.d/clamscan
/var/log/clamav/clamscan.log {
monthly
rotate 4
missingok
}
ウィルス以外にも、サーバ内ファイルの改ざんにも対応していく必要があります。次はTripwireをインストールしましょう。
参考にしたサイト様
CentOSで自宅サーバー構築 - アンチウィルスソフト導入(Clam AntiVirus)
今回新しく登場したコマンド
[広告]

トップページ
Rocky Linux 8
CentOS 7
Scientific Linux 6
CentOS 5
○準備
○VMware Player
○Hyper-V(Win Proのみ)
○導入
○セキュリティ対策
○Dynamic DNS
○NTPサーバ
○データベース
○WEBサーバ
○FTPサーバ
○メールサーバ
○DNSサーバ
○ファイルサーバ
○ブログシステム
○その他