2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

スパムを撃退するSpamAssassinのセットアップ!

SpamAssassinスパムアサシンと読む。本家サイト(モジュールをダウンするなら)は、こちら → http://spamassassin.org/

(2004/05/22現在)
perl-Mail-SpamAssassin-2.63-1.i386.rpm
spamassassin-2.63-1.i386.rpm

上記が最新のパッケージである。前者がSpamAssassinのperlライブラリで後者がSpamAssassinのパッケージである。FreeBSDのPortsやVineLinuxPlusパッケージが有るが、自分が試したところどうもperlのライブラリファイルの整合性が合わなくエラーを出力するようだ。テストメールを受信してもSpamAssassinのヘッダー情報が出力されないため旨くないと考える。したがって、FreeBSDではソースからコンパイル、VineLinuxでは上記のRPMパッケージを使用することを進める。


1.SpamAssassinとは?

SpamAssassinは、Perlテキスト解析とORBブラックリストを組み合わせてspamを検出するメールフィルタである。決められたルールで、望まれないメール”spam”を検出する。spamとして判定されたメールにはspamとしてのタグを追加でき、容易にMUAによるフィルタリングが可能になる。受信メールの種類にもよるが、SpamAssassinはかなりの確率で、spamと正当なメールを正確に検出する。


2.インストール(俺のメル鯖VineLinuxの場合)

# rpm -Uvh perl-Mail-SpamAssassin-2.63-1.i386.rpm spamassassin-2.63-1.i386.rpm

ちなみに、FreeBSDでソースをコンパイルする場合、
# tar zxvf Mail-SpamAssassin-2.63.tar.gz
# chown -R root:wheel Mail-SpamAssassin-2.63
# cd Mail-SpamAssassin-2.63
# perl Makefile.PL
# make
# make isntall

一応、実行ファイルの居場所確認(笑)。実行ファイルは2種類有って、いずれかを選択できる。

# which spamassassin
/usr/bin/spamassassin

この実行ファイルは、その都度実行してSpam検出を行うモジュール。その都度実行するため、デーモンを起動しておかなくて済むが検出速度が遅いのが欠点。

# which spamc
/usr/bin/spamc

この実行ファイルは、spamdデーモンを起動した状態で実行してSpam検出を行うコントローラモジュール。検出速度は速いが、デーモンを起動しておかなくてはならない。


3.SpamAssassinの設定

① 定義ファイルを設定する

SpamAssassinは、定義ファイルを参照してSpamを検出する。ユーザ別では、各ユーザのHOMEディレクトリ配下の.spamassassin/user_prefsを参照する。全てのユーザ共通では、/etc/mail/spamassassin/local.cfを参照する。俺の場合、共通定義ファイルとして設定した。定義ファイルは、既に結構マニアックな定義ファイルが出てるため、使わせてもらう事にした。以下より、wgetして使うことにする。

# cd /etc/mail/spamassassin

# wget http://tlec.linux.or.jp/docs/user_prefs

# mv local.cf local.cf.bak

# mv user_prefs local.cf

② Procmailとの連携

SpamAssassinは、Procmailとの連携で動かすのがベストとされている。もちろん、MTAに組み込むことも出来る。俺の場合、たまたまpostfixのmain.cfから、

省略

# Procmail Command
mailbox_command = /usr/bin/procmail -m /etc/postfix/procmailrc

省略

のようにProcmailをキックしてるので俺の場合は、SpamAssassinをProcmailからの起動とした。

# vi /etc/postfix/procmailrc

DEFAULT=/var/spool/mail/$LOGNAME
SPAM=$HOME/.spam                
← Spam野郎を閉じこめるファイルを定義

:0fw spamassassin.lock
| /usr/bin/spamc                    
← SpamAssassinコントローラを起動

:0:
*^X-Spam-Status: Yes                   
← Spamだった場合のヘッダー$SPAM                     ← Spamだったら、.spamファイルに閉じこめる


4.SpamAssassinの起動

起動の為の準備。ランレベル3をonにする。

# chkconfig spamassassin on

# /etc/init.d/spamassassin start


5.本当に動くのかをテストする

添付されているサンプルSpamファイルを使って、ちゃんと動くかテストする。

① Spamだった場合

Spamのサンプルでテストし結果をlogへリダイレクトする。

[mity@michi mity]$ spamc < /usr/share/doc/spamassassin-2.63/sample-spam.txt > log
[mity@michi mity]$ more log

Received: from localhost by michi.kozupon.com
with SpamAssassin (2.63 2004-01-11);
Sat, 22 May 2004 23:33:09 +0900
From: Sender <sender@example.net>
To: Recipient <recipient@example.net>
Subject: Test spam mail (GTUBE)
Date: Wed, 23 Jul 2003 23:30:00 +0200
Message-Id: <GTUBE1.1010101@example.net>
X-Spam-Flag: YES
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on michi.kozupon.com
X-Spam-Status: Yes, hits=1000.0 required=7.0 tests=GTUBE autolearn=no
version=2.63
X-Spam-Level: **************************************************
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=”———-=_40AF64A5.903BE025″

This is a multi-part message in MIME format.

————=_40AF64A5.903BE025
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Spam detection software, running on the system “michi.kozupon.com”, has
identified this incoming email as possible spam. The original message
has been attached to this so you can view it (if it isn’t spam) or block
similar future email. If you have any questions, see
the administrator of that system for details.

Content preview: This is the GTUBE, the Generic Test for Unsolicited
Bulk Email If your spam filter supports it, the GTUBE provides a test
by which you can verify that the filter is installed correctly and is
detecting incoming spam. You can send yourself a test mail containing
the following string of characters (in upper case and with no white
spaces and line breaks): […]

Content analysis details: (1000.0 points, 7.0 required)

pts rule name description
—————————————————————————-
1000 GTUBE BODY: Generic Test for Unsolicited Bulk Email

————=_40AF64A5.903BE025
Content-Type: message/rfc822; x-spam-type=original
Content-Description: original message before SpamAssassin
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Subject: Test spam mail (GTUBE)
Message-ID: <GTUBE1.1010101@example.net>
Date: Wed, 23 Jul 2003 23:30:00 +0200
From: Sender <sender@example.net>
To: Recipient <recipient@example.net>
Precedence: junk
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is the GTUBE, the
Generic
Test for
Unsolicited
Bulk
Email

If your spam filter supports it, the GTUBE provides a test by which you
can verify that the filter is installed correctly and is detecting incoming
spam. You can send yourself a test mail containing the following string of
characters (in upper case and with no white spaces and line breaks):

XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

You should send this test mail from an account outside of your network.


————=_40AF64A5.903BE025–

② Spamでない場合

Spamでないサンプルでテストし、log2へリダイレクトする。

[mity@michi mity]$ spamc < /usr/share/doc/spamassassin-2.63/sample-nonspam.txt > log
[mity@michi mity]$ more log2

Return-Path: <tbtf-approval@world.std.com>
Delivered-To: foo@foo.com
Received: from europe.std.com (europe.std.com [199.172.62.20])
by mail.netnoteinc.com (Postfix) with ESMTP id 392E1114061
for <foo@foo.com>; Fri, 20 Apr 2001 21:34:46 +0000 (Eire)
Received: (from daemon@localhost)
by europe.std.com (8.9.3/8.9.3) id RAA09630
for tbtf-outgoing; Fri, 20 Apr 2001 17:31:18 -0400 (EDT)
Received: from sgi04-e.std.com (sgi04-e.std.com [199.172.62.134])
by europe.std.com (8.9.3/8.9.3) with ESMTP id RAA08749
for <tbtf@facteur.std.com>; Fri, 20 Apr 2001 17:24:31 -0400 (EDT)
Received: from world.std.com (world-f.std.com [199.172.62.5])
by sgi04-e.std.com (8.9.3/8.9.3) with ESMTP id RAA8278330
for <tbtf@facteur.std.com>; Fri, 20 Apr 2001 17:24:31 -0400 (EDT)
Received: (from dawson@localhost)
by world.std.com (8.9.3/8.9.3) id RAA26781
for tbtf@world.std.com; Fri, 20 Apr 2001 17:24:31 -0400 (EDT)
Received: from sgi04-e.std.com (sgi04-e.std.com [199.172.62.134])
by europe.std.com (8.9.3/8.9.3) with ESMTP id RAA07541
for <tbtf@facteur.std.com>; Fri, 20 Apr 2001 17:12:06 -0400 (EDT)
Received: from world.std.com (world-f.std.com [199.172.62.5])
by sgi04-e.std.com (8.9.3/8.9.3) with ESMTP id RAA8278330
for <tbtf@facteur.std.com>; Fri, 20 Apr 2001 17:24:31 -0400 (EDT)
Received: (from dawson@localhost)
by world.std.com (8.9.3/8.9.3) id RAA26781
for tbtf@world.std.com; Fri, 20 Apr 2001 17:24:31 -0400 (EDT)
Received: from sgi04-e.std.com (sgi04-e.std.com [199.172.62.134])
by europe.std.com (8.9.3/8.9.3) with ESMTP id RAA07541
for <tbtf@facteur.std.com>; Fri, 20 Apr 2001 17:12:06 -0400 (EDT)
Received: from world.std.com (world-f.std.com [199.172.62.5])
by sgi04-e.std.com (8.9.3/8.9.3) with ESMTP id RAA8416421
for <tbtf@facteur.std.com>; Fri, 20 Apr 2001 17:12:06 -0400 (EDT)
Received: from [208.192.102.193] (ppp0c199.std.com [208.192.102.199])
by world.std.com (8.9.3/8.9.3) with ESMTP id RAA14226
for <tbtf@world.std.com>; Fri, 20 Apr 2001 17:12:04 -0400 (EDT)
Mime-Version: 1.0
Message-Id: <v0421010eb70653b14e06@[208.192.102.193]>
Date: Fri, 20 Apr 2001 16:59:58 -0400
To: tbtf@world.std.com
From: Keith Dawson <dawson@world.std.com>
Subject: TBTF ping for 2001-04-20: Reviving
Content-Type: text/plain; charset=”us-ascii”
Sender: tbtf-approval@world.std.com
Precedence: list
Reply-To: tbtf-approval@europe.std.com
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on michi.kozupon.com
X-Spam-Status: No, hits=1.0 required=7.0 tests=LINES_OF_YELLING,QENCPTR2
autolearn=no version=2.63
X-Spam-Level: *

—–BEGIN PGP SIGNED MESSAGE—–
TBTF ping for 2001-04-20: Reviving

T a s t y B i t s f r o m t h e T e c h n o l o g y F r o n t

Timely news of the bellwethers in computer and communications
technology that will affect electronic commerce — since 1994

Your Host: Keith Dawson

ISSN: 1524-9948

This issue: < http://tbtf.com/archive/2001-04-20.html >

To comment on this issue, please use this forum at Quick Topic:
< http://www.quicktopic.com/tbtf/H/kQGJR2TXL6H >
________________________________________________________________________

Q u o t e O f T h e M o m e n t
Even organizations that promise “privacy for their customers” rarely
if ever promise “continued privacy for their former customers…”
Once you cancel your account with any business, their promises of
keeping the information about their customers private no longer
apply… you’re not a customer any longer.

This is in the large category of business behaviors that individuals
would consider immoral and deceptive — and businesses know are not
illegal.

— “_ankh,” writing on the XNStalk mailing list
________________________________________________________________________

..TBTF’s long hiatus is drawing to a close

Hail subscribers to the TBTF mailing list. Some 2,000 [1] of you
have signed up since the last issue [2] was mailed on 2000-07-20.
This brief note is the first of several I will send to this list to
excise the dead addresses prior to resuming regular publication.

While you time the contractions of the newsletter’s rebirth, I in-
vite you to read the TBTF Log [3] and sign up for its separate free
subscription. Send “subscribe” (no quotes) with any subject to
tbtf-log-request@tbtf.com . I mail out collected Log items on Sun-
days.

If you need to stay more immediately on top of breaking stories,
pick up the TBTF Log’s syndication file [4] or read an aggregator
that does. Examples are Slashdot’s Cheesy Portal [5], Userland [6],
and Sitescooper [7]. If your news obsession runs even deeper and you
own an SMS-capable cell phone or PDA, sign up on TBTF’s WebWire-
lessNow portal [8]. A free call will bring you the latest TBTF Log
headline, Jargon Scout [9] find, or Siliconium [10].

Two new columnists have bloomed on TBTF since last summer: Ted By-
field’s roving_reporter [11] and Gary Stock’s UnBlinking [12]. Late-
ly Byfield has been writing in unmatched depth about ICANN, but the
roving_reporter nym’s roots are in commentary at the intersection of
technology and culture. Stock’s UnBlinking latches onto topical sub-
jects and pursues them to the ends of the Net. These writers’ voices
are compelling and utterly distinctive.

[1] http://tbtf.com/growth.html
[2] http://tbtf.com/archive/2000-07-20.html
[3] http://tbtf.com/blog/
[4] http://tbtf.com/tbtf.rdf
[5] http://www.slashdot.org/cheesyportal.shtml
[6] http://my.userland.com/
[7] http://www.sitescooper.org/
[8] http://tbtf.com/pull-wwn/
[9] http://tbtf.com/jargon-scout.html
[10] http://tbtf.com/siliconia.html
[11] http://tbtf.com/roving_reporter/
[12] http://tbtf.com/unblinking/
________________________________________________________________________

S o u r c e s

> For a complete list of TBTF’s email and Web sources, see
http://tbtf.com/sources.html .
________________________________________________________________________

B e n e f a c t o r s

TBTF is free. If you get value from this publication, please visit
the TBTF Benefactors page < http://tbtf.com/the-benefactors.html >
and consider contributing to its upkeep.
________________________________________________________________________

TBTF home and archive at http://tbtf.com/ . To unsubscribe send
the message “unsubscribe” to tbtf-request@tbtf.com. TBTF is Copy-
right 1994-2000 by Keith Dawson, <dawson@world.std.com>. Commercial
use prohibited. For non-commercial purposes please forward, post,
and link as you see fit.
_______________________________________________
Keith Dawson dawson@world.std.com
Layer of ash separates morning and evening milk.

—–BEGIN PGP SIGNATURE—–
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQCVAwUBOuCi3WAMawgf2iXRAQHeAQQA3YSePSQ0XzdHZUVskFDkTfpE9XS4fHQs
WaT6a8qLZK9PdNcoz3zggM/Jnjdx6CJqNzxPEtxk9B2DoGll/C/60HWNPN+VujDu
Xav65S0P+Px4knaQcCIeCamQJ7uGcsw+CqMpNbxWYaTYmjAfkbKH1EuLC2VRwdmD
wQmwrDp70v8=
=8hLB
—–END PGP SIGNATURE—–

これで、ちゃんと動いてることが解った。


6.いやいやまだ動いてるか信じられない

SpamAssassinを動作させて、メールを受信してみる。そのメールのヘッダーのプロパティを見て、

X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on michi.kozupon.com
X-Spam-Status: No, hits=5.0 required=7.0 tests=FAKEDWORD_EXCLAMATION, FORGED_RCVD_NET_HELO,MULTIPART_ALTERNATIVE autolearn=no version=2.63
X-Spam-Level: *****
Status:

のようなヘッダー情報が有れば動いてる証拠だ。上記は、Spamではなかったときのヘッダー情報。
Spamだった場合は、 X-Spam-Status: Yes になる。


7.これもSpamだとSpamAssassinに覚えさせる!

定義ファイルを参照させているので別段問題はないが、本当はSpamなのに検出しなかった場合は無理矢理「これもSpamだ!学習せい!」と覚えさせる
事が出来る。~/mail/spamdirにテキストにしてスパム達を入れておく。そして以下のコマンドで学習させる。

$ /usr/bin/sa-learn –spam ~/spamdir

逆に、Spamではないメールを覚えさせるには、同じ要領でSpamではないメールを~/mail/nonspamdirに入れておく。

$ /usr/bin/sa-learn –nonspam ~/nonspamdir

上記の方法で学習させることができる。

$ /usr/bin/sa-learn –rebuild

最後に結果を反映する。

以上

コメント