[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4779: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4781: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4782: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4783: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
Gentoo Taiwan 討論區 • 檢視主題 - 電子垃圾郵件、病毒郵件的阻擋機制

電子垃圾郵件、病毒郵件的阻擋機制

發現了什麼好東西?來這裡告訴大家吧!

版主: Forums Team

電子垃圾郵件、病毒郵件的阻擋機制

文章peterkim » 週三 4月 28, 2004 4:26 am

本份文件可以在 http://peterkim.cgucccc.org/document/filter_mail.txt 看到最新版。

文件作者:
長庚大學醫學系 洪梓策
長庚大學資管系 廖享進

本文就開放原始碼技術,提出一套高效率且低成本的垃圾廣告、病毒信件阻擋技術,
同時這套系統我們也希望具備自我學習判斷的特色,讓廣告垃圾信件的阻擋機制能夠更積極自動,
有別於以往被動式的阻擋廣告、病毒電子郵件的方法。
同時我們將這套方法實際應用於某大學的學生電子郵件系統中,驗證其可行性和高度的可用性。

在閱讀這篇文章之前,希望讀者能具備Linux作業系統的基礎伺服器操作觀念,良好的網路、DNS、E-mail Server等運作觀念;
本文對這些觀念將不再累述。
同時也希望閱讀本文章的讀者都已經有過設定或阻擋垃圾電子郵件的伺服器管理經驗,能夠更快加速瞭解本文。

同時也希望觀看本文的任何網友有更好的建議歡迎提出,
期盼本文可以成為許多電子郵件伺服器管理員的良好參考技術指南。
本文使用的平台為 Gentoo Linux(現在均正常成功運作)。

本文採用以下的所有軟體,來達成這一整套阻擋方案,
在此列出軟體清單和官方網頁,希望想瞭解這套方案的人都能主動查閱這些軟體,
瞭解他們的功能和作用,以協助自己能以更快的速度瞭解本文。
同時也期盼有心的人,可以進一步參考查閱,並且給予本方案改善的意見:

(一) Postfix:
http://www.postfix.org/
(二) Amavisd-new:
http://www.ijs.si/software/amavisd/
(三) Spam Assassin:
http://www.spamassassin.org/
(四) Sophos Anti Virus and Sophie:
http://www.sophos.com/
http://www.vanja.com/tools/sophie/
http://www.ijs.si/software/sophos-ide-update/
(五) Razor:
http://razor.sourceforge.net/
(六) Pyzor:
http://pyzor.sourceforge.net/
(七) DCC:
http://www.dcc-servers.net/dcc/

首先,當然要有一台已經正在正常運作中的 E-mail Server 囉!
本文以 Postfix MTA 為主要說明,使用其餘 MTA 的使用者(如:sendmail)可以酌情參考修改。

1. 阻擋Open relay以及錯誤domain name的電子郵件主機:
在/etc/postfix/main.cf新增:
smtpd_client_restrictions = reject_rbl_client relay.ordb.org
smtpd_sender_restrictions = reject_unknown_sender_domain

2. 阻擋位於浮動撥接IP上的電子郵件伺服器:
最近國內 ISP 終於達成協議,陸續將浮動 IP 的反解改成 dynamic.domain.name 的格式,
而現今許多廣告信的發送點,都是從這些動態撥接的 IP 而來,因此可以檔掉。
詳細新聞可以參閱:http://www.twia.org.tw/SPAM-930412(news).htm
在/etc/postfix/main.cf已經新增的上一段設定,修改成為:
smtpd_client_restrictions = check_client_access regexp:/etc/postfix/access, reject_rbl_client relay.ordb.org
新增/etc/postfix/access檔案,內容為:
/\.dynamic\..+\.tw/ DISCARD We can't allow dynamic IP to relay!

3. 安裝Amavisd-new和Sophos以及Sophie:
在Debian或Gentoo中,安裝Amavisd-new相當簡單容易!(知道我們為什麼要用這兩個dist了吧:P)
emerge Mail-SpamAssassin
ln -s /etc/mail/.spamassassin /var/lib/amavis/.spamassassin
emerge amavisd-new
若有中途 procmail 安裝失敗的問題,請參閱:
http://forums.gentoo.org/viewtopic.php? ... t=procmail

關於 Amavisd-new,有一篇文章在 Postfix 和 Amavisd-new 之間的流程和一些設定說明的相當清楚,
可以做為底下安裝除錯的參考:
http://phorum.study-area.org/viewtopic. ... mavisd-new

安裝後請您不用煩惱複雜的amavisd.conf設定,這裡提供一份範本給您下載:
http://peterkim.cgucccc.org/document/amavisd.conf
您只要修改其中的這兩個部分:
$mydomain = 'mail.com.tw';
@local_domains_acl = ( ".$mydomain", 'mail.com.tw' );
將mail.com.tw的部分換成自己E-mail Server的domain name即可!

安裝amavisd-new之後,由於系統預設使用amavis作為程式執行的user和group,
若系統沒有新增的話,請手動新增。
同時也請注意是否有建立/var/run/amavis和/var/virusmails目錄是否有建立起來,
所屬使用者和群組均為 amavis。

修改/etc/postfix/main.cf,增加:
content_filter = smtp-amavis:[127.0.0.1]:10024

修改/etc/postfix/master.cf,增加:
smtp-amavis unix - - n – 30 smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes

127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o myhostname=scanned
-o smtpd_sender_restrictions=
-o local_recipient_maps=
-o relay_recipient_maps=

再來放置 Mail SpamAssassin 所使用的 local.cf,這邊也有一份範例給大家參考:
http://peterkim.cgucccc.org/document/local.cf
放置到 /etc/spamassassin/ 下。

4. 再來是安裝 Sophos AntiVirus For Linux,到此下載試用版:
http://downloads.sophos.com/dp/full/lin ... ibc6.tar.Z
(雖說是試用版,但是其實沒有使用限制,當然,
這麼好的防毒軟體如果是在商業用途上,希望你尋找國內許多經銷商購買使用授權,
會有原廠或支援單位的更好服務!)
下載後解開安裝:
tar zcxf linux.intel.libc6.tar.Z
cd sav-install/
sh install.sh

接著安裝 Sophie,Sophie 是一個使用 Sophos Anti Virus Library 的掃毒介面程式,
它運作的原理就是一開始會把 Sophos AntiVirus 所有的病毒碼 Load 進記憶體,
因此掃毒的速度將會非常的快!
先抓下最新版的 Sophie,(http://www.vanja.com/tools/sophie/)
這邊測試的時候是使用 3.04rc1 的版本
解開檔案後,進行安裝:
./configure --with-savilib=/usr/local/lib
make
接著就產生了 sophie 這個 binary file(可執行檔),
將這個檔案搬到理想位置 (如:/usr/local/sophie),
還有原目錄下的 etc/sophie.cfg sophie.savi 複製到 /etc 之下,
更改 sophie.cfg 中 user 和 group 的設定 (設成 amavis ),
並且將 maxproc 的參數調整為 0,
然後就可以執行 sophie -v 看有沒有抓到掃毒引擎和病毒碼了,
沒問題後執行 /usr/local/bin/sophie -D,並且 ls -l /var/run/ 下有沒有出現 sophie 的 socket,
確認之後這個程式就會執行常駐在記憶體中等待 amavisd-new 呼叫掃毒了!

4. 安裝 Sophos ide update 自動更新病毒碼:
http://www.ijs.si/software/sophos-ide-update/ 抓,
我們測試的時候最新版是 1.2,抓下來後解開:
tar zxvf sophos-ide-update_1.2.tar.gz
底下有一個 pl 檔,就可以直接執行了,
他會自動判斷版本更新病毒碼,而且更後完後也會自動重啟 Sophie 更新,
可以放在 crontab 跑,我都設定每三個小時跑一次。
(Gentoo 要跑這隻 perl,必須先 emerge mailx)

5.安裝 razor,DCC,pyzor,
emerge razor
ln -s /etc/razor /root/.razor
vi /root/.razor/razor-agent.conf
找 razorhome = /etc/razor
razor-client
razor-admin -create
razor-admin -register -user postmaster@你的e-mail server domain

emerge /usr/portage/net-mail/dcc/dcc-1.2.28.ebuild
/usr/bin/cdcc 'info'

emerge pyzor
su - amavis
pyzor discover
exit

這些工具都是利用 cryptographic hash 或 checksum 和特徵比對的方式,作為判斷垃圾信件的依據,
詳情請分別參閱各工具網站。


6. 建立貝式分析模式
參考文件:
http://phorum.study-area.org/viewtopic.php?t=16063
http://www.oddquad.org/linux/anti-spam.html

emerge php-cgi
mkdir /var/spool/spamfwd/
cd /var/spool/spamfwd
mkdir incoming errors log
wget http://peterkim.cgucccc.org/document/spam/script.tgz
tar zxvf script.tgz
vi config.inc.php (將 mail.com.tw 的部分換成自己 E-mail Server 的 domain name)
chmod 777 *

vi /etc/postfix/aliases
增加以下:
spam:"|/var/spool/spamfwd/spam_recv.php realspam"
notspam:"|/var/spool/spamfwd/spam_recv.php fakespam

離開後:
postaliases /etc/aliases
useradd spam
useradd notspam
useradd realspam
useradd fakespam
cd /root
ln -s /var/spool/mail /var/mail
wget http://peterkim.cgucccc.org/document/spam/sa-learn.sh
chmod 755 sa-learn.sh

然後我這邊有一份建立好的 bayes rules,大家可以先抓去將就將就:
cd /etc/mail
wget http://peterkim.cgucccc.org/document/spam/bayes.tgz
tar bayes.tgz
chown -R amavis:amavis .spamassassin
ln -s ../spamassassin spamassassin

最後可以執行 spamassassin --lint -D 察看所有程式是否都正常執行或被呼叫!

系統可以使用貝式分析之後由於每一次學習都需要廣告信的樣本和非廣告信的樣本,
因此麻煩可以收集這些樣本,並且依照下面這個方法作:

1.非廣告信或者被誤判成為廣告信的信件,請將該封郵件用
"以附件轉寄" (大家常用的 OpenWebmail 上的選項)

"以附加檔案方式轉寄" (Outlook 上的選項)
的方式寄到 notspam@你的 e-mail server domain

2.沒有抓到的廣告郵件用:
"以附件轉寄" (大家常用的 OpenWebmail 上的選項)

"以附加檔案方式轉寄" (Outlook 上的選項)
的方式寄到 spam@你的 e-mail server domain

請不要用其他轉寄的方式,以免造成系統的錯亂。
也不要故意惡作劇,將非廣告信寄到收廣告信的信箱,
這將會造成系統判斷力降低,
轉寄過來的郵件會經過"學習式的貝式垃圾信演算法"學習,以加強分析的能力。

這整個步驟完成後,
整個 Mail Server 的導信流程為:
Postfix (Port 25) -> Amavisd-new (Port 10024) -> Sophie 掃毒 ->
Call SpamAssassin 作廣告信判讀掃瞄(使用 bayes rule, dcc, razor, pyzor, rbl_check 多重判斷) ->
postfix (Port 10025) 把信收下來。

被判斷成廣告信的信件,信件的主旨標題前會有 *****SPAM***** 的字串式樣,
可以通知 Client 使用 E-mail 軟體的時候,設定郵件收件規則,
將標題中含有這個字串的信件丟到垃圾桶,
若有誤判可以用以上的方式寄到 spam 或 notspam 的信箱,
系統管理員大約格一段時間或者懶一點的用 crontab,
定期去跑:
/var/spool/spamfwd/spam_send.php
/root/sa-learn.sh
系統便會根據這些使用者寄過來的垃圾信和非垃圾信的樣本信,重新修整建立 bayes model,
來作為下一次判斷廣告信的掃瞄依據。
貝式分析簡單來說是藉由判斷廣告信和廣告信使用的"語言文字模式"來演算分析,
他藉由分析信件中所有文字 token 出現的或然率來作為判斷分類信件是否為垃圾信的依據,
詳情可以到以下網址查閱:
http://spamconference.org/
http://www.nongnu.org/ifile/
http://spambayes.sourceforge.net/


這樣的機制已經使用在我們學校的 E-mail Server 上,
我們的 E-mail 有 1 萬多個帳號,使用雙 CPU P4 2G,並採用 2G Ram,
運作起來還算相當的順暢,同時完全不用擔心病毒信的問題,
對於廣告信的判斷準度上也常能達到 80% ~ 90% 的程度,
非常少誤判,
即使最近垃圾信的內容或行為模式開始改變的時候,
伺服器管理員也可以利用大量的垃圾信和非垃圾信樣本,
重新訓練我們的 bayes model,調整整個 SpamAssassin 判斷廣告信的分析模式,
以達到精準判斷的目標。

由於這份文件撰寫匆促,必定有許多疏失或者遺漏,
如果有任何指正和問題,歡迎立刻寫信堪誤給我,
我會立刻修正,並且在文章再版之後著名您的足跡。
最後由 peterkim 於 週三 4月 28, 2004 11:48 pm 編輯,總共編輯了 2 次。
peterkim
 
文章: 12
註冊時間: 週五 2月 06, 2004 4:28 pm

文章pahud » 週三 4月 28, 2004 9:55 am

pahud
24hr 義工
 
文章: 1251
註冊時間: 週二 11月 26, 2002 10:22 pm


回到 好康報報

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 19 位訪客

cron