转贴自:
http://netlab.dananes.mlc...ocmail.htmPROCMAIL
--------------------------------------------------------------------------------
最近邮件病毒肆虐,因此,我希望能从主机上直接过滤外来的邮件。procmail是不错的选择。
广告、垃圾信件漫天飞,只要来第一封,就加入信件过滤规则中,就再也收不到了。
--------------------------------------------------------------------------------
安装procmail:
用Ports的方式安装procmail。
--------------------------------------------------------------------------------
建立procmail的设定档:
复制程式
vi /usr/local/etc/procmailrc
MAILDIR=/var/mail
VERBOSE=off
PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin
LOGFILE=/var/log/procmail.log
# procmail 会寄进来的邮件依下列规则逐一过滤,未符合底下规则的信件都放行。
# 过滤这样的主旨(WORM_KLEZ.G):
:0b
* ^Subject:.*(Let's be friends)
/dev/null
# 根据 ip 地?#125;来防止滥发邮件?
:0:
* ^Received:.*(s(n[0-9]|ky)\.seed\.net\.tw|\.is\.net\.tw|\.HINET-IP\.hinet\.net|\.ethome\.net\.tw)
/dev/null
# 过滤附件中有下列副档名的信件。
:0 B
* ^Content-Type:.*
* ^.*name=.*\.(hta|com|pif|vbs|vbe|js|jse|exe|bat|cmd|vxd|scr|shm|dll|SCR)
/dev/null
* ^.iframe src=3Dcid
/dev /null
# 这些寄件者的来信直接丢弃
:0 Hw
* ^.*[Ff]rom:.*MAILER-DAEMON|[email]bgates@microsoft.com[/email]
/dev/null
#SirCam Virus
:0 Bh
*I send you this file in order to have your advice
/dev/null
#Nimda Virus
:0 Bh
* ^Content-Type:.*audio/x-wav.*
* name="readme.exe"
/dev/null
:0 Bh
* ^Content-Type:.*audio/x-wav.*
* name="sample.exe"
/dev/null
:0 B
* ^Content-Type:.*multipart/mixed.*
* name="readme.exe"
/dev/null
:0 B
* ^Content-Type:.*multipart/mixed.*
* name="sample.exe"
/dev/null
请参考台南县教育网路中心的设定档: ftp]会中毒,病毒(WORM_KLEZ.G)透过网页,浏览时就会强迫你下载,还来不及反应就中镖了。
--------------------------------------------------------------------------------
Sendmail + Procmail (IN FreeBSD 4.4-RELEASE):
复制程式
cd /etc/mail
vi freebsd.mc
将
复制程式
divert(-1)
divert(0)
VERSIONID(`$FreeBSD: src/etc/sendmail/freebsd.mc,v 1.10.2.11 2001/07/14 18:07:27
gshapiro Exp $')
OSTYPE(freebsd4)
DOMAIN(generic)
FEATURE(access_db, `hash -o /etc/mail/access')
FEATURE(blacklist_recipients)
FEATURE(local_lmtp)
FEATURE(mailertable, `hash -o /etc/mail/mailertable')
FEATURE(relay_based_on_MX)
FEATURE(virtusertable, `hash -o /etc/mail/virtusertable')
define(`confCW_FILE', `-o /etc/mail/local-host-names')
define(`confMAX_MIME_HEADER_LENGTH', `256/128')
define(`confNO_RCPT_ACTION', `add-to-undisclosed')
define(`confPRIVACY_FLAGS', `authwarnings,noexpn,novrfy')
MAILER(local)
MAILER(smtp)
增加一行,改为:
复制程式
divert(-1)
divert(0)
VERSIONID(`$FreeBSD: src/etc/sendmail/freebsd.mc,v 1.10.2.11 2001/07/14 18:07:27
gshapiro Exp $')
OSTYPE(freebsd4)
DOMAIN(generic)
FEATURE(access_db, `hash -o /etc/mail/access')
FEATURE(blacklist_recipients)
FEATURE(local_lmtp)
FEATURE(mailertable, `hash -o /etc/mail/mailertable')
FEATURE(relay_based_on_MX)
FEATURE(virtusertable, `hash -o /etc/mail/virtusertable')
define(`confCW_FILE', `-o /etc/mail/local-host-names')
define(`confMAX_MIME_HEADER_LENGTH', `256/128')
define(`confNO_RCPT_ACTION', `add-to-undisclosed')
define(`confPRIVACY_FLAGS', `authwarnings,noexpn,novrfy')
FEATURE(local_procmail)
MAILER(local)
MAILER(smtp)
建立一个有支援procmail的sendmail.cf档:
复制程式
新的sendmail.cf主要变更如下:
复制程式
Mlocal, P=/usr/local/bin/procmail, F=lsDFMAw5:/|@qSPfhn9, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,
T=DNS/RFC822/SMTP,
A=procmail -Y -a $h -d $u
--------------------------------------------------------------------------------
重新启动sendmail:
复制程式
killall sendmail
/usr/sbin/sendmail -bd -q30m
--------------------------------------------------------------------------------
网路上的资源:
http://www.pro....org/ http://www.uwasa.fi/~ts...tips.html http://freebsd.sinica.edu.tw/~s...procmail.html http://mir.ncnu.edu.tw/www.sen...cf-readme.txt http://hpds.ee.ncku.edu....work/mail/ http://weber.tn.edu.tw/ch...ocmail.htm