Mailfiltering Gateway/ko

이 안내서는 Postfix의 스팸 차단 기능에 대한 과정별 안내서입니다. 이 과정에서 Amavisd-new, 스팸 어쌔신, ClamAV, 그레이 리스팅, SPF를 활용합니다.

도입부
이 안내서에서는 스팸 및 바이러스를 걸러내는 메일 게이트웨이를 설치하는 방법을 과정별로 설명합니다. 단일 서버 솔루션에 적용할 때 꽤 단순합니다.

대략적인 그림
이 문서는 다중 도메인에 대한 스팸 차단 메일 게이트웨이 설정 방법을 설명합니다. 이 서버는 메일 계정을 실제로 보유하고 있는 메일 서버(마이크로소프트 익스체인지 또는 로터스 노츠 등)의 앞단에서 실행합니다.

이 설치 과정에서 적절한 보안 레코드와 알아보기 쉬운 설정 파일을 갖춘 프로그램을 선택합니다. 전자메일 MTA로는 적절한 보안레코드를 보유하고 있으며 설정을 올바르게 처리하는데 상당히 쉬운 postfix를 활용합니다. Postfix는 메일 수신에 보통 25번 포트로 감청합니다. 이 과정에서 Amavisd-new에 10024번 포트를 통해 전달합니다. Amavisd-new 는 다음 메일 서버로 메일을 전달할 10025번 포트를 통해 Postfix로 메일을 다시 되돌리기 전에 다양한 필터를 거칩니다.

Amavisd-new는 내용 기반 차단 프레임워크이며 바이러스 및 스팸을 차단하는 도우미 프로그램을 제대로 동작하게 합니다. 이 설치 과정에서 바이러스를 차단하는 ClamAV 그리고 스팸을 차단하는 스팸 어쌔신을 두가지 도우미 프로그램으로 활용하겠습니다. 스팸 어쌔신 자체는 내용 기반 차단 프레임워크 계층 기능을 잇따라 수행하며, Vipul's Razor2와 DCC 도우미 프로그램을 동작합니다.

RBL 및 기타 스팸 처리 기능 프로그램과는 달리 스팸 어쌔신은 단순히 일회 시험만을 기반으로 하는 전자메일 수용, 거절 기능만을 수행하지 않습니다. 내부 시험과 외부 도우미 프로그램을 통해 거쳐간 모든 전자메일을 기반으로 스팸 가중치를 계산합니다. 이 가중치는 다음 시험 과정을 기반으로 합니다:


 * 베이지안 필터링
 * 정규 표현식에 기반한 정적 규칙
 * 분산 협업 네트워크
 * RBLs
 * Razor2
 * Pyzor
 * DCC

The first part (chapters 1 to 4) of the guide will describe the basic setup of a mailfiltering gateway. The next chapters can be implemented individually with no dependence between each chapter. These chapters describe how to:


 * setup special IMAP folders for learning of the Bayesian filter and for delivery of false positives
 * setup greylisting with Postfix
 * setup Amavisd-new to use a MySQL backend for user preferences
 * setup Spamassassin to use a MySQL backend for AWL and Bayes data

A planned fifth part will contain various tips regarding performance and things you may want to know (running chrooted, postfix restrictions, etc.).

준비
설치한 Postfix가 잘 동작하는지 확인하기 전에 메일을 주고 받을 수 있는 네트워크에 백엔드 메일 서버가 필요합니다. Postfix를 설정해본 경험이 없다면 한번에 모든 부분을 설정해야 한다고 할 경우 상당히 복잡한 느낌이 바로 찾아올 것입니다. 도움이 필요하다면 젠투 위키에 있는 가상 메일 서버 완벽 안내서 를 참고하십시오

필요한 프로그램 설치
가장 중요한 Amavisd-new, Spamassassin, ClamAV 프로그램 설치로 시작하겠습니다.

DNS 설정
프로그램을 이머지하는 동안 다른 쉘을 띄우시고 필요한 DNS 레코드를 만드십시오.

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

방화벽 개방
In addition to allowing normal mail traffic you have to allow a few services through your firewall to allow the network checks to communicate with the servers.

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.

We also need to set the next hop destination for mail. Tell Postfix to filter all mail through an external content filter and enable explicit routing to let Postfix know where to forward the mail to.

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 is used to handle all the filtering and allows you to easily glue together severel different technologies. Upon reception of a mail message it will extract the mail, filter it through some custom filters, handle white and black listing, filter the mail through various virus scanners and finally it will filter the mail using 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.

에서 다음 부분을 편집하십시오

Create a quarantine directory for the virus mails as we don't want these delivered to our users.

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.

마지막으로 파일에서 새 소켓 위치 값으로 바꾸십시오.

Vipul's Razor 설정
Razor2는 협업 분산 스팸 검사합 네트워크입니다. 명령으로 설치하고 필요한 설정 파일을 만드십시오. 사용자로 다음  를 입력하여 실행하십시오.

분산 검사합 정리 저장소(Distributed Checksum Clearinghouse : dcc) 설정
Like Razor2, dcc is a collaborative and distributed spam checksum network. Its philosopy is to count the number of recipients of a given mail identifying each mail with a fuzzy checksum.

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.

설정 시험
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.

이제 로그 파일에 이상한 메시지가 안나타난다면 새로 테스트 해볼 시간입니다.

으로 에 접속할 때 10024 포트를,  에 접속할 때 10025 포트를 활용하십시오.

와 를   런레벨에 추가하십시오.

spamtrap 사용자 만들기
spamtrap 계정과 디렉터리를 민드십시오.

spamtrap 사용자에게 제대로 된 암호를 부여하십시오.

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 만들기
이제 Postfix 에서 메일을 전달할 때 을 사용하는지 확인하십시오.

메일 폴더 만들기
이제 햄과 스팸을 처리할 공유 폴더를 만들겠습니다.

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.

사용자로 다음 명령을 실행하십시오:

크론 작업 추가
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.

간단한 그레이 리스팅
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:

그레이 리스팅 설정
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:

이제 간단한 그레이 리스팅 설정은 끝났습니다.

postgrey로 그레이 리스팅 설정 개선하기
간단한 명령으로 개선된 그레이 리스팅 정책 서버를 설치할 수 있습니다:

를 설치한 후 를 편집해야 합니다. 바꿀 내용은 이미 그레이리스팅한 내용과 거의 정확하게 비슷합니다.

마지막으로, 서버를 시작하고 적당한 런레벨에 추가하십시오.

도입부
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:

MySQL 설정
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.

MySQL을 활용하여 amavisd 설정
Now that MySQL is ready we need to tell amavis to use it:

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:

MySQL 백엔드를 사용하도록 스팸 어쌔신 설정
DBM 데이터베이스에서 오래된 Bayes 데이터베이스를 보유하고 있고 다음 절차를 통해 유지하려면:

이제 필요한 정보를 스팸 어쌔신에 제공하십시오:

다음 보안 수준을 만족스러운 수준으로 끌어올리기 위해 권한을 바꾸십시오:

이제 해야 할 일은 명령의 실행입니다.

Amavisd-new
Amavisd-new 문제를 해결하려면 명령으로 서비스를 멈추고  명령으로 전면 실행하여 출력 내용에 이상한 점이 없는지 관찰하십시오.

스팸 어쌔신
스팸 어쌔신의 문제를 찾을 때 명령으로 전자메일을 걸러볼 수 있습니다. 헤더에 문제가 없는지 확인하려면 다른 머신에서 IMAP으로 메일을 가져올 수 있습니다.

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

설치 후 작업 반복 처리
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:

도움 받기
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.

더 많은 정보

 * 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

일반 자료

 * 스팸 어쌔신
 * Amavisd-new
 * Amavisd-new 문서 모음
 * Vipuls's Razor
 * Pyzor
 * 분산 검사합 정리 저장소
 * Maia Mailguard

다른 설명서

 * OpenBSD, Postfix, Amavisd-new, 스팸 어쌔신, Razor, DCC를 활용한 매우 안전한 스팸 차단 게이트웨이