Mailfiltering Gateway/ja

このガイドでは、Postfixのスパム対策技術のインストール手順を段階的に説明しています. そのうち、Amavisd-newはSpamassassinとClamAVを使用し、greylistingとSPFを使用しています.

はじめに
このガイドでは、スパムおよびウイルスフィルタリングメールゲートウェイをインストールする方法を段階的に説明します. 単一のサーバーソリューションにこれを採用するのは非常に簡単です.

概観
このドキュメントでは、複数のドメインを持つスパムフィルタリングメールゲートウェイを設定する方法について説明します. このサーバーは、実際にメールアカウント、すなわちMicrosoft ExchangeまたはLotus Notesを保持しているメールサーバーの前で実行されます.

この設定では、適切なセキュリティレコードと読み取り可能な設定ファイルを持つアプリケーションが選択されています. 電子メールMTAは、良いセキュリティー記録を持っていて、セットアップが簡単です. Postfixは受信メールのために通常ポート25でリッスンします. それを受信すると、ポート10024のAmavisd-newに転送されます. Amavisd-newは、メールを次のメールサーバーに転送するポート10025のPostfixにメールを戻す前に、異なるフィルタでメールをフィルタリングします.

Amavisd-newは、ウイルスフィルタリングとスパムフィルタリングのためのヘルパーアプリケーションを利用したコンテンツフィルタリングフレームワークです. この設定では、ウイルスメールをフィルタリングするためのClamAVと、スパムをフィルタリングするためのSpamassassinの2つのヘルパーアプリケーションを使用します. Spamassassin自体は、コンテンツフィルタリングフレームワークのさらに別の層として機能し、ヘルパアプリケーションVipulのRazor2とDCCを利用することができます.

RBLなどの他の多くのスパム対策テクノロジーとは異なり、Spamassassinは単一のテストに基づいて特定の電子メールを受諾または拒否するだけではありません. これは、多くの内部テストと外部ヘルパーアプリケーションを使用して、通過するすべてのメールのスパムスコアを計算します. このスコアは、次のテストに基づいています.


 * Bayesian filtering
 * Static rules based on regular expressions
 * Distributed and collaborative networks:
 * RBLs
 * Razor2
 * Pyzor
 * DCC

ガイドの最初の部分（第1章から第4章）では、メールフィルタリングゲートウェイの基本的なセットアップについて説明します. 次の章は、各章に依存することなく個別に実装できます. これらの章では、次の方法について説明します. ：


 * ベイジアンフィルターの学習と誤検知の配信のために特別なIMAPフォルダーを設定します
 * Postfixでグレイリストを設定する
 * Amavisdのセットアップ-ユーザー設定にMySQLバックエンドを使用するようになりました
 * AWLおよびベイズデータにMySQLバックエンドを使用するようにSpamassassinをセットアップします

計画されている第5部には、パフォーマンスに関するさまざまなヒントと、知りたいことが含まれます（chrootの実行、postfixの制限など）.

準備
Before you start make sure that you have a working Postfix installation where you can send and receive mails also you need a backend mailserver. If you're not experienced with setting up Postfix it might quickly become too complicated if all should be set up at once. If you need help you can find it in the excellent Complete Virtual Mail Server in the Gentoo Wiki.

必要なプログラムのインストール
まず、最も重要なプログラムであるAmavisd-new、Spamassassin、ClamAVをインストールします.

DNS のセットアップ
プログラムが出現している間に、別のシェルを起動し、必要なDNSレコードを作成します.

Start out by creating a  record for the mail gateway and an   record for the next destination.

ファイアウォールを開ける
通常のメールトラフィックを許可することに加えて、ネットワークチェックがサーバーと通信できるようにするには、ファイアウォールを通過するいくつかのサービスを許可する必要があります.

Razorは、pingを使用して、最も近いサーバーを検出します.

Postfix の設定
First we have to tell  to listen on port 10025 and we remove most of the restrictions as they have already been applied by the   instance listening on port 25. Also we ensure that it will only listen for local connections on port 10025. To accomplish this we have to add the following at the end of

The file tells the postfix master program how to run each individual postfix process. More info with.

Next we need the main  instance listening on port 25 to filter the mail through   listening on port 10024.

また、メールのネクストホップ先を設定する必要があります. Postfixに、外部コンテンツフィルタを介してすべてのメールをフィルタリングし、明示的なルーティングを有効にして、メールの転送先をPostfixに通知するように指示します.

Postfix has a lot of options set in. For further explanation of the file please consult  or the same online Postfix Configuration Parameters.

The format of the file is the normal Postfix hash file. Mail to the domain on the left hand side is forwarded to the destination on the right hand side.

After we have edited the file we need to run the  command. Postfix does not actually read this file so we have to convert it to the proper format with. This creates the file. There is no need to reload Postfix as it will automatically pick up the changes.

If your first attempts to send mail result in messages bouncing, you've likely made a configuration error somewhere. Try temporarily enabling  while you work out your configuration issues. This prevents postfix from bouncing mails on delivery errors by treating them as temporary errors. It keeps mails in the mail queue until  is disabled or removed.

Once you've finished creating a working configuration, be sure to disable or remove  and reload postfix.

amavisd-new の設定
Amavisd-newは、すべてのフィルタリングを処理するために使用され、さまざまなテクノロジーを簡単に接着できます. メールメッセージを受信すると、メールを抽出し、いくつかのカスタムフィルタでフィルタリングし、白と黒のリストを処理し、さまざまなウイルススキャナーでメールをフィルタリングし、最後にSpamAssassinを使用してメールをフィルタリングします.

Amavisd-new自体には、いくつかの追加機能があります. ：


 * it identifies dangerous file attachments and has policies to handle them
 * per-user, per-domain and system-wide policies for:
 * whitelists
 * blacklists
 * spam score thresholds
 * virus and spam policies

Apart from  and   we will run all applications as the user.

Edit the following lines in

ウイルスメールをユーザーに配信したくないため、ウイルスメールの検疫ディレクトリを作成します.

ClamAV の設定
As virus scanner we use ClamAV as it has a fine detection rate comparable with commercial offerings, it is very fast and it is Open Source Software. We love log files, so make  log using   and turn on verbose logging. Also do not run  as. Now edit

ClamAV comes with the  deamon dedicated to periodical checks of virus signature updates. Instead of updating virus signatures twice a day we will make  update virus signatures every two hours.

Start  with   using the init scripts by modifying.

At last modify with the new location of the socket.

Configuring Vipul's Razor
Razor2 is a collaborative and distributed spam checksum network. Install it with  and create the needed configuration files. Do this as user  by running   followed.

Configuring Distributed Checksum Clearinghouse (dcc)
Razor2と同様に、dccは協調的で分散型のスパムチェックサムネットワークです. その哲学は、ファジーチェックサムで各メールを識別する特定のメールの受信者の数を数えることです.

Configuring Spamassassin
Amavis is using the Spamassassin Perl libraries directly so there is no need to start the service. Also this creates some confusion about the configuration as some Spamassassin settings are configured in and overridden by options in.

すべての適切なルールには適切な例外もあります
Once mail really starts passing through this mail gateway you will probably discover that the above setup is not perfect. Maybe some of your customers like to receive mails that others wouldn't. You can whitelist/blacklist envelope senders quite easily. Uncomment the following line in.

In the file you put complete email addresses or just the domian parts and then note a positive/negative score to add to the spam score.

While waiting for a better method you can add the following to to bypass spam checks for   and   mailboxes.

ルールをさらに追加
If you want to use more rules provided by the SARE Ninjas over at the SpamAssassin Rules Emporium you can easily add and update them using the  mechanism included in Spamassassin.

A brief guide to using SARE rulesets with  can be found here.

Testing the setup
Now before you start  you can manually verify that it works.

Now you have updated virus definitions and you know that is working properly.

Test freshclam and amavisd from the cli and amavisd testmails. Start  and   with the following commands:

If everything went well  should now be listening for mails on port 25 and for reinjected mails on port 10024. To verify this check your log file.

Now if no strange messages appear in the log file it is time for a new test.

Use  to manually connect to   on port 10024 and   on port 10025.

Add  and   to the   runlevel.

Creating the spamtrap user
Create the spamtrap account and directories.

Give the spamtrap user a sensible password.

If you manually want to check some of the mails to ensure that you have no false positives you can use the following  recipe to sideline spam found into different mail folders.

.procmailrc の作成
Now make sure that Postfix uses  to deliver mail.

メールフォルダの作成
Now we will create shared folders for ham and spam.

Amavisd-new needs to be able to read these files as well as all mailusers. Therefore we add all the relevant users to the mailuser group along with amavis.

This makes the spam and ham folders writable but not readable. This way users can safely submit their ham without anyone else being able to read it.

Then run the following command as the  user:

cron ジョブの追加
Now run  to edit the amavis crontab to enable automatic learning of the Bayes filter every hour.

amavisd.conf の変更
Now modify amavis to redirect spam emails to the  account and keep spamheaders.

後片付け
We don't want to keep mail forever so we use  to clean up regularily. Emerge it with. Only  is able to run   so we have to edit the   crontab.

はじめに
Greylisting is one of the newer weapons in the spam fighting arsenal. As the name implies it is much like whitelisting and blacklisting. Each time an unknown mailserver tries to deliver mail the mail is rejected with a try again later message. This means that mail gets delayed but also that stupid spam bots that do not implement the RFC protocol will drop the attempt to deliver the spam and never retry. With time spam bots will probably adjust, however it will give other technologies more time to identify the spam.

Postfix 2.1 come with a simple Perl greylisting policy server that implements such a scheme. However it suffers from unpredictable results when the partition holding the greylisting database run out of space. There exists an improved version that do not suffer this problem. First I will show how to install the builtin greylisting support that come with Postfix and then I will show how to configure the more robust replacement.

Simple greylisting
We need the file but unfortunately the ebuild does not install it as default.

Now we have the file in place we need to create the directory to hold the greylisting database:

Configuring greylisting
Now that we have all this ready all that is left is to add it to the postfix configuration. First we add the necessary information to the :

The postfix spawn daemon normally kills its child processes after 1000 seconds but this is too short for the greylisting process so we have to increase the timelimit in :

We don't want to use greylisting for all domains but only for those frequently abused by spammers. After all it will delay mail delivery. A list of frequently forged MAIL FROM domains can be found online. Add the domains you receive a lot of spam from to :

If you want a more extensive list:

Now we only have to initialize the database:

Now the setup of simple greylisting is complete.

Configuring improved greylisting with postgrey
You can install the enhanced greylisting policy server with a simple  :

After installing  we have to edit. Changes are almost exactly like the built in greylisting.

Finally, start the server and add it to the proper runlevel.

はじめに
SPF allows domain owners to state in their DNS records which IP addressess should be allowed to send mails from their domain. This will prevent spammers from spoofing the.

First domain owners have to create a special  DNS record. Then an SPF-enabled MTA can read this and if the mail originates from a server that is not described in the SPF record the mail can be rejected. An example entry could look like this:

The  means to reject all mail by default but allow mail from the ,   and   DNS records. For more info consult further resources below.

Spamassassin 3.0 has support for SPF, however it is not enabled by default and the new policy daemon in Postfix supports SPF so let's install SPF support for Postfix.

準備
First you have to install Postfix 2.1 as described above. When you have fetched the source grab the with:

This Perl script also needs some Perl libraries that are not in portage but it is still quite simple to install them:

Now that we have everything in place all we need is to configure Postfix to use this new policy.

Now add the SPF check in. Properly configured SPF should do no harm so we could check SPF for all domains:

MySOL の設定
For large domains the default values you can set in might not suit all users. If you configure amavisd-new with MySQL support you can have individual settings for users or groups of users.

Now that the database is created we'll need to create the necessary tables. You can cut and paste the following into the mysql prompt:

If you wish to use whitelisting and blacklisting you must add the sender and receiver to  after which you create the relation between the two e-mail addresses in   and state if it is whitelisting  or blacklisting.

Now that we have created the tables let's insert a test user and a test policy:

This inserts a test user and a Test policy. Adjust these examples to fit your needs. Further explanation of the configuration names can be found in.

Configuring amavisd to use MySQL
Now that MySQL is ready we need to tell amavis to use it:

Configuring Spamassassin to use MySQL
As of Spamassassin 3.0 it is possible to store the Bayes and AWL data in a MySQL database. We will use MySQL as the backend as it can generally outperform other databases. Also, using MySQL for both sets of data makes system management much easier. Here I will show how to easily accomplish this.

First start out by creating the new MySQL user and then create the needed tables.

Now that the database is created we'll create the necessary tables. You can cut and paste the following into the mysql prompt:

Configuring Spamassassin to use the MySQL backend
If you have an old Bayes database in the DBM database and want to keep it follow these instructions:

Now give Spamassassin the required info:

Next, change its permissions for proper security:

Now all you have to do is.

Amavisd-new
To troubleshoot Amavisd-new start out by stopping it with  and then start it manually in the foreground with   and watch it for anomalies in the output.

Spamassassin
To troubleshoot Spamassassin you can filter an email through it with. To ensure that the headers are intact you can move it from another machine with IMAP.

If you want you can make get the same information and more with Amavisd-new using.

Repeating tasks after installation
Some of the activities mentioned in this guide will need to be repeated after upgrades. For instance, the  in the section on  will need to be repeated after every update of amavisd-new.

Luckily, Gentoo provides you with the means to perform these steps automatically. In Hooking in the Emerge Process, the Gentoo Handbook explains how to execute tasks after installations of a particular package, like so:

Getting help
If you need help a good place to go is the amavis-user mailing list. Before postting a question try searching the Amavis User mailing list archives. If you find no answer here you can subscribe to the Amavis User mailing list

If your question is specific to SpamAssassin, DCC, Razor, or Postfix, please refer to their respective home pages listed below.

For further information

 * Amavisd-new INSTALL
 * Amavisd-new Postfix README
 * Amavisd-new Policy bank documentation
 * Spamassassin SQL README
 * Greylisting
 * Postfix SMTPD_POLICY_README
 * Blocking spammers with Postfix HELO controls
 * SPF Overview
 * Jim Seymour's Postfix Anti-UCE Cheat Sheet

General resources

 * Spamassassin
 * Amavisd-new
 * Amavisd-new documentation bits and pieces
 * Vipuls's Razor
 * Pyzor
 * Distributed Checksum Clearinghouse
 * Maia Mailguard

Other howtos

 * Fairly-Secure Anti-SPAM Gateway Using OpenBSD, Postfix, Amavisd-new, SpamAssassin, Razor and DCC