ウィルス対策用にClam AntiVirusを搭載します。
Clam AntiVirusはオープンソース(GPL)のUNIX向けウィルス対策ツールキットです。
①Clam AntiVirus の導入
GNOME端末より
# su + 管理者権限パスワード
# yum install gcc* → コンパイラのインストール
# yum install zlib-devel → Clam AntiVirus導入に必要
# yum install gmp-devel → ウィルスデータベース検証に必要
# useradd -s /sbin/nologin clamav -m -d /usr/local/share/clamav -k /dev/null
→ インストールする前にユーザ登録が必要
# wget http://nchc.dl.sourceforge.net/sourceforge/clamav/clamav-0.94.2.tar.gz
→ Clam AntiVirusダウンロード
# tar zxvf clamav-0.94.2.tar.gz → Clam AntiVirus解凍
# cd clamav-0.94.2 → 展開先ディレクトリへ移動
# ./configure && make && make install → Clam AntiVirusインストール
(暫く待つ、、、、、)
# cp contrib/init/RedHat/clamd /etc/rc.d/init.d/
→ clamd起動スクリプトを所定のディレクトリへコピー
# cd → 展開ディレクトリから移動
# rm -rf clamav-0.94.2 → 展開ディレクトリ削除
# rm -f clamav-0.94.2.tar.gz → ダウンロードしたファイルを削除
②Clam AntiVirus の設定
GNOME端末より
# vi /usr/local/etc/clamd.conf → clamd設定ファイルの編集
# Comment or remove the line below.
#Example → コメントアウトする(#を追加)
(省略)
#LogFile /tmp/clamd.log
LogFile /var/log/clamd.log → 追加(ログを記録)
(省略)
# Log time with each message.
# Default: no
LogTime yes → コメントアウトを削除(ログに日時を記録)
(省略)
# Remove stale socket after unclean shutdown.
# Default: no
FixStaleSocket yes → コメントアウトを削除(clamd強制終了後の再起動不可)
# vi /usr/local/etc/freshclam.conf → freshclam設定ファイルの編集
# Comment or remove the line below.
#Example → コメントアウトする(#を追加)
(省略)
# Path to the log file (make sure it has proper permissions)
# Default: disabled
UpdateLogFile /var/log/freshclam.log → コメントアウトを削除(ログを記録)
(省略)
# Uncomment the following line and replace XY with your country
# code. See http://www.iana.org/cctld/cctld-whois.htm for the full list.
#DatabaseMirror db.XY.clamav.net
DatabaseMirror db.jp.clamav.net → ウィルス定義ファイル入手先を日本に変更
(省略)
# Send the RELOAD command to clamd.
# Default: no
#NotifyClamd /path/to/clamd.conf
NotifyClamd /usr/local/etc/clamd.conf
→ 追加(ウィルス定義ファイル更新をclamdに通知)
# touch /var/log/freshclam.log → 空のログファイルを作成
# chown clamav:clamav /var/log/freshclam.log → ログファイルの所有者を変更
# freshclam → ウィルス定義ファイル更新
# vi freshclam → ウィルス定義ファイル更新スクリプト作成
------------ 作成内容 ------------
#!/bin/sh
/usr/local/bin/freshclam --quiet
------------------------------------
# chmod 700 freshclam → ウィルス定義ファイル更新スクリプトに実行権限付加
# mv freshclam /etc/cron.hourly/
→ ウィルス定義ファイル更新スクリプト自動実行(1時間毎)するディレクトリへ移動
# vi /etc/logrotate.d/clamd → clamdログローテーション設定ファイル作成
------------ 作成内容 ------------
/var/log/clamd.log {
sharedscripts
postrotate
/etc/rc.d/init.d/clamd restart > /dev/null || true
endscript
}
------------------------------------
# vi /etc/logrotate.d/freshclam → freshclamログローテーション設定ファイル作成
------------ 作成内容 ------------
/var/log/freshclam.log {
missingok
notifempty
create 644 clamav clamav
}
------------------------------------
③Clam AntiVirus の起動
GNOME端末より
# /etc/rc.d/init.d/clamd start → clamd起動
# chkconfig --add clamd → clamd自動起動設定
# chkconfig clamd on → clamd自動起動設定
# chkconfig --list clamd → 設定の確認
④Clam AntiVirus定期自動実行スクリプト作成
GNOME端末より
# vi clamav.sh ← Clam AntiVirus定期自動実行スクリプト作成
------------ 作成内容 -----------------------------------------------
#!/bin/bash
PATH=/bin:/usr/local/bin
# excludelist
excludelist=/root/clamscan.exclude
# make excludelist
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
# update virus databases & ClamAV
freshclam > /dev/null 2>&1
# scan virus
CLAMSCANTMP=`mktemp`
clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1
# virus detect message send
[ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \
grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" root
rm -f $CLAMSCANTMP
------------------------------------ 以上 ------------------------------------
# chmod 700 clamav.sh → 実行権限付与(Clam AntiVirus定期自動実行スクリプト)
# mv clamav.sh /etc/cron.daily/
→ Clam AntiVirus定期自動実行スクリプトを移動(毎日自動実行するディレクトリ)
* 毎日自動的にウィルス定義ファイルの最新化後、
全ファイルのウィルススキャンが行われ、
ウィルスを検知した場合のみroot宛にメールが送られてくるようになります。
* Clam AntiVirusインストールディレクトリにテスト用ウィルスがあるので、
インストール後最初の全体スキャンでは、必ずウィルス検知メールがきます。
⑤Clam AntiVirusの自動アップデート(clamav-update)の導入
GNOME端末より
# rpm -q curl → パッケージがインストールされているかを確認
------ インストールされていない場合は続けて下記を実行します。 ------
# yum install curl → curlのインストール(clamav-updateに必要)
-------------------------------------------------------------------------------------
# wget http://jaist.dl.sourceforge.jp/clamav-update/32035/clamav-update-2.2.5.tar.gz
* ダウンロードが開始されない場合,別のミラーを選択してください。
# tar zxvf clamav-update-2.2.5.tar.gz → clamav-update解凍
# cd clamav-update-2.2.5 → 展開先ディレクトリへ移動
# ./install.sh → clamav-updateのインストール
# cd → ディレクトリを移動
# rm -rf clamav-update-2.2.5 → 展開先ディレクトリを削除
# rm -f clamav-update-2.2.5.tar.gz → ダウンロードしたファイルを削除
⑥clamav-update自動実行の設定
GNOME端末より
# vi /usr/local/etc/clamav-update.conf → 設定ファイルを編集します。
#$Setting{option}->{src} = 'http://jaist.dl.sourceforge.net/sourceforge/clamav';
→ $Setting{option}->{src} = 'http://mesh.dl.sourceforge.net/sourceforge/clamav'; → ClamAVダウンロード先を変更
# vi /usr/local/etc/freshclam.conf → ウィルスデータベース更新設定ファイルを編集します。
(省略)
# Default: clamav (may depend on installation options)
#DatabaseOwner clamav
DatabaseOwner root → 追加(データベース所有者をrootに変更)
(省略)
# In the command string %v will be replaced by the new version number.
# Default: disabled
#OnOutdatedExecute command
OnOutdatedExecute /usr/local/bin/clamav-update.pl --config /usr/local/etc/clamav-update.conf
→ Clam AntiVirusアップデート検知時にclamav-updateを実行します。
登録完了です。
またまた、進歩しました。
コメントする