Yesterday:117 | Today:113 | Total:75758
[ 自宅サーバーWebRing |ID=83 前後5表示乱移動サイト一覧 ]

E-HIRO.NET Web Site..

- ウィルスメール対策(AntiVir MailGate) -

Postfix(メールサーバー)に送られてきたメールに対して、AntiVir MailGateを使用してウィルスチェックを行い、ウィルスを検出したら管理者宛にウィルス検出メールを送りメールを配送しないようにします。

AntiVir MailGateと言うソフトは企業など団体で使用する場合は有料ですが、個人利用に限り無料で使用可能となっています。

初めに、ユーザー登録を行います。H+BEDVのサイトで登録できます。

必要事項を入力し、チェックボックスにチェック入れてsendボタンを押してください。
必ずユーザー登録を行ってください。しないと使用できません!!

ユーザー登録後、登録完了メールにライセンスキー(HBEDV.KEY)が添付されてくるので、任意のディレクトリに保存しておいてください。

私の使用したバージョンは、2.0.2-9でしたが、一応こちらから最新のバージョンを確認してください。

作業ディレクトリに移動します。
# cd /usr/src/redhat/SOURCES

AntiVir MailGateのダウンロード(avlxmgt.tgzという名前です)
# wget http://dl.antivir.de/dateien/antivir/release/avlxmgt.tgz
# tar -zxvf avlxmgt.tgz
# cd antivir-mailgate-2.0.2-9


AntiVir MailGateのインストール
# ./avinstall.pl     ← perlスクリプトを実行します。
使用承諾書が大量に出力されます。SPACEキーを押し続けて先へ進めてください。

Do you agree the LICENSE (y/n):yyを入力(承諾します)

Enter the path of the init directory
(default is: /etc/rc.d): EnterEnterを入力

Enter the path where AntiVir MailGate binaries will be located
(default is: /usr/sbin): EnterEnterを入力

Enter the path where scan engine and virus definition file will be located
(default is: /usr/lib/AntiVir): EnterEnterを入力
      The directory /usr/lib/AntiVir doesn't exists. Try again!
      Should I create it? (y/n): yyを入力

Enter the path where manual pages will be located
(default is: /usr/share/man): EnterEnterを入力

Enter the path to your license file: EnterEnterを入力


The automatic internet updater will check every hour
if a new update is available. Default is yes.
Install the automatic internet updater? (y/n):yyを入力

Installing new /usr/lib/AntiVir/antivir with version: 6.28.0.3
Installing new /usr/lib/AntiVir/antivir.vdf with version: 6.28.0.2
Installing new /usr/sbin/avgated with version: 2.0.2-9+gui
Installing new /usr/sbin/avgatefwd with version: 2.0.2-9+gui

Installing config file /etc/avmailgate.conf


Installing config file /etc/antivir.conf


Installing ignore file for addressfilter /etc/avmailgate.ignore


Installing scan file for filter /etc/avmailgate.scan


Installing warn file /etc/avmailgate.warn

Enter the hosts and/or domains that are local:
(default is: e-hiro.net server.e-hiro.net): e-hiro.net mail.e-hiro.net各自環境に合わせて設定してください。(そのままEnterでもいいです)

Enter the hosts and networks that are allowed to relay:
(default is: 127.0.0.1/8 192.168.0.0/16): 127.0.0.1/8 192.168.0/20各自設定してください。

Installing config file /etc/avmailgate.acl

Installing start/stop script on a Redhat System to /etc/rc.d/avgate

Creating /var/spool/avmailgate/incoming
Creating /var/spool/avmailgate/outgoing
Creating /var/spool/avmailgate/rejected


Installing /usr/share/man/man5/avmailgate.conf.5
Installing /usr/share/man/man8/avmailgate.8

Would you like to enable GUI support?
The GUI allows you to monitor realtime activity, view logs, and configure MailGa
te (y/n). nnを入力


AntiVir MailGate is now installed. Please read the installation
description in the directory avmailgate and follow the
instructions in INSTALL.sendmail, INSTALL.qmail,
INSTALL.postfix or INSTALL.exim.
Then start AntiVir MailGate "/usr/sbin/rcavgate start".

これでインストールは完了です。後は、設定です。

起動スクリプトを移動します。
# mv /etc/rc.d/avgate /etc/rc.d/init.d/avgate


AntiVir MailGateの設定
編集箇所周辺を示します。(全文ではありません)
変更箇所は赤字、補足説明は青字です。
# vi /etc/avmailgate.conf
###################################
# Parameters used by both daemons #
###################################
ほとんどが注釈(#:シャープ)を削除すればよいものばかりだったと思います。
# ------------------------------------------------------------------------
# Avgated and avgatefwd will switch to this user and group
# as soon as possible. Avgated will do this after opening
# the SMTP port and avgatefwd will do it immediately.

AntiVir MailGateの実行権限を、uucpとします。
 User                            uucp
 Group                           uucp

# ------------------------------------------------------------------------
# Who will get errors and alert messages.

管理者をwebmasterとします。
 Postmaster                      webmaster

# ------------------------------------------------------------------------
# MyHostName: FQDN of the local host.
# The default value, if not set in configuration file, is that
# obtained by gethostname(2), or if this fails, "localhost".

ドメインを設定します
 MyHostName                      e-hiro.net

# ------------------------------------------------------------------------
# The spooldir must be owned by User:Group (as specified above)
# and must be accessible by only this user (mode = 0700).
# Both programs will yell and refuse to run if something is wrong.

#(注釈)を削除
 SpoolDir                        /var/spool/avmailgate


# ------------------------------------------------------------------------
# AntiVirDir: The antivir 'library' directory, where the VDF,
# the key, and some other files are stored.

#(注釈)を削除
 AntiVirDir                      /usr/lib/AntiVir


# ------------------------------------------------------------------------
# TemporaryDir: Where the temporary files are stored
# (for example, attachments while checking them).
# It needs enough space to hold uncompressed attachments
# for each forwarder, and some more.
# Default: "/var/tmp" or else "/tmp".

#(注釈)を削除
 TemporaryDir                    /var/tmp


# ------------------------------------------------------------------------
# You can set this option to RECIPIENT, SENDER or BOTH to allow matching of
# domain name of the recipient and/or sender mail address, to check if it's
# to be considered local.

# If MatchMailAddressForLocal is RECIPIENT, and the recipient address matches
# the domain given in "local:", mail will be accepted.
# If MatchMailAddressForLocal is SENDER, and the sender address matches the
# domain given in "local:", mail will be accepted.
# If MatchMailAdressForLocal is BOTH, and the recipient or the sender adresses
# matches the domain given in "local:" mail will be accepted.

# MatchMailAddressForLocal      RECIPIENT


# ------------------------------------------------------------------------
# SMTP greeting message.

#(注釈)を削除
 SMTPBanner                    "AntiVir MailGate"


# ------------------------------------------------------------------------
# Where the pid files of avgated and avgatefwd are stored.
# Default: "/var/tmp" or else "/tmp".

後で、/var/run/antivirディレクトリを作成します
 PidDir                        /var/run/antivir


# ------------------------------------------------------------------------
# Specify a full path with a filename to which AntiVir MailGate
# will write its log messages. AntiVir MailGate still logs to syslog
# even if this option is set.

# Default: NO - dont use custom logfile.


##############################
# Parameters used by avgated #
##############################

# ------------------------------------------------------------------------
# Select the interface, the SMTP daemon will listen on.
# The default listen address of 0.0.0.0 means all interfaces.
# IF YOU ARE UNSURE JUST LEAVE IT AS IS!

AntiVir MailGateのポートの設定
 ListenAddress  localhost port antivir


# ------------------------------------------------------------------------
# Select how mail should be forwarded.
# Send mail by piping it thru sendmail (this is the default):

# ForwardTo /usr/lib/sendmail -oem -oi

# Or if you want the mail to be sent by SMTP:

SMTPのためのAntiVirからのフォワード先ポートの設定
 ForwardTo SMTP: localhost port smtp-backdoor

# ------------------------------------------------------------------------
# User name of sender of alerts, if an alert was found in a mail.

メールでウィルスが検出された場合にメッセージを送ります。
 AlertsUser                 webmaster
# or
# AlertsUser            someone@anywhere.tld

/etc/avmailgate.confの設定はここで終了です。

メールに添付されてきたライセンスキーを/usr/lib/AntiVirにコピーしてください。
# cp HBEDV.KEY /usr/lib/AntiVir/HBEDV.KEY

ライセンスキーの所有者:グループをuucpにしてください。
# chown uucp:uucp /usr/lib/AntiVir/HBEDV.KEY

先程、avmailgate.conf内のPidDirで設定したディレクトリを作成します。
# cd /var/run
# mkdir -m 755 antivir
# chown uucp:uucp antivir

AntiVir MailGateのために使用するサービスポートを設定します。
servicesファイルの一番下に、# Local services という行がありました。
# vi /etc/services
# Local services
antivir         10024/tcp
smtp-backdoor   10025/tcp


Postfixの設定ファイルの編集
下記をそれぞれの設定ファイルに追記してください。
場所はどこでも構いません。
# vi /etc/postfix/master.cf
localhost:smtp-backdoor inet n - n - - smtpd -o content_filter=
# vi /etc/postfix/main.cf
content_filter = smtp:127.0.0.1:10024

設定を変更したので、Postfixを再起動してください。
# /etc/rc.d/init.d/postfix restart

AntiVir MailGate起動
# /etc/rc.d/init.d/avgate start

また、AntiVir MailGateを停止するときに失敗してしまうので、
その対処として起動スクリプトを修正します。
# vi /etc/rc.d/init.d/avgate
#    killproc avmg_stats  ← コメントアウトしてください

ウィルス定義ファイルのアップデート
# /usr/lib/AntiVir/antivir --update


eicarのサイトの下の方にあるDownload Areaからテスト用のウィルスファイルを
ダウンロードできますので、メールに添付して試してみましょう。

実際に試した時にシステムから来たメールを以下に示しておきます。
(メールアドレスはxxxなどに変更してます)
From: root
To: webmaster
Date: Mon, 15 Nov 2004 22:51:24 +0900 (JST)
References:
Subject: AntiVir ALERT [mail from: xxx]

* * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * *
This version of AntiVir is licensed for private and non-commercial use.

AntiVir has detected the following in a mail sent through your server:

        Eicar-Test-Signature virus        

The mail was not delivered.

It has been quarantined with the following queue id:

        19551-6CC82334

Mail-Info:
--8<--

 Message-Id:
 From: xxx
 To: yyy@yyy
 Date: Mon, 15 Nov 2004 22:50:04 +0900 (JST)
 Subject: =?ISO-2022-JP?B?GyRCJSYlIyVrJTklQSUnJUMlLyVhITwlaxsoQg==?= 
 Mail-From: 
 Rcpt: xxx@e-hiro.net
 Queue-Id: 19551-6CC82334
 Status: The mail was not delivered!

--8<--


Log-File:
--8<--

checking file "/var/spool/avmailgate/incoming/df-19551-6CC82334"

--8<--
This version of AntiVir is licensed for private and non-commercial use.

-- 
AntiVir for UNIX
Copyright (c) 1994-2004 by H+BEDV Datentechnik GmbH.
All rights reserved.
For more information see http://www.antivir.de/ or http://www.hbedv.com/

ちなみに、これはeicar_com.zipを添付した時の結果です。

このメールを送信した時のmaillogの結果です。
# cat /var/log/maillog | grep avmailgate
Nov 15 22:51:24 server avgatefwd[19552]: Alert! the file 
                     "/var/spool/avmailgate/incoming/df-19551-6CC82334" 
                      contains "Eicar-Test-Signature" virus ← 実際は1行です。



ウィルス定義ファイルアップデート、ウィルスメール削除の自動化
(AntiVir MailGateは、メールのウィルス検出、駆除だけでなくシステムのウィルスチェックもできます)

# vi /etc/crontab
26 * * * * root /usr/lib/AntiVir/antivir --update -q
この行を削除してください。インストール時に自動的に追加されてます。

実行スクリプトの作成
# vi ~/bin/avgate.sh
#!/bin/sh

AVGATE='/usr/lib/AntiVir/antivir'
LOG='/var/log/avgate.log'

echo '========================= Update Start =========================' >> $LOG
$AVGATE --update >> $LOG

echo '======================= VirMail Delete =========================' >> $LOG
$AVGATE /var/spool/avmailgate/rejected/ -z -e -del >> $LOG

echo '========================= /HOME Scan ===========================' >> $LOG
$AVGATE /home -s -z -e -del --allfiles >> $LOG

echo '=========================== Scan End ===========================' >> $LOG

作成したファイルに実行権限を与えます。
# chmod +x avgate.sh

※ オプションについて
-q : バックグラウンドで動作
-s : サブディレクトリ以下もスキャンする(未指定時はメインディレクトリのみ)
-z : 圧縮ファイルをスキャンする(未指定時は圧縮ファイルはスキャンされない)
-e : 感染ファイルの修復を試みる
-del : 修復できなければ削除する(上記のオプションがなければいきなり削除)
--allfiles : 全てのファイルをスキャンする
以下でヘルプが見れます。
# /usr/lib/AntiVir/antivir --help

cronを編集して、毎日06:00にスクリプトを実行しウィルス定義ファイルのアップデート、
ウィルスの削除が行われます。また、処理結果は/var/log/avgate.logに保存されます。
# crontab -e
00 06 * * * /root/bin/avgate.sh

処理結果は以下のようになります。
(/home/userディレクトリにテスト用のウィルスファイルを置いておきました)
========================= Update Start =========================
AntiVir / Linux Version 2.1.2-15 +gui
Copyright (c) 1994-2004 by H+BEDV Datentechnik GmbH.
All rights reserved.

checking for updates

06.28.00.97 <=> 06.28.00.97 [vdf database, loaded]
06.28.00.19 <=> 06.28.00.19 [scan engine, running]
02.01.02.15 <=> 02.01.02.15 [main program, running]

AntiVir is up-to-date

======================= VirMail Delete =========================
AntiVir / Linux Version 2.1.2-15 +gui
Copyright (c) 1994-2004 by H+BEDV Datentechnik GmbH.
All rights reserved.

Loading /usr/lib/AntiVir/antivir.vdf ...

VDF version: 6.28.0.97 created 29 Nov 2004

For private, non-commercial use only.
AntiVir license: xxxxxxxxxx for xxxxxxx

checking drive/path (list): /var/spool/avmailgate/rejected/

------ scan results ------
   directories:        1
 scanned files:        0
        alerts:        0
    suspicious:        0
     scan time: 00:00:01
--------------------------
Thank you for using AntiVir.
========================= /HOME Scan ===========================
AntiVir / Linux Version 2.1.2-15 +gui
Copyright (c) 1994-2004 by H+BEDV Datentechnik GmbH.
All rights reserved.

Loading /usr/lib/AntiVir/antivir.vdf ...

VDF version: 6.28.0.97 created 29 Nov 2004

For private, non-commercial use only.
AntiVir license: xxxxxxxxxx for xxxxxxx

checking drive/path (list): /home
/home/user/eicar_com.zip
 Date:  4.08.2004  Time: 00:23:42  Size: 184
 ALERT: [Eicar-Test-Signature virus] /home/user/eicar_com.zip --> eicar.com <
<< Contains code of the Eicar-Test-Signature virus
 file deleted.



------ scan results ------
   directories:      141
 scanned files:      745
        alerts:        1
    suspicious:        0
      repaired:        0
       deleted:        1
       renamed:        0
     scan time: 00:00:02
--------------------------
Thank you for using AntiVir.
=========================== Scan End ===========================


AntiVir MailGateの自動起動の設定です。
# chkconfig --add avgate
# chkconfig avgate on
# chkconfig --list avgate
			
Menu
Copyright © 2004-2005 E-HIRO.NET. All Rights Reserved.