postfix,postfix过滤(header_checks,body_checks...)

Postfix是目前比较流行的,拥有相当好的安全性和高效率的邮件系统。Postfix自身带了很多反垃圾邮件的功能,现在我们就来简单的了解一下它的这些功能。
一、访问控制列表
访问控制列表可以限制客户端对邮件服务器的访问,main.cf中常用的访问控制如下:
程序代码:
smtpd_client_restrictions SMTPD客户端限制
smtpd_helo_restrictions SMTPD标识限制
smtpd_sender_restrictions SMTPD发送者限制
smtpd_recipient_restrictions SMTPD接收都限制
以下是访问控制列表使用的示例:
程序代码:
smtpd_client_restrictions = check_client_access hash:/etc/postfix/checks/access_client
smtpd_helo_restrictions = check_client_access hash:/etc/postfix/checks/helo_client
smtpd_sender_restrictions = check_client_access hash:/etc/postfix/checks/sender_client
smtpd_recipient_restrictions = check_client_access hash:/etc/postfix/checks/recipient_client
访问控制表是一个hash表,其中每一行就是一条控制项,如下:
程序代码:
spammer.com 550 You can't sends mail from my server.
hacker@ 550 You aren't allowed to send mail.
规则中,第一项是规则内容,第二项是对满足规则时所采取的行动,第三项是返回给客户端的信息。
其中第一条表示禁止任何spammer.com上的用户发送邮件,第二条表示禁止任何用户名为hacker的用户发送邮件。
二、内容过滤
反垃圾邮件中,内容过滤是非常重要的部分,在Postfix中有两种内容过滤:邮件头过滤和邮件内容过滤。
1)邮件头过滤
邮件头包括邮件头部信息和MIME头信息,要使邮件头过滤生效需要在main.cf中加入:
程序代码:
header_checks = regexp:/etc/postfix/checks/header_checks
mime_header_checks = regexp:/etc/postfix/checks/mime_header_checks
在这里我们使用的是标准正规表示式过滤规则,规则文件中的第一行都类似于如下行:
程序代码:
/^HEADER: .*content_to_act_on/ ACTION MESSAGE
/^HEADER: .*content_to_act_on/是正规表示式,ACTION是对满足正规表示式时所
采取的动作,MESSAGE是该规则的说明,一般用于向客户端反回信息或用户邮件日志。常用的ACTION有:
REJECT 通知Postfix弹回邮件,这样邮件在进入你的邮件服务器前便被禁止 IGNORE 通知Postfix删除满足过滤条件的那部分内容 HOLD 通知Postfix将邮件保存在邮件队列中,以便管理对之进一步处理 DISCARD 通知Postfix直接删除邮件,在这种情况下,服务器不对发送者返回任何信息,以便让发送端感觉邮件已经正常发送
下面是一些有用的例子:
程序代码:
/^Subject: .* / REJECT Spam Header Many Spaces
/^Subject: Free Money/ REJECT Spam Free Money Mails
/^Date: 19[0-9][0-9]/ REJECT Spam past date
/name=[^>]*\.(bat|com|exe)/ REJECT Spam Executable Attachements
2)邮件内容过滤
邮件内容过滤是指邮件的正文内容过滤,它是针对邮件正文中的文字进行过滤,其规则的用法和邮件头过滤一样,为了使用邮件内容过滤需要在main.cf中加入:
程序代码:
body_checks = regexp:/etc/postfix/checks/body_checks
下面是几个有用的规则:
程序代码:
/Free Money/ REJECT Spam Free Money in Body mails
/www.disallowdsites.com/ REJECT Disallowed Sites
/Real Bad Words/ REJECT Bad Words
需要提醒的是,与邮件头过滤规则不同的,邮件内容过滤规则中的正则表示式不区分大小写。
main.cf
header_checks = pcre:/etc/postfix/header_checks
不需要这步postmap /etc/postfix/header_checks //执行这一步的功能是产生header_checks.db
############# Part I 病毒攻防戰 #######################
/filename\=\"1.*zip\"/ REJECT Virus 不允許這個夾帶檔案的檔名(/filename\=\"1.*zip\"/)
/filename\=\"postcard\.zip\"/ REJECT Virus 不允許這個夾帶檔案的檔名(/filename\=\"postcard\.zip\"/ )
# 1. KLEZ.G 病毒攻防戰 #####################################
/^Subject:.*Let\'s be friends/ DISCARD Virus drop the unavailable header
#/^Subject:.*A\ funny\ game/ DISCARD Virus drop the unavailable header
#/^Subject:.*A WinXP patch$/ DISCARD Virus drop the unavailable header
#/^Subject:.*A special funny website/ DISCARD Virus drop the unavailable header
/^Subject:.*Hello\,.*\,how\ are\ you.*/ DISCARD Virus drop the unavailable header
/^Subject:.*W32.*removal\ tools$/ DISCARD Virus drop the unavailable header
/^Subject:.*Worm\ Klez.*immunity.*/ DISCARD Virus drop the unavailable header
# 4. Sobig #############################################
/^Subject.*my\ details/ DISCARD Virus drop the unavailable header
#/^Subject.*your\ details/ DISCARD Virus drop the unavailable header
#/^Subject.*your\ application/ DISCARD Virus drop the unavailable header
# 5. 微軟 假好心病毒 ####################################
#/^Subject.*Last\ Internet\ Pack/ DISCARD Virus drop the unavailable header
#/^Subject.*Last\ Network\ Pack/ DISCARD Virus drop the unavailable header
/^From.*MS\ Network\ Security/ DISCARD Virus drop the unavailable header
# 6. 其他最新 #########################################
/^Subject.*our\ private\ photos/ DISCARD Virus drop the unavailable header
/^Subject.*don\'t\ be\ late\!/ DISCARD Virus drop the unavailable header
# 其他病毒 #############################################
/^Subject:.*Here\ is\ that\ sample/ REJECT Virus drop the unavailable header
/^Subject:.*Your.*password/ REJECT Virus drop the unavailable header
/charset\=\"Windows\-1252\"/ REJECT Virus 本主機不可使用 charset 為 windows-1252 (Sorry, charset=windows-1252 is unavailable header)
#/^Subject\:\ warning$/ REJECT Virus 本主機不可使用這個標題做為信件標題 unavailable header
#/^Subject\:\ unknown$/ REJECT Virus 本主機不可使用這個標題做為信件標題 unavailable header
#/^Subject\:\ stolen$/ REJECT Virus 本主機不可使用這個標題做為信件標題 unavailable header
#/^Subject\:\ hi$/ REJECT Virus 本主機不可使用這個標題做為信件標題 unavailable header
#/^Subject\:\ fake$/ REJECT Virus 本主機不可使用這個標題做為信件標題 unavailable header
# 一些不要被允許的帳號,這些都可以抵擋! #############################################
/^From\:.linyan\@/ REJECT Virus 本主機不支援使用您的來源帳號寄信 linyan
/^From\:.*admin\@/ REJECT Virus 本主機不支援使用您的來源帳號寄信 unavailable header
Postfix UCE/anti-spam guide
http://www.securitysage.com/guides/postfix_uce.html
Tags:  postfix

延伸阅读

最新评论

发表评论