*SpamAssassin(スパム対策ソフト) [#aa24b114]

RIGHT:更新日 &lastmod();

SpamAssassin(スパムアサシン)はprocmailから起動して条件ごとに決められた ポイントを加算ししきい値を超えたらspamメールと判断するソフトで、Razorと いうデータベースとも連携することができ、spamメールを排除するperlスクリプト

**SpamAssassin-3.3.2 [#a8fcb636]

Vine6.xでインストールすると以下のモジュールが必要なようだ

-REQUIRED module missing: Net::DNS
-REQUIRED module missing: NetAddr::IP
-optional module missing: Digest::SHA1
-optional module missing: Mail::SPF
-optional module missing: IP::Country
-optional module missing: Razor2
-optional module missing: Net::Ident
-optional module missing: IO::Socket::INET6
-optional module missing: IO::Socket::SSL (うまくインストールできず)
-optional module missing: Mail::DKIM (うまくインストールできず)
-optional module missing: Encode::Detect

***Perl CPANのネットワークインストール設定 [#y82e8c99]

 # perl -MCPAN -e shell
 
 (略)
 Would you like me to automatically choose the best CPAN mirror
 sites for you? (This means connecting to the Internet and could
 take a couple minutes) [yes] <=Enter
 (略)
 
 If you prefer to enter a dialog instead, you can answer 'no' to this
 question and I'll let you configure in small steps one thing after the
 other. (Note: you can revisit this dialog anytime later by typing 'o
 conf init' at the cpan prompt.)
 
 Would you like me to configure as much as possible automatically? [yes] <=Enter
 
 (略)
 
 cpan[1]> 

''Anonymous FTPの設定''

ユーザ名、パスワードの変更(anonymous)

 cpan[20]> o conf username ftp
 
 cpan[20]> o conf password okada@ism21.net

''DLサイトの変更''

 cpan[22]> o conf urllist ftp://cpan.cs.utah.edu/CPAN/ ftp://cpan-\
 sj.viaverio.com/pub/CPAN/ ftp://cpan.llarian.net/pub/CPAN/\
 ftp://mirrors1.kernel.org/pub/CPAN/ ftp://mirrors2.kernel.org/pub/CPAN/
 Please use 'o conf commit' to make the config permanent!
 
 cpan[23]> o conf commit
 commit: wrote '/usr/lib64/perl5/5.12.3/CPAN/Config.pm'
 
 cpan[24]> o conf urllist
     urllist
         0 [ftp://cpan.cs.utah.edu/CPAN/]
         1 [ftp://cpan-sj.viaverio.com/pub/CPAN/]
         2 [ftp://cpan.llarian.net/pub/CPAN/]
         3 [ftp://mirrors1.kernel.org/pub/CPAN/]
         4 [ftp://mirrors2.kernel.org/pub/CPAN/]
 Type 'o conf' to view all configuration items

''表示''

 cpan[3]> o conf
 $CPAN::Config options from '/usr/lib64/perl5/5.12.3/CPAN/Config.pm':
    commit             [Commit changes to disk]
     defaults           [Reload defaults from disk]
     help               [Short help about 'o conf' usage]
     init               [Interactive setting of all options]
 
     applypatch         []
     auto_commit        [0]

''モジュールインストール''

 cpan[25]> install Net::DNS
 Fetching with LWP:
 ftp://cpan.cs.utah.edu/CPAN/authors/01mailrc.txt.gz
 Going to read '/root/.cpan/sources/authors/01mailrc.txt.gz'
 ............................................................................DONE
 Fetching with LWP:
 
 (略)
 
 Installing /usr/share/man/man3/Net::DNS::RR::MX.3pm
 Installing /usr/share/man/man3/Net::DNS::Resolver::Base.3pm
 Installing /usr/share/man/man3/Net::DNS::RR::MB.3pm
 Appending installation info to /usr/lib64/perl5/5.12.3/x86_64-linux-thread- multi/perllocal.pod
   OLAF/Net-DNS-0.66.tar.gz
   /usr/bin/make install  -- OK


***Razor2をインストール [#df67735b]
DL後展開して

 $ perl Makefile.PL
 $ make
 $ make test
 $ su
 # make install


***SpamAssassinのインストール [#gd4840d6]
 $ perl Makefile.PL
 
 (略)
 
 Checking if your kit is complete...
 Looks good
 Warning: prerequisite Mail::DKIM 0.31 not found.
 Writing Makefile for Mail::SpamAssassin
 Makefile written by ExtUtils::MakeMaker 6.56
 
 $ make
 $ make test
 
 t/whitelist_to.t .................. ok
 t/zz_cleanup.t .................... ok
 All tests successful.
 Files=165, Tests=2013, 163 wallclock secs ( 0.40 usr  0.67 sys + 37.10 cusr   8.58 csys = 46.75 CPU)
 Result: PASS
 
 $ su
 # make install

''定義ファイルの設定''

SPAM定義ファイル作成およびUpdate

定義ファイルを作成しないと動作しない

 # /usr/bin/sa-update

cronで自動Updateする(月曜 1時 20分)

 20 1 * * 1 /usr/bin/sa-update  > /dev/null 2>&1


**SpamAssassinのインストール [#s8a93702]
SpamAssassinを[[ここ:http://spamassassin.apache.org/downloads.cgi]]から Download

***モジュール事前インストール [#y7897d1b]
事前にHTML::Parser.pmとHTML::Tagset.pmのPerlモジュールをインストール [[ここ:http://search.cpan.org/]]からDownloadする。

Vine4.0 SpamAssassin-3.1.7ではDigest::SHA1をリクエストされたのでインストールした。それ以外もいくつかのオプション(optional module missing: Net::DNS)でワーニングが出たがとろあえず無視した。

 $ tar zxvf HTML-Tagset-3.03.tar.gz
 $ cd HTML-Tagset-3.03
 $ perl Makefile.PL
 Checking if your kit is complete...
 Looks good
 Writing Makefile for HTML::Tagset
 $ make
 cp Tagset.pm blib/lib/HTML/Tagset.pm
 Manifying blib/man3/HTML::Tagset.3pm
 $ make test
 PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/usr/lib/perl5/5.6.1/i386-linux -I/usr/lib/perl5/5.6.1 test.pl
 1..1
 ok 1
 $ su
 # make install
 # make install
 Installing /usr/share/man/man3/HTML::Tagset.3pm
 Writing /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/HTML/Tagset/.packlist
 Appending installation info to /usr/lib/perl5/5.6.1/i386-linux/perllocal.pod
 
 $ tar tar zxvf HTML-Parser-3.36.tar.gz
 $ cd HTML-Parser-3.36
 $ perl Makefile.PL
 Perl-5.8 provide core support for Unicode strings.  You can compile
 (略)
 Do you want decoding on unicode entities? [no] <--(Enterを入力)
 Writing Makefile for HTML::Parser
 
 $ make
 gcc -c  -fno-strict-aliasing -O2 -m486 -fno-strength-reduce \
 -DVERSION=\"3.36\" -DXS_VERSION=\"3.36\" -fPIC -I/usr/lib/perl5/5.6.1/i386-linux/CORE -DMARKED_SECTION Parser.c
 (略)
 Manifying blib/man3/HTML::Parser.3pm
 Manifying blib/man3/HTML::Entities.3pm
 Manifying blib/man3/HTML::TokeParser.3pm
 Manifying blib/man3/HTML::Filter.3pm
 $ make test
 PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/usr/lib/perl5/5.6.1/
 i386-linux -I/usr/lib/perl5/5.6.1 -e 'use Test::Harness qw(&runtests $verbose)
 ; $verbose=0; runtests @ARGV;' t/*.t
 t/api_version.......ok
 (略)
 t/uentities.........skipped: Unicode entities not selected
 t/unbroken-text.....ok
 t/xml-mode..........ok
 All tests successful, 3 tests skipped.
 Files=42, Tests=228, 13 wallclock secs ( 6.40 cusr +  2.69 csys =  9.09 CPU)
 $ su
 # make install

***SpamAssassinのインストール [#v8f5f9f6]

 $ tar zxvf Mail-SpamAssassin-2.63.tar.gz
 $ cd Mail-SpamAssassin-2.63
 $ perl Makefile.PL
 (個人インストールは perl Makefile.PL PREFIX=~/sausr SYSCONFDIR=~/saetc)
 
 What email address or URL should be used in the suspected-spam report
 text for users who want more information on your filter installation?
 (In particular, ISPs should change this to a local Postmaster contact)
 default text: [the administrator of that system]okada@localhost <--アドレスを入力
 
 Checking if your kit is complete...
 Looks good
 $ make
 $ make test
 $ su
 # make install

***起動 [#a69ad782]

 # /usr/bin/spamd > /dev/null 2>&1 &

''設定(個人)''

~/.forward
 "|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #okada"

~/.procmailrc

 MAILDIR=$HOME/Maildir
 DEFAULT=$MAILDIR/
 
 :0fw: spamassassin.lock
 | /usr/bin/spamc
 :0:
 * ^X-Spam-Status: Yes
 #Spammail/.  <==この設定(/.)だとスパムメールが単純な1,2,3のような番号のファイル名
 になる。また、curフォルダにリンクを張って複数のリーダ(Outlook Express と
 ActiveMail)から読むとおかしくなるので以下のようなに指定する
 .spam/      <==/.はつけない。これでIMAPフォルダとしてsapmを指定する
 (一行目2文字はゼロ)
 (個人インストールは2行目を/home/okada/sausr/bin/spamassasinにする)

3行目からは、ヘッダーに^X-Spam-Status: YesがあればSpammailというディレクトリに入れる指示

''サーバとして設定''

サーバとして設定するにはメールボックスへの配信をpostfixからprocmailに変更する

/etc/postfix/main.cfの
 mailbox_command = /usr/bin/procmail
に変更。

サーバ全体のユーザに利用してもらうために個人設定と同じ内容(~/.procmailrc)を
 /etc/procmailrc
に記入し、postfixをreloadする。

&color(red){両方設定したときはprocmailは個人設定よりサーバ設定のほうが優先される};

***動作確認 [#r4cc891d]

''試験メール1(スパムでないメール)''

 From okada@abc.ac.jp  Fri Jul  2 09:13:31 2004
 Delivered-To: okada@[10.99.99.125]
 From: okada <okada@abc.ac.jp>
 To: okada@[10.99.99.125]
 Date: Fri, 2 Jul 2004 10:04:52 +0900
 Subject: TEST2
 MIME-Version: 1.0
 Content-Type: text/plain; charset="ISO-2022-JP"
 Content-Transfer-Encoding: 7bit
 X-Mailer: nPOPQ Ver 1.0.1d
 X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on
         vvine26r3.abc.ac.jp
 X-Spam-Status: No, hits=0.0 required=5.0 tests=none autolearn=ham version=2.63  <--ここ
 X-Spam-Level:
 
 
 岡田です。
 
 TEST2

-------------------------------------

''試験メール2(スパムメール)''
本文はMail-SpamAssassin-2.63/sample-spam.txtを送る。

送り先と送り元を以下のように修正して
 From: Sender <okada@[10.99.99.125]>
 To: okada <okada@[10.99.99.125]>
 
 $ /usr/sbin/sendmail -oi -t < sample-spam.txt
 
 From okada@vvine26r3.abc.ac.jp  Fri Jul  2 15:16:47 2004
 Received: from localhost by vvine26r3.abc.ac.jp
         with SpamAssassin (2.63 2004-01-11);
         Fri, 02 Jul 2004 15:17:01 +0900
 From: Sender <okada@[10.99.99.125]>
 To: okada <okada@[10.99.99.125]>
 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
         vvine26r3.abc.ac.jp
 X-Spam-Status: Yes, hits=1007.7 required=12.0 tests=DATE_IN_PAST_96_XX,GTUBE,
         NO_DNS_FOR_FROM,RAZOR2_CF_RANGE_51_100,RAZOR2_CHECK autolearn=no
         version=2.63
 (ここに検査時にHitした項目が表示される)
 X-Spam-Level: **************************************************
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----------=_40E4FDDD.AC6A48DB"
 
 This is a multi-part message in MIME format.
 
 ------------=_40E4FDDD.AC6A48DB
 Content-Type: text/plain
 Content-Disposition: inline
 Content-Transfer-Encoding: 8bit
 
 Spam detection software, running on the system "vvine26r3.abc.ac.jp", 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
 okada@localhost 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:   (1007.7 points, 12.0 required) 
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
  1000 GTUBE                  BODY: Generic Test for Unsolicited Bulk Email
  1.5 RAZOR2_CF_RANGE_51_100 BODY: Razor2 gives confidence between 51 and 100
                            [cf: 100]
  1.5 RAZOR2_CHECK           Listed in Razor2 (http://razor.sf.net/)
  3.5 NO_DNS_FOR_FROM        Domain in From header has no MX or A DNS records
  1.2 DATE_IN_PAST_96_XX     Date: is 96 hours or more before Received: date
  
  
 
 ------------=_40E4FDDD.AC6A48DB
 Content-Type: message/rfc822; x-spam-type=original
 Content-Description: original message before SpamAssassin
 Content-Disposition: inline
 Content-Transfer-Encoding: 8bit
 
 Return-Path: <okada@vvine26r3.abc.ac.jp>
 Delivered-To: okada@[10.99.99.125]
 Received: by vvine26r3.abc.ac.jp (Postfix, from userid 500)
         id 140A4E133D; Fri,  2 Jul 2004 15:16:46 +0900 (JST)
 Subject: Test spam mail (GTUBE)
 Message-ID: <GTUBE1.1010101@example.net>
 Date: Wed, 23 Jul 2003 23:30:00 +0200
 From: Sender <okada@[10.99.99.125]>
 To: okada <okada@[10.99.99.125]>
 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.
 
 
 ------------=_40E4FDDD.AC6A48DB--

***捕らえたスパムメールを指定ディレクトリに取り込む [#ge431721]

~Maildir/Caughtspamというディレクトリを作成しておきそこに取り込む

.procmailrcに追加
 :0fw: spamassassin.lock
 | /usr/bin/spamc
 (以下の3行を追加)
 :0:
 * ^X-Spam-Status: Yes
 .spam/

''spamメールの捕らえたのを確認''
 $ cd Caughtspam
 $ ls -l
 合計 8
 -rw-------    1 okada    okada        3603 Jul  2 09:25 msg.MfKC
 -rw-------    1 okada    okada        3604 Jul  2 09:27 msg.SfKC

スパムも解析は

内容を表示すると

 Content analysis details:   (10.4 points, 7.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.1 ISO2022JP_CHARSET      ISO-2022-JP message
  0.1 X_MAILER_PRESENT       exists:X-Mailer
  5.4 INVALID_DATE           Invalid Date: header (not RFC 2822)
 -0.1 ISO2022JP_BODY         BODY: ISO-2022-JP message
  0.5 FAKEDWORD_ATMARK       BODY: ex. em@il (this rule is only for body)
  1.9 DATE_IN_FUTURE_06_12   Date: is 6 to 12 hours after Received: date
  2.7 FORGED_MUA_MOZILLA     Forged mail pretending to be from Mozilla


にある。この場10.4ポイントで7.0ポイント以上なのでスパムになった。

***チェックのパラメータの設定 [#dd997abf]
/etc/mail/spamassassin/local.cfの中の
しきい値は rrequired_score 10.0 (旧バージョン:equired_hits 10.0)

各パラメータのしきい値は
 score INVALID_DATE 5.4
等を設定

以下設定例

 # 2バイトコードの判定をゆるやかにするために ポイントを0に変更
 score HEADER_8BITS              0
 score HTML_COMMENT_8BITS        0
 score SUBJ_FULL_OF_8BITS        0
 score UPPERCASE_25_50           0
 score UPPERCASE_50_75           0
 score UPPERCASE_75_100          0
 
 # SPAM判定した場合には subjetctタグの文字列を加える場合 1。
 # そのままにしておきたい場合には 0。
 rewrite_subject         1
 subject_tag             [SPAMASS]
 # X-Spam-Levelの*をヘッダーに加える場合 1
 spam_level_stars        1
 # SPAMの時だけヘッダーを出すようにするには 0。常に出すなら 1。
 always_add_headers      0
 # SPAM判定された場合にその判定理由を出す場合には 0。(デフォルト)
 # 出したくない場合には 1にしておく。
 always_add_report       1
 # 指定数値以上をSPAMと判定する デフォルトは5。
 required_hits           10
 # ある程度受け取る言語を限定する場合には指定。デフォルトは all。
 ok_languages ja en
 # HTMLフォームのメールなどで識別できる場合に指定すれば判定可能。
 # デフォルトは all。
 ok_locales ja en
 
 # ユーザのディレクトリでusers_prefsを使わせる場合には1を指定。
 # デフォルトは0で使わせないようになっているらしい。
 allow_user_rules        1
 # レポートと本文の表示のされ方
 # 0:本文は変更しない 1:オリジナルページは添付に変更 2:本文はその後に記述
 report_safe             0
 # 短めのメッセージにする場合には 1。長めにする場合は0。デフォルトは0
 use_terse_report        1
 # 自動的にホワイトリストに加えるリストを作成する場合には指定
 # ディレクトリとかは事前に作成の必要性がある
 # auto_whitelist_path /var/spool/spamassassin/auto-whitelist
 
 # ベイジアンにより学習させておく場合には指定すると良い
 # use_bayes 1
 # bayes_auto_learn 1
 # bayes_path /var/spool/spamassassin/bayes
 
 
 # 信頼し、判定から除外する場合には指定
 trusted_networks        10.99.99.
 
**スパムデータベース(Razor)の導入 [#o1fc27d5]
Razorを [[ここ:http://razor.sourceforge.net/]]からDownload

 $ tar zxvf razor-agents-2.40.tar.gz
 $ cd razor-agents-2.40
 $ perl Makefile.PL
 Checking if your kit is complete...
 Looks good
 Warning: prerequisite Net::DNS failed to load: Can't locate Net/DNS.pm in @INC 
 (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/p
 erl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/s
 ite_perl /usr/local/lib/site_perl/5.6.1/i386-linux /usr/local/lib/site_perl/5.6
 .1 /usr/local/lib/site_perl .) at (eval 8) line 3.
 Warning: prerequisite Time::HiRes failed to load: Can't locate Time/HiRes.pm in
 @INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/
 lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/pe
 rl5/site_perl /usr/local/lib/site_perl/5.6.1/i386-linux /usr/local/lib/site_per
 l/5.6.1 /usr/local/lib/site_perl .) at (eval 10) line 3.
 Warning: prerequisite URI::Escape failed to load: Can't locate URI/Escape.pm in
 @INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/
 lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/pe
 rl5/site_perl /usr/local/lib/site_perl/5.6.1/i386-linux /usr/local/lib/site_per
 l/5.6.1 /usr/local/lib/site_perl .) at (eval 11) line 3.
 Checking if your kit is complete...
 Looks good
 Writing Makefile for Razor2::Preproc::deHTMLxs
 Writing Makefile for razor-agents

これでNet::DNS、Time::HiRes、URI::Escapeが必要なことがわかる

**&aname(CAPN){PerlモジュールをCPANからNetworkインストール}; [#b11f6bad]

CPANからDownLoadしてインストールしても良いが以下のようなインストール方法もある。~
また、この環境設定は/usr/lib/perl5/5.8.6/CPAN/Config.pmに保存されるので削除すれば再設定できる。

(初めての時は環境設定のためいろいろ聞かれる)
 $ su
 # perl -MCPAN -e shell (はじめての時は以下ようになるが、
 2回目からはcapan> プロンプトがすぐ出る)
 
 /usr/lib/perl5/5.6.1/CPAN/Config.pm initialized.
 (略)
 Are you ready for manual configuration? [yes] <--Enter入力
 (略)
 First of all, I'd like to create this directory. Where? 
 
 CPAN build and cache directory? [/root/.cpan] <--Enter入力
 (略)
 How big should the disk cache be for keeping the build directories
 with all the intermediate files?
 
 Cache size for build directory (in MB)? [10] <--Enter入力
 (略)
 Perform cache scanning (atstart or never)? [atstart] <--Enter入力
 (略)
 Cache metadata (yes/no)? [yes] <--Enter入力
 (略)
 Your terminal expects ISO-8859-1 (yes/no)? [yes] <--no入力
 
 (略)
 File to save your history? [/root/.cpan/histfile] <--Enter入力
 Number of lines to save? [100] <--Enter入力
 
 (略)
 Policy on building prerequisites (follow, ask or ignore)? [ask] <--Enter入力
 (略)
 (以下はパスを確認して)
 Where is your gzip program? [/bin/gzip] <--Enter入力
 Where is your tar program? [/bin/tar] <--Enter入力
 Where is your unzip program? [/usr/bin/unzip] <--Enter入力
 Where is your make program? [/usr/bin/make] <--Enter入力
 Warning: lynx not found in PATH
 Where is your lynx program? [] <--Enter入力
 Where is your wget program? [/usr/bin/wget] <--Enter入力
 Warning: ncftpget not found in PATH
 Where is your ncftpget program? [] <--Enter入力
 Warning: ncftp not found in PATH
 Where is your ncftp program? [] <--Enter入力
 Where is your ftp program? [/usr/bin/ftp] <--Enter入力
 Where is your gpg program? [/usr/bin/gpg] <--Enter入力
 What is your favorite pager program? [/usr/bin/less] <--Enter入力
 What is your favorite shell? [/bin/bash] <--Enter入力
 (略) 
 
 Parameters for the 'perl Makefile.PL' command?
 Typical frequently used settings:
 
     POLLUTE=1        increasing backwards compatibility
     LIB=~/perl       non-root users (please see manual for more hints) 
 
 Your choice:  [] <--Enter入力
 Parameters for the 'make' command?
 Typical frequently used setting:
 
     -j3              dual processor system
 
 Your choice:  [] <--Enter入力
 Parameters for the 'make install' command?
 Typical frequently used setting: 
 
    UNINST=1         to always uninstall potentially conflicting files
 
 Your choice:  [] <--Enter入力
 (略) 
 
 If you set this value to 0, these processes will wait forever. This is
 the default and recommended setting.
 
 Timeout for inactivity during Makefile.PL? [0] <--Enter入力
 
 Your ftp_proxy? <--Enter入力
 Your http_proxy? <--Enter入力
 Your no_proxy? <--Enter入力
 You have no /root/.cpan/sources/MIRRORED.BY
   I'm trying to fetch one
 LWP not available
 
   Please, install Net::FTP as soon as possible. CPAN.pm installs it for you
   if you just type
       install Bundle::libnet
 (略)
 Finally, you will be prompted for any extra URLs -- file:, ftp:, or
 http: -- that host a CPAN mirror.
 
 (1) Africa
 (2) Asia
 (3) Central America
 (4) Europe
 (5) North America
 (6) Oceania
 (7) South America
 Select your continent (or several nearby continents) [] <--2を入力 
 
 (1) China
 (2) Indonesia
 (3) Israel
 (4) Japan
 (5) Malaysia
 (6) Philippines
 (7) Republic of Korea
 (8) Russian Federation
 (9) Saudi Arabia
 (10) Singapore
 (11) Taiwan
 (12) Thailand
 Select your country (or several nearby countries) [] <--4を入力 
 
 (1) ftp://ftp.ayamura.org/pub/CPAN/
 (2) ftp://ftp.dti.ad.jp/pub/lang/CPAN/
 (3) ftp://ftp.jaist.ac.jp/pub/lang/perl/CPAN/
 (4) ftp://ftp.kddlabs.co.jp/CPAN/
 (5) ftp://ftp.ring.gr.jp/pub/lang/perl/CPAN/
 (6) ftp://ftp.u-aizu.ac.jp/pub/CPAN
 (7) http://ftp.cpan.jp/
 Select as many URLs as you like,
 put them on one line, separated by blanks [] <-- 1 2を入力 
 
 Enter another URL or RETURN to quit: [] <--Enter入力
 New set of picks:
   ftp://ftp.ayamura.org/pub/CPAN/
   ftp://ftp.dti.ad.jp/pub/lang/CPAN/
 
 (略)
 Your favorite WAIT server?
    [wait://ls6.informatik.uni-dortmund.de:1404] <--Enter入力
 
 commit: wrote /usr/lib/perl5/5.6.1/CPAN/Config.pm 
 
 cpan shell -- CPAN exploration and modules installation (v1.59_54)
 ReadLine support available (try 'install Bundle::CPAN')
 cpan> install Net::DNS <--モジュール名を入力 
 
 (途中でDownloadシーケンスが止まった場合^Cで止めると2つ目の候補からDownloadする)
 
 (略)
 Net-DNS-0.47/TODO
 Net-DNS-0.47/README
 Net-DNS-0.47/META.yml
 Net-DNS-0.47/DNS.xs
 Net-DNS-0.47/Makefile.PL
 
   CPAN.pm: Going to build C/CR/CREIN/Net-DNS-0.47.tar.gz
 
 Testing if you have a C compiler and the needed header files....
 cc    -c -o compile.o compile.c
 You have a working compiler.
 
 You appear to be directly connected to the Internet.  I have some tests
 that try to query live nameservers.
 
 Do you want to enable these tests? [y] <--Enter入力
 
 Checking if your kit is complete...
 Looks good
 Warning: prerequisite Digest::MD5 2.12 not found at /usr/lib/perl5/5.6.1/ExtUti
 ls/MakeMaker.pm line 352.
 Warning: prerequisite MIME::Base64 failed to load: Can't locate MIME/Base64.pm 
 in @INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /u
 sr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib
 /perl5/site_perl /usr/local/lib/site_perl/5.6.1/i386-linux /usr/local/lib/site_
 perl/5.6.1 /usr/local/lib/site_perl .) at (eval 17) line 3.
 Warning: prerequisite Test::More failed to load: Can't locate Test/More.pm in @
 INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/l
 ib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/per
 l5/site_perl /usr/local/lib/site_perl/5.6.1/i386-linux /usr/local/lib/site_perl
 /5.6.1 /usr/local/lib/site_perl .) at (eval 18) line 3.
 Writing Makefile for Net::DNS
 ---- Unsatisfied dependencies detected during [C/CR/CREIN/Net-DNS-0.47.tar.gz]  -----
     MIME::Base64
     Digest::MD5
     Test::More
 Shall I follow them and prepend them to the queue
 of modules we are processing right now? [yes] <--Enter入力
 (TESTを行うと足りないモジュールが指摘されるのでそのままインストールする 
 すると指摘されたモジュールもインストールされる)
 
 (略)
 Running install for module MIME::Base64
 Running make for G/GA/GAAS/MIME-Base64-3.01.tar.gz
 
 (略)
 
 ftp.ayamura.org をDNSに問いあわせています... 完了しました。
 ftp.ayamura.org[203.174.65.13]:21 に接続しています... 接続しました。
 anonymous としてログインしています... ログインしました!
 ==> SYST ... 完了しました。    ==> PWD ... 完了しました。
 ==> TYPE I ... 完了しました。  ==> CWD /pub/CPAN/authors/id/G/GA/GAAS ... 完 了しました。
 ==> PORT ... 完了しました。    ==> RETR MIME-Base64-3.01.tar.gz ... 完了しました。
 長さ: 14,514 (確証はありません)
 
 100%[====================================>] 14,514       383.08K/s    ETA 00:00
 
 10:01:34 (383.08 KB/s) - `-' を保存しました [14514]
 
 (略)
 
 MIME-Base64-3.01/Base64.pm
 MIME-Base64-3.01/Changes
 MIME-Base64-3.01/Makefile.PL
 MIME-Base64-3.01/decode-base64
 MIME-Base64-3.01/Base64.xs
 
   CPAN.pm: Going to build G/GA/GAAS/MIME-Base64-3.01.tar.gz
 
 (略)
 
 Running make test
 PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib -I/usr/lib/perl5/5.6.1/ i3
 86-linux -I/usr/lib/perl5/5.6.1 -e 'use Test::Harness qw(&runtests $verbose); $v
 erbose=0; runtests @ARGV;' t/*.t
 t/bad-sv............skipped: Perl::API needed for this test
 t/base64............ok
 t/quoted-print......ok
 
 (略)
 
 Installing /usr/bin/encode-qp
 Installing /usr/bin/encode-base64
 Installing /usr/bin/decode-base64
 Installing /usr/bin/decode-qp
 Writing /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/MIME/Base64/.packlist
 Appending installation info to /usr/lib/perl5/5.6.1/i386-linux/perllocal.pod
   /usr/bin/make install  -- OK
 
 Installing /usr/share/man/man3/Net::DNS::RR::NULL.3pm
 Installing /usr/share/man/man3/Net::DNS::RR::RP.3pm
 Writing /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/Net/DNS/.packlist
 Appending installation info to /usr/lib/perl5/5.6.1/i386-linux/perllocal.pod
   /usr/bin/make install  -- OK
 cpan> quit (終了コマンド)
 
 Lockfile removed.


/usr/lib/perl5/5.6.1/CPAN/Config.pm
に設定ファイルが作成される。

URLのLIST等はここにある

  'urllist' => [q[ftp://ftp.dti.ad.jp/pub/lang/CPAN/], q[ftp://ftp.ayamura.org/pub/CPAN/]],
2回目からは起動するとすぐインストール画面になる。

 # perl -MCPAN -e shell (2回目以降)
 
 cpan shell -- CPAN exploration and modules installation (v1.59_54)
 ReadLine support available (try 'install Bundle::CPAN')
 
 cpan>

となり、install Time::HiRes 等と入力すればよい

ただし、再度設定し直しは
/usr/lib/perl5/5.8.2/CPAN/Config.pmに
 1;
だけのファイルに変えるとOK
***Perl で @INC(perl検索パス) にパスを追加 [#vf20d64e]

 $ perl -I ~/perl/lib 

***Perl CAPNのインストール済モジュールの確認方法 [#q7d0e519]

次のコマンドで全てのモジュールが表示される
 $ find `perl -e 'print "@INC"'` -name '*.pm' -print

これでは多いのでモジュールを指定(存在するとき)
 $ find `perl -e 'print "@INC"'` -name 'Parser.pm' -print
 /usr/lib/perl5/5.8.6/Pod/Parser.pm
 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/XML/Parser.pm
 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/HTML/Parser.pm
 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/XML/Parser.pm
 /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi/HTML/Parser.pm
 find: /usr/lib/perl5/site_perl/5.8.2: そのようなファイルやディレクトリはありません
 find: /usr/lib/perl5/site_perl/5.8.2: そのようなファイルやディレクトリはありません
 (略)

存在しない場合
 $ find `perl -e 'print "@INC"'` -name 'Tagset.pm' -print
 /usr/lib/perl5/site_perl/5.8.6/HTML/Tagset.pm
 find: /usr/lib/perl5/site_perl/5.8.2: そのようなファイルやディレクトリはありません
 find: /usr/lib/perl5/site_perl/5.8.2: そのようなファイルやディレクトリはありません
 /usr/lib/perl5/site_perl/5.8.6/HTML/Tagset.pm
 find: /usr/lib/perl5/vendor_perl/5.8.2: そのようなファイルやディレクトリはありません
 find: /usr/lib/perl5/vendor_perl/5.8.2: そのようなファイルやディレクトリはありません
 find: /usr/local/lib/site_perl/i386-linux-thread-multi: そのようなファイルやディレクトリはありません
 find: /usr/local/lib/site_perl/5.8.2: そのようなファイルやディレクトリはありません
 find: /usr/local/lib/site_perl/5.8.2: そのようなファイルやディレクトリはありません


''Razorインストールの続き''

全てのモジュールをインストール後再度

 $ perl Makefile.PL
 $ make
 $ make test
 $ su
 # make install

***Razorの動作確認 [#w1c4cd96]

デバッグモードで

 $ cd ../Mail-SpamAssassin-2.63
 $ spamassassin -t -D < ./sample-spam.txt
 
 debug: Score set 0 chosen.
 debug: running in taint mode? yes
 debug: Running in taint mode, removing unsafe env vars, and resetting PATH
 debug: PATH included '/bin', keeping.
 debug: PATH included '/usr/bin', keeping.
 debug: PATH included '/usr/X11R6/bin', keeping.
 debug: Final PATH set to: /bin:/usr/bin:/usr/X11R6/bin
 
 (略)
 
 debug: is Net::DNS::Resolver available? yes
 debug: trying (3) yahoo.de...
 debug: looking up MX for 'yahoo.de'
 debug: MX for 'yahoo.de' exists? 1
 debug: MX lookup of yahoo.de succeeded => Dns available (set dns_available to hardcode)
 debug: is DNS available? 1
 debug: all '*From' addrs: sender@example.net
 debug: running header regexp tests; score so far=0
 debug: running body-text per-line regexp tests; score so far=0
 debug: Razor2 is available   <--この行で確認
 debug: entering helper-app run mode
  Razor-Log: Computed razorhome from env: /home/okada/.razor
  Razor-Log: No razorhome found, using all defaults
  Razor-Log: No razor-agent.conf found, using defaults.
  7月 02 10:33:51.794611 check[10300]: [ 2] [bootup] Logging initiated  LogDebugLe

設定ファイル 


システムの設定については
SpamAssassinについては/etc/mail/spamassassin/local.cf
個別は ~okada/.spamassassin/user_prefs
にある。

書式は同じなので、必要に応じて使い分ける。
[[TLEC:http://tlec.linux.or.jp/]]にある個人用設定ファイル が日本語もフィルタリングしてくれるそうなのでDownloadした。

user_prefsを/etc/mail/spamassassin/local.cfに置き換える。 
また、Mail-SpamAssassin-3.1.3では/etc/mail/spamassassin/v310.preを以下のように修正 

 # TextCat - language guesser
 #
 ##loadplugin Mail::SpamAssassin::Plugin::TextCat
 loadplugin Mail::SpamAssassin::Plugin::TextCat  <--コメントを削除

Razorは
 $ /usr/local/src/razor-agents-2.40/blib/script/razor-admin -create

を実行して~/.razorに設定ファイルができる。

**Perlでのスクリプトについて [#p9d47db6]

swatch等が動作しているとlogrotatでperlを一度終了するので再度起動する必要があるので以下のようにする。

/etc/logrotate.d/syslogを

 /var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boo
 t.log /var/log/cron {
     sharedscripts
     postrotate
 
         /usr/bin/killall /usr/bin/perl
         /usr/bin/killall /usr/bin/tail
 
         /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
         /usr/bin/swatch -c /etc/.swatchrc -t /var/log/messages &
         /usr/bin/spamd &  <---追加
 
     endscript
 }

**ホワイトリスト/ブラックリスト [#m968d2b1]
SpamAssassinを個人レベルの場合は~/.spamassassin/user_prefsに、システムレベルの場合は/etc/mail/spamassassin/local.cfに以下のような内容を追加。~
システムレベルでは全体に有効になり、個人レベルではその個人のみが有効になる。

 whitelist_from *@abc-u.ac.jp

その後spamdをkillして再起動

 # /usr/bin/spamd &

うまくいくとヘッダーに
 X-Spam-Status: No, score=-104.8 required=13.0
 ・・・・・・・・
 USER_IN_WHITELIST   <==これが入る。(許可したアドレスからの受信に対し)

以下のようなパラメータがある。

|パラメータ	|引数	|デフォルト	|項目|
|required_score	|スコア(実数)	|5	|このスコア以上をspamと判定|
|score	|テスト名 |スコア		|テストのスコアを定義(状況に応じた4段階スコアも定義できる)|
|whitelist_from	|アドレス	|	|ホワイトリスト、アドレス定義には"*"と"?"のワイルドカードが使える|
|blacklist_from	|アドレス	|	|ブラックリスト|
|whitelist_to	|アドレス	|	|宛先ホワイトリスト|
|blacklist_to	|アドレス	|	|宛先ブラックリスト|
|rewrite_header|	{subject│from│to} 文字列	|{無効)	|pam通知のためにヘッダ追記を行う(デフォルトlocal.cf:"Subject [SPAM]")|
|eport_safe|	(0│1│2)	|1	|spam通知のために、0:ヘッダ追加のみ、1:添付形式、2:より安全な添付を行う(デフォルトlocal.cf:0)|
|ok_locales	|ロケール	|all	|文字セットが日本語:ja、西欧言語:enのとき許可する|
|use_bayes	|(0│1)	|1	|ベイジアンフィルタを使う|
|bayes_auto_learn	|(0│1)	|1	|自動学習を有効にする|
|bayes_min_ham_num	|数値	|200	|ベイジアンフィルタを有効にする最低のham数|
|bayes_min_spam_num	|数値	|200	|ベイジアンフィルタを有効にする最低のspam数|

***システムで設定を共通化 [#v2019da4]

/etc/mail/spamassassin/local.cfに以下を追加

 bayes_path /etc/mail/spamassassin/spamers/bayes
 bayes_file_mode 0666
 
 auto_whitelist_path /etc/mail/spamassassin/spamers/auto-whitelist
 auto_whitelist_file_mode 0666

bayes_pathの値は、SpamAssassinが生成するデータベースファイルのプレフィックス(ここではbayes)まで指定する必要があるよう。ファイルは全ユーザで共有するために、モードを666にする。

/etc/mail/spamassassin/spamers/ の下に~
bayes_journal~
bayes_seen~
bayes_toks~
のようなbayes_をプレフィックスとするファイルができる

ファイルを保存後共有の為のフォルダ設定
 # mkdir /etc/mail/spamassassin/spamers
 # chmod 777 /etc/mail/spamassassin/spamers


***AWLの無効化 [#z147663a]
AWL(AutoWhiteList)は、過去に同一の宛先から受信したメールのスコアの平均値をもとに、スコアを調整するしくみのようだ。

/etc/mail/spamassassin/v310.pre

 #loadplugin Mail::SpamAssassin::Plugin::AWL

コメントアウトする

***メールを学習させる [#xb934744]
ベイズ理論を応用したベイジアン・フィルターを備えているので、既存のメールを学習させることでスパムっぽいメールはよりスパムとして認識されやすくなる。

 $ sa-learn --spam /home/hoge/Maildir/.SPAM/cur/
 $ sa-learn --ham /home/hoge/Maildir/.NO_SPAM/cur/
 $ sa-learn --sync <= ジャーナルをDBに反映させる

***問題かも [#j2d6ada5]

ヘッダーのReceived:のIPが255を超えるとスパムと判断されるけどその検出が~
バージョン番号等と間違える場合があるのでそのスコアを0にして運営する

/etc/mail/spamassassin/local.cf

 FORGED_RCVD_IP Invalid IP number, over 255.
 score FORGED_RCVD_IP 0

変更後再起動



------------------------------------------------
RIGHT:[[元ページ:https://wwwism.dyndns.org/hp/linux/spamass.htm]]


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS