Compare commits

..

1 Commits

Author SHA1 Message Date
cvs2svn e66a56154d This commit was manufactured by cvs2svn to create tag 'pymilter-0_8_9'.
Sprout from master 2007-09-25 17:07:32 UTC Stuart Gathman <stuart@gathman.org> 'Test on Centos5'
Cherrypick from bmsi 2005-05-31 18:23:49 UTC Stuart Gathman <stuart@gathman.org> 'Development changes since 0.7.2':
    rejects.py
    rhsbl.m4
    sample.py
    test/amazon
    test/big5
    test/bounce
    test/bounce1
    test/bound
    test/honey
    test/missingboundary
    test/samp1
    test/spam44
    test/spam7
    test/spam8
    test/test1
    test/test8
    test/virus1
    test/virus13
    test/virus2
    test/virus3
    test/virus4
    test/virus5
    test/virus6
    test/virus7
    testsample.py
2007-09-25 17:07:33 +00:00
17 changed files with 321 additions and 533 deletions
+4 -4
View File
@@ -35,13 +35,13 @@ wish to install pydspam.
For basic pymilter you'll need: For basic pymilter you'll need:
python-2.4 python-2.4
milter-0.8.10 milter-0.8.7
sendmail-8.13.x (with milter support enabled) sendmail-8.13.x (with milter support enabled)
and for SPF you'll need: and for SPF you'll need:
pydns-2.3.3-2.4 pydns-2.3.0-2.4
pyspf-2.0.5-1.py24 pyspf-2.0.3-2.py24
and for SRS you'll need: and for SRS you'll need:
@@ -65,7 +65,7 @@ Start milter and pysrs with "service milter start", "service pysrs start".
Tail /var/log/milter/milter.log while SMTP clients connect to your Tail /var/log/milter/milter.log while SMTP clients connect to your
sendmail instance. This should show you what the milter is doing. sendmail instance. This should show you what the milter is doing.
By default, milter-0.8.10 rejects on SPF fail. By default, milter-0.8.7 rejects on SPF fail.
Step four. Tweaking the basic config. Step four. Tweaking the basic config.
+2 -4
View File
@@ -184,10 +184,8 @@ def runmilter(name,socketname,timeout = 0):
print "Removing %s" % fname print "Removing %s" % fname
try: try:
os.unlink(fname) os.unlink(fname)
except os.error, x: except:
import errno pass
if x.errno != errno.ENOENT:
raise milter.error(x)
# The default flags set include everything # The default flags set include everything
# milter.set_flags(milter.ADDHDRS) # milter.set_flags(milter.ADDHDRS)
+12 -20
View File
@@ -10,11 +10,6 @@
# CBV results. # CBV results.
# #
# $Log$ # $Log$
# Revision 1.8 2007/09/03 16:18:45 customdesigned
# Delete unparseable timestamps when loading address cache. These have
# arisen because of failure to parse MAIL FROM properly. Will have to
# tighten up MAIL FROM parsing to match RFC.
#
# Revision 1.7 2007/01/25 22:47:26 customdesigned # Revision 1.7 2007/01/25 22:47:26 customdesigned
# Persist blacklisting from delayed DSNs. # Persist blacklisting from delayed DSNs.
# #
@@ -94,10 +89,8 @@ class AddrCache(object):
except IOError: except IOError:
lock.unlock() lock.unlock()
def has_precise_key(self,sender): def has_key(self,sender):
"""True if precise sender is cached and has not expired. Don't "True if sender is cached and has not expired."
try looking up wildcard entries.
"""
try: try:
lsender = sender and sender.lower() lsender = sender and sender.lower()
ts,res = self.cache[lsender] ts,res = self.cache[lsender]
@@ -105,17 +98,16 @@ class AddrCache(object):
if not ts or ts > too_old: if not ts or ts > too_old:
return True return True
del self.cache[lsender] del self.cache[lsender]
except KeyError: pass try:
return False user,host = sender.split('@',1)
return self.has_key(host)
def has_key(self,sender): except ValueError:
"True if sender is cached and has not expired." pass
if self.has_precise_key(sender): except KeyError:
return True try:
try: user,host = sender.split('@',1)
user,host = sender.split('@',1) return self.has_key(host)
return self.has_precise_key(host) except: pass
except: pass
return False return False
__contains__ = has_key __contains__ = has_key
-40
View File
@@ -4,8 +4,6 @@ import socket
import email.Errors import email.Errors
from fnmatch import fnmatchcase from fnmatch import fnmatchcase
from email.Header import decode_header from email.Header import decode_header
#import email.Utils
import rfc822
ip4re = re.compile(r'^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$') ip4re = re.compile(r'^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$')
@@ -42,44 +40,6 @@ def iniplist(ipaddr,iplist):
return True return True
return False return False
def parseaddr(t):
"""Split email into Fullname and address.
>>> parseaddr('user@example.com')
('', 'user@example.com')
>>> parseaddr('"Full Name" <foo@example.com>')
('Full Name', 'foo@example.com')
>>> parseaddr('spam@spammer.com <foo@example.com>')
('spam@spammer.com', 'foo@example.com')
>>> parseaddr('God@heaven <@hop1.org,@hop2.net:jeff@spec.org>')
('God@heaven', 'jeff@spec.org')
>>> parseaddr('Real Name ((comment)) <addr...@example.com>')
('Real Name', 'addr...@example.com')
>>> parseaddr('a(WRONG)@b')
('WRONG', 'a@b')
"""
#return email.Utils.parseaddr(t)
res = rfc822.parseaddr(t)
# dirty fix for some broken cases
if not res[0]:
pos = t.find('<')
if pos > 0 and t[-1] == '>':
addrspec = t[pos+1:-1]
pos1 = addrspec.rfind(':')
if pos1 > 0:
addrspec = addrspec[pos1+1:]
return rfc822.parseaddr('"%s" <%s>' % (t[:pos].strip(),addrspec))
if not res[1]:
pos = t.find('<')
if pos > 0 and t[-1] == '>':
addrspec = t[pos+1:-1]
pos1 = addrspec.rfind(':')
if pos1 > 0:
addrspec = addrspec[pos1+1:]
return rfc822.parseaddr('%s<%s>' % (t[:pos].strip(),addrspec))
return res
def parse_addr(t): def parse_addr(t):
"""Split email into user,domain. """Split email into user,domain.
+1 -3
View File
@@ -1,6 +1,4 @@
See pymilter.spec for recent history. Here is a history of user visible changes to Python milter.
Here is a history of older changes to Python milter.
0.8.8 move AddrCache, parse_addr, iniplist, parse_header to Milter package 0.8.8 move AddrCache, parse_addr, iniplist, parse_header to Milter package
fix plock for missing source and can't change owner/group fix plock for missing source and can't change owner/group
add sample spfmilter.py milter add sample spfmilter.py milter
+10 -21
View File
@@ -1,10 +1,6 @@
Check ESMTP NOTIFY before sending real DSNs. Just use CBV if DSNs are Convert DSN to REJECT unless sender gets SPF pass or best guess pass. Make
not wanted. configurable by SPF result with NOTSPAM policy (reject or deliver without DSN).
Maybe policy should be NODSN - still verify sender with CBV.
Support CBV to local domains and cache results so that invalid users
can be rejected without maintaining valid user lists.
Now that we blacklist IPs for too many bad rcpts, delay SPF until RCPT TO.
When content filtering is not installed, reject BLACKLISTed MFROM When content filtering is not installed, reject BLACKLISTed MFROM
immediately. There is no use waiting until EOM. immediately. There is no use waiting until EOM.
@@ -16,8 +12,7 @@ MTA. The mail is flagged external, so we don't list example.com in
internal_domains (or we would get "spam from self"). But, if we try to do a internal_domains (or we would get "spam from self"). But, if we try to do a
CBV, we get "fraudulent MX", because the MX is ourself! So we need to CBV, we get "fraudulent MX", because the MX is ourself! So we need to
avoid doing CBV on such domains. Currently, we try to make sure the SPF avoid doing CBV on such domains. Currently, we try to make sure the SPF
policies don't do CBV. The real solution is for users to use SMTP AUTH, policies don't do CBV.
but some of them are stubborn.
We now don't check internal domains for incoming mail if there is an We now don't check internal domains for incoming mail if there is an
SPF record. SPF record.
@@ -82,6 +77,10 @@ Whitelisted senders from trusted relay get PROBATION. Need to extracted
SPF result from headers - and in the case of mail internal to relay SPF result from headers - and in the case of mail internal to relay
(e.g. bmsi.com), supply 'pass' result. (e.g. bmsi.com), supply 'pass' result.
For selected domains, check rcpts via CBV before accepting mail. Cache
results. This will kick out dictonary attacks against a mail domain
behind a gateway sooner.
Add auto-blacklisted senders to blacklist.log with timestamp. Add auto-blacklisted senders to blacklist.log with timestamp.
Add emails blacklisted via CBV so that they are remembered across milter Add emails blacklisted via CBV so that they are remembered across milter
restarts. restarts.
@@ -98,6 +97,8 @@ e.g. verizon.net).
Allow verified hostnames for trusted_relay. E.g. HELO name that Allow verified hostnames for trusted_relay. E.g. HELO name that
passes SPF. passes SPF.
Table of sendmail macros for documentation.
When do we get two hello calls? STARTTLS is one reason. When do we get two hello calls? STARTTLS is one reason.
Option: accept mail from auto-whitelisted senders even with spf-fail, Option: accept mail from auto-whitelisted senders even with spf-fail,
@@ -179,18 +180,6 @@ Need a test module to feed sample messages to a milter though a live
sendmail and SMTP. The mockup currently used is probably not very accurate, sendmail and SMTP. The mockup currently used is probably not very accurate,
and doesn't test the threading code. and doesn't test the threading code.
DONE Table of sendmail macros for documentation. In API docs on milter.org.
DONE For selected domains, check rcpts via CBV before accepting mail. Cache
results. This will kick out dictonary attacks against a mail domain
behind a gateway sooner.
DONE Convert DSN to REJECT unless sender gets SPF pass or best guess pass. Make
configurable by SPF result with NOTSPAM policy (reject or deliver without DSN).
Maybe policy should be NODSN - still verify sender with CBV.
DONE Add parseaddr test case for 'foo@bar.com <baz@barf.biz>'
DONE Require signed MFROM for all incoming bounces when signing all outgoing DONE Require signed MFROM for all incoming bounces when signing all outgoing
mail - except from trusted relays. mail - except from trusted relays.
+82 -187
View File
@@ -1,49 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# A simple milter that has grown quite a bit. # A simple milter that has grown quite a bit.
# $Log$ # $Log$
# Revision 1.126 2008/08/18 17:47:57 customdesigned
# Log rcpt for SRS rejections.
#
# Revision 1.125 2008/08/06 00:52:38 customdesigned
# CBV policy sends no DSN. DSN policy sends DSN.
#
# Revision 1.124 2008/08/05 18:04:06 customdesigned
# Send quarantine DSN to SPF PASS only.
#
# Revision 1.123 2008/07/29 21:59:29 customdesigned
# Parse ESMTP params
#
# Revision 1.122 2008/05/08 21:35:56 customdesigned
# Allow explicitly whitelisted email from banned_users.
#
# Revision 1.121 2008/04/10 14:59:35 customdesigned
# Configure gossip TTL.
#
# Revision 1.120 2008/04/02 18:59:14 customdesigned
# Release 0.8.10
#
# Revision 1.119 2008/04/01 00:13:10 customdesigned
# Do not CBV whitelisted addresses. We already know they are good.
#
# Revision 1.118 2008/01/09 20:15:49 customdesigned
# Handle unquoted fullname when parsing email.
#
# Revision 1.117 2007/11/29 14:35:17 customdesigned
# Packaging tweaks.
#
# Revision 1.116 2007/11/01 20:09:14 customdesigned
# Support temperror policy in access.
#
# Revision 1.115 2007/10/10 18:23:54 customdesigned
# Send quarantine DSN to SPF pass (official or guessed) only.
# Reject blacklisted email too big for dspam.
#
# Revision 1.114 2007/10/10 18:07:50 customdesigned
# Check porn keywords in From header field.
#
# Revision 1.113 2007/09/25 16:37:26 customdesigned
# Tested on RH7
#
# Revision 1.112 2007/09/13 14:51:03 customdesigned # Revision 1.112 2007/09/13 14:51:03 customdesigned
# Report domain on reputation reject. # Report domain on reputation reject.
# #
@@ -201,19 +158,17 @@ import gc
import anydbm import anydbm
import Milter.dsn as dsn import Milter.dsn as dsn
from Milter.dynip import is_dynip as dynip from Milter.dynip import is_dynip as dynip
from Milter.utils import \ from Milter.utils import iniplist,parse_addr,parse_header,ip4re,addr2bin
iniplist,parse_addr,parse_header,ip4re,addr2bin,parseaddr
from Milter.config import MilterConfigParser from Milter.config import MilterConfigParser
from fnmatch import fnmatchcase from fnmatch import fnmatchcase
from email.Utils import getaddresses from email.Utils import getaddresses,parseaddr
# Import gossip if available # Import gossip if available
try: try:
import gossip import gossip
import gossip.client import gossip.client
import gossip.server import gossip.server
gossip_node = None
except: gossip = None except: gossip = None
# Import pysrs if available # Import pysrs if available
@@ -295,7 +250,6 @@ hello_blacklist = ()
smart_alias = {} smart_alias = {}
dspam_dict = None dspam_dict = None
dspam_users = {} dspam_users = {}
dspam_train = {}
dspam_userdir = None dspam_userdir = None
dspam_exempt = {} dspam_exempt = {}
dspam_whitelist = {} dspam_whitelist = {}
@@ -427,7 +381,6 @@ def read_config(list):
dspam_users = cp.getaddrdict('dspam','dspam_users') dspam_users = cp.getaddrdict('dspam','dspam_users')
dspam_userdir = cp.getdefault('dspam','dspam_userdir') dspam_userdir = cp.getdefault('dspam','dspam_userdir')
dspam_screener = cp.getlist('dspam','dspam_screener') dspam_screener = cp.getlist('dspam','dspam_screener')
dspam_train = set(cp.getlist('dspam','dspam_train'))
dspam_reject = cp.getlist('dspam','dspam_reject') dspam_reject = cp.getlist('dspam','dspam_reject')
dspam_internal = cp.getboolean('dspam','dspam_internal') dspam_internal = cp.getboolean('dspam','dspam_internal')
if cp.has_option('dspam','dspam_sizelimit'): if cp.has_option('dspam','dspam_sizelimit'):
@@ -475,7 +428,7 @@ def read_config(list):
banned_users = cp.getlist('srs','banned_users') banned_users = cp.getlist('srs','banned_users')
if gossip: if gossip:
global gossip_node, gossip_ttl global gossip_node
if cp.has_option('gossip','server'): if cp.has_option('gossip','server'):
server = cp.get('gossip','server') server = cp.get('gossip','server')
host,port = gossip.splitaddr(server) host,port = gossip.splitaddr(server)
@@ -485,10 +438,6 @@ def read_config(list):
for p in cp.getlist('gossip','peers'): for p in cp.getlist('gossip','peers'):
host,port = gossip.splitaddr(p) host,port = gossip.splitaddr(p)
gossip_node.peers.append(gossip.server.Peer(host,port)) gossip_node.peers.append(gossip.server.Peer(host,port))
if cp.has_option('gossip','ttl'):
gossip_ttl = cp.getint('gossip','ttl')
else:
gossip_ttl = 1
def findsrs(fp): def findsrs(fp):
lastln = None lastln = None
@@ -512,12 +461,6 @@ def findsrs(fp):
lastln = ln lastln = ln
break break
def param2dict(str):
pairs = [x.split('=',1) for x in str]
for e in pairs:
if len(e) < 2: e.append(None)
return dict([(k.upper(),v) for k,v in pairs])
class SPFPolicy(object): class SPFPolicy(object):
"Get SPF policy by result from sendmail style access file." "Get SPF policy by result from sendmail style access file."
def __init__(self,sender): def __init__(self,sender):
@@ -590,12 +533,6 @@ class SPFPolicy(object):
policy = 'REJECT' policy = 'REJECT'
return policy return policy
def getTempErrorPolicy(self):
policy = self.getPolicy('spf-temperror:')
if not policy:
policy = 'REJECT'
return policy
def getPassPolicy(self): def getPassPolicy(self):
policy = self.getPolicy('spf-pass:') policy = self.getPolicy('spf-pass:')
if not policy: if not policy:
@@ -605,7 +542,7 @@ class SPFPolicy(object):
from Milter.cache import AddrCache from Milter.cache import AddrCache
cbv_cache = AddrCache(renew=7) cbv_cache = AddrCache(renew=7)
auto_whitelist = AddrCache(renew=60) auto_whitelist = AddrCache(renew=30)
blacklist = AddrCache(renew=30) blacklist = AddrCache(renew=30)
class bmsMilter(Milter.Milter): class bmsMilter(Milter.Milter):
@@ -743,9 +680,6 @@ class bmsMilter(Milter.Milter):
# of each message. # of each message.
def envfrom(self,f,*str): def envfrom(self,f,*str):
self.log("mail from",f,str) self.log("mail from",f,str)
#param = param2dict(str)
#self.envid = param.get('ENVID',None)
#self.mail_param = param
self.fp = StringIO.StringIO() self.fp = StringIO.StringIO()
self.tempname = None self.tempname = None
self.mailfrom = f self.mailfrom = f
@@ -788,9 +722,9 @@ class bmsMilter(Milter.Milter):
self.user = self.getsymval('{auth_authen}') self.user = self.getsymval('{auth_authen}')
if self.user: if self.user:
# Very simple SMTP AUTH policy by default: # Very simple SMTP AUTH policy by defaul:
# any successful authentication is considered INTERNAL # any successful authentication is considered INTERNAL
# Detailed authorization policy is configured in the access file below. # FIXME: configure allowed MAIL FROM by user
self.internal_connection = True self.internal_connection = True
self.log( self.log(
"SMTP AUTH:",self.user, self.getsymval('{auth_type}'), "SMTP AUTH:",self.user, self.getsymval('{auth_type}'),
@@ -876,8 +810,6 @@ class bmsMilter(Milter.Milter):
else: else:
self.dspam = False self.dspam = False
self.log("PROBATION",self.canon_from) self.log("PROBATION",self.canon_from)
if res not in ('permerror','softfail'):
self.cbv_needed = None
elif cbv_cache.has_key(self.canon_from) and cbv_cache[self.canon_from] \ elif cbv_cache.has_key(self.canon_from) and cbv_cache[self.canon_from] \
or domain in blacklist: or domain in blacklist:
if not self.internal_connection: if not self.internal_connection:
@@ -897,8 +829,7 @@ class bmsMilter(Milter.Milter):
else: else:
global gossip global gossip
if gossip and domain and rc == Milter.CONTINUE \ if gossip and domain and rc == Milter.CONTINUE \
and not (self.internal_connection or self.trusted_relay) \ and not (self.internal_connection or self.trusted_relay):
and gossip_node:
if self.spf and self.spf.result == 'pass': if self.spf and self.spf.result == 'pass':
qual = 'SPF' qual = 'SPF'
elif res == 'pass': elif res == 'pass':
@@ -953,22 +884,13 @@ class bmsMilter(Milter.Milter):
res,code,txt = q.check() res,code,txt = q.check()
q.result = res q.result = res
if res in ('unknown','permerror') and q.perm_error and q.perm_error.ext: if res in ('unknown','permerror') and q.perm_error and q.perm_error.ext:
self.cbv_needed = (q,'permerror') # report SPF syntax error to sender self.cbv_needed = (q,res) # report SPF syntax error to sender
res,code,txt = q.perm_error.ext # extended (lax processing) result res,code,txt = q.perm_error.ext # extended (lax processing) result
txt = 'EXT: ' + txt txt = 'EXT: ' + txt
p = SPFPolicy(q.s) p = SPFPolicy(q.s)
# FIXME: try:finally to close policy db, or reuse with lock # FIXME: try:finally to close policy db, or reuse with lock
if res in ('error','temperror'):
if self.need_cbv(p.getTempErrorPolicy(),q,'temperror'):
self.log('TEMPFAIL: SPF %s %i %s' % (res,code,txt))
self.setreply(str(code),'4.3.0',txt,
'We cannot accept your email until the DNS server for %s' % q.o,
'is operational for TXT record queries.'
)
return Milter.TEMPFAIL
res,code,txt = 'none',250,'EXT: ignoring DNS error'
hres = None hres = None
if res != 'pass': if res not in ('pass','error','temperror'):
if self.mailfrom != '<>': if self.mailfrom != '<>':
# check hello name via spf unless spf pass # check hello name via spf unless spf pass
h = spf.query(self.connectip,'',self.hello_name,receiver=receiver) h = spf.query(self.connectip,'',self.hello_name,receiver=receiver)
@@ -1013,9 +935,11 @@ class bmsMilter(Milter.Milter):
and hres != 'pass': and hres != 'pass':
# this bad boy has no credentials whatsoever # this bad boy has no credentials whatsoever
policy = p.getNonePolicy() policy = p.getNonePolicy()
if policy in ('CBV','DNS'): if policy == 'CBV':
self.offenses = 3 # ban ip if any bad recipient if self.mailfrom != '<>':
if self.need_cbv(policy,q,'strike3'): self.cbv_needed = (q,ores) # accept, but inform sender via DSN
self.offenses = 3 # ban ip if any bad recipient
elif policy != 'OK':
self.log('REJECT: no PTR, HELO or SPF') self.log('REJECT: no PTR, HELO or SPF')
self.setreply('550','5.7.1', self.setreply('550','5.7.1',
"You must have a valid HELO or publish SPF: http://www.openspf.org ", "You must have a valid HELO or publish SPF: http://www.openspf.org ",
@@ -1024,9 +948,13 @@ class bmsMilter(Milter.Milter):
"that contain your IP don't count), an invalid or dynamic HELO, ", "that contain your IP don't count), an invalid or dynamic HELO, ",
"and no SPF record." "and no SPF record."
) )
return self.offense() # ban ip if too many bad MFROMs return Milter.REJECT
if res in ('deny', 'fail'): if res in ('deny', 'fail'):
if self.need_cbv(p.getFailPolicy(),q,'fail'): policy = p.getFailPolicy()
if policy == 'CBV':
if self.mailfrom != '<>':
self.cbv_needed = (q,res)
elif policy != 'OK':
self.log('REJECT: SPF %s %i %s' % (res,code,txt)) self.log('REJECT: SPF %s %i %s' % (res,code,txt))
self.setreply(str(code),'5.7.1',txt) self.setreply(str(code),'5.7.1',txt)
# A proper SPF fail error message would read: # A proper SPF fail error message would read:
@@ -1034,7 +962,11 @@ class bmsMilter(Milter.Milter):
# "forged.org" in the sender address. Contact <postmaster@forged.org>. # "forged.org" in the sender address. Contact <postmaster@forged.org>.
return Milter.REJECT return Milter.REJECT
if res == 'softfail': if res == 'softfail':
if self.need_cbv(p.getSoftfailPolicy(),q,'softfail'): policy = p.getSoftfailPolicy()
if policy == 'CBV':
if self.mailfrom != '<>':
self.cbv_needed = (q,res)
elif policy != 'OK':
self.log('REJECT: SPF %s %i %s' % (res,code,txt)) self.log('REJECT: SPF %s %i %s' % (res,code,txt))
self.setreply('550','5.7.1', self.setreply('550','5.7.1',
'SPF softfail: If you get this Delivery Status Notice, your email', 'SPF softfail: If you get this Delivery Status Notice, your email',
@@ -1045,7 +977,12 @@ class bmsMilter(Milter.Milter):
) )
return Milter.REJECT return Milter.REJECT
if res == 'neutral': if res == 'neutral':
if self.need_cbv(p.getNeutralPolicy(),q,'neutral'): policy = p.getNeutralPolicy()
if policy == 'CBV':
if self.mailfrom != '<>':
self.cbv_needed = (q,res)
# FIXME: this makes Received-SPF show wrong result
elif policy != 'OK':
self.log('REJECT: SPF neutral for',q.s) self.log('REJECT: SPF neutral for',q.s)
self.setreply('550','5.7.1', self.setreply('550','5.7.1',
'mail from %s must pass SPF: http://openspf.org/why.html' % q.o, 'mail from %s must pass SPF: http://openspf.org/why.html' % q.o,
@@ -1057,7 +994,11 @@ class bmsMilter(Milter.Milter):
) )
return Milter.REJECT return Milter.REJECT
if res in ('unknown','permerror'): if res in ('unknown','permerror'):
if self.need_cbv(p.getPermErrorPolicy(),q,'permerror'): policy = p.getPermErrorPolicy()
if policy == 'CBV':
if self.mailfrom != '<>':
self.cbv_needed = (q,res)
elif policy != 'OK':
self.log('REJECT: SPF %s %i %s' % (res,code,txt)) self.log('REJECT: SPF %s %i %s' % (res,code,txt))
# latest SPF draft recommends 5.5.2 instead of 5.7.1 # latest SPF draft recommends 5.5.2 instead of 5.7.1
self.setreply(str(code),'5.5.2',txt, self.setreply(str(code),'5.5.2',txt,
@@ -1065,6 +1006,10 @@ class bmsMilter(Milter.Milter):
'We cannot accept mail from %s until this is corrected.' % q.o 'We cannot accept mail from %s until this is corrected.' % q.o
) )
return Milter.REJECT return Milter.REJECT
if res in ('error','temperror'):
self.log('TEMPFAIL: SPF %s %i %s' % (res,code,txt))
self.setreply(str(code),'4.3.0',txt)
return Milter.TEMPFAIL
kv = {} kv = {}
if hres and q.h != q.o: if hres and q.h != q.o:
kv['helo_spf'] = hres kv['helo_spf'] = hres
@@ -1080,15 +1025,6 @@ class bmsMilter(Milter.Milter):
# track header mods separately from body mods - so use only # track header mods separately from body mods - so use only
# in emergencies. # in emergencies.
def envrcpt(self,to,*str): def envrcpt(self,to,*str):
try:
param = param2dict(str)
self.notify = param.get('NOTIFY','FAILURE,DELAY').upper().split(',')
if 'NEVER' in self.notify: self.notify = ()
#self.rcpt_param = param
except:
self.log("REJECT: invalid PARAM:",to,str)
self.setreply('550','5.7.1','Invalid SRS signature')
return Milter.REJECT
# mail to MAILER-DAEMON is generally spam that bounced # mail to MAILER-DAEMON is generally spam that bounced
if to.startswith('<MAILER-DAEMON@'): if to.startswith('<MAILER-DAEMON@'):
self.log('REJECT: RCPT TO:',to,str) self.log('REJECT: RCPT TO:',to,str)
@@ -1127,13 +1063,10 @@ class bmsMilter(Milter.Milter):
self.setreply('550','5.7.1','Invalid SES signature') self.setreply('550','5.7.1','Invalid SES signature')
return Milter.REJECT return Milter.REJECT
# reject for certain recipients are delayed until after DATA # reject for certain recipients are delayed until after DATA
if auto_whitelist.has_precise_key(self.canon_from): if srs_reject_spoofed \
self.log("WHITELIST: DSN from",self.canon_from) and not user.lower() in ('postmaster','abuse'):
else: return self.forged_bounce()
if srs_reject_spoofed \ self.data_allowed = not srs_reject_spoofed
and user.lower() not in ('postmaster','abuse'):
return self.forged_bounce(to)
self.data_allowed = not srs_reject_spoofed
if not self.internal_connection and domain in private_relay: if not self.internal_connection and domain in private_relay:
self.log('REJECT: RELAY:',to) self.log('REJECT: RELAY:',to)
@@ -1156,7 +1089,7 @@ class bmsMilter(Milter.Milter):
self.log('REJECT: RCPT TO:',to,str) self.log('REJECT: RCPT TO:',to,str)
if gossip and self.umis: if gossip and self.umis:
gossip_node.feedback(self.umis,1) gossip_node.feedback(self.umis,1)
self.umis = None self.umis = None
return self.offense() return self.offense()
# FIXME: should dspam_exempt be case insensitive? # FIXME: should dspam_exempt be case insensitive?
if user in block_forward.get(domain,()): if user in block_forward.get(domain,()):
@@ -1246,14 +1179,7 @@ class bmsMilter(Milter.Milter):
# original sender (encoded in Message-ID) is blacklisted # original sender (encoded in Message-ID) is blacklisted
elif lname == 'from': elif lname == 'from':
fname,email = parseaddr(val) name,email = parseaddr(val)
# check for porn keywords
lval = fname.lower().strip()
for w in porn_words:
if lval.find(w) >= 0:
self.log('REJECT: %s: %s' % (name,val))
self.setreply('550','5.7.1','Watch your language')
return Milter.REJECT
if email.lower().startswith('postmaster@'): if email.lower().startswith('postmaster@'):
# Yes, if From header comes last, this might not help much. # Yes, if From header comes last, this might not help much.
# But this is a heuristic - if MTAs would send proper DSNs in # But this is a heuristic - if MTAs would send proper DSNs in
@@ -1274,9 +1200,9 @@ class bmsMilter(Milter.Milter):
return Milter.REJECT return Milter.REJECT
return Milter.CONTINUE return Milter.CONTINUE
def forged_bounce(self,rcpt='-'): def forged_bounce(self):
if self.mailfrom != '<>': if self.mailfrom != '<>':
self.log("REJECT: bogus DSN",rcpt) self.log("REJECT: bogus DSN")
self.setreply('550','5.7.1', self.setreply('550','5.7.1',
"I do not accept normal mail from %s." % self.mailfrom.split('@')[0], "I do not accept normal mail from %s." % self.mailfrom.split('@')[0],
"All such mail has turned out to be Delivery Status Notifications", "All such mail has turned out to be Delivery Status Notifications",
@@ -1284,7 +1210,7 @@ class bmsMilter(Milter.Milter):
"you need to. Use another MAIL FROM if you need to send me mail." "you need to. Use another MAIL FROM if you need to send me mail."
) )
else: else:
self.log('REJECT: bounce with no SRS encoding',rcpt) self.log('REJECT: bounce with no SRS encoding')
self.setreply('550','5.7.1', self.setreply('550','5.7.1',
"I did not send you that message. Please consider implementing SPF", "I did not send you that message. Please consider implementing SPF",
"(http://openspf.org) to avoid bouncing mail to spoofed senders.", "(http://openspf.org) to avoid bouncing mail to spoofed senders.",
@@ -1494,12 +1420,6 @@ class bmsMilter(Milter.Milter):
elif not self.internal_connection or dspam_internal: elif not self.internal_connection or dspam_internal:
if len(txt) > dspam_sizelimit: if len(txt) > dspam_sizelimit:
self.log("Large message:",len(txt)) self.log("Large message:",len(txt))
if self.blacklist:
self.log('REJECT: BLACKLISTED')
self.setreply('550','5.7.1',
'%s has been blacklisted.'%self.canon_from)
self.fp = None
return Milter.REJECT
return False return False
if user == 'honeypot' and Dspam.VERSION >= '1.1.9': if user == 'honeypot' and Dspam.VERSION >= '1.1.9':
keep = False # keep honeypot mail keep = False # keep honeypot mail
@@ -1511,12 +1431,9 @@ class bmsMilter(Milter.Milter):
return False return False
if self.spf and self.mailfrom != '<>': if self.spf and self.mailfrom != '<>':
# check that sender accepts quarantine DSN # check that sender accepts quarantine DSN
if self.spf.result == 'pass': msg = mime.message_from_file(StringIO.StringIO(txt))
msg = mime.message_from_file(StringIO.StringIO(txt)) rc = self.send_dsn(self.spf,msg,'quarantine')
rc = self.send_dsn(self.spf,msg,'quarantine') del msg
del msg
else:
rc = self.send_dsn(self.spf)
if rc != Milter.CONTINUE: if rc != Milter.CONTINUE:
return rc return rc
ds.check_spam(user,txt,self.recipients,quarantine=True, ds.check_spam(user,txt,self.recipients,quarantine=True,
@@ -1534,13 +1451,8 @@ class bmsMilter(Milter.Milter):
elif self.blacklist: elif self.blacklist:
txt = ds.check_spam(user,txt,self.recipients, txt = ds.check_spam(user,txt,self.recipients,
force_result=dspam.DSR_ISSPAM) force_result=dspam.DSR_ISSPAM)
elif user in dspam_train:
txt = ds.check_spam(user,txt,self.recipients)
else: else:
txt = ds.check_spam(user,txt,self.recipients,classify=True) txt = ds.check_spam(user,txt,self.recipients)
if txt:
self.add_header("X-DSpam-Score",'%f' % ds.probability)
return False
if not txt: if not txt:
# DISCARD if quarrantined for any recipient. It # DISCARD if quarrantined for any recipient. It
# will be resent to all recipients if they submit # will be resent to all recipients if they submit
@@ -1571,7 +1483,7 @@ class bmsMilter(Milter.Milter):
ds.check_spam(screener,txt,self.recipients, ds.check_spam(screener,txt,self.recipients,
force_result=dspam.DSR_ISINNOCENT) force_result=dspam.DSR_ISINNOCENT)
return False return False
if self.reject_spam and self.spf.result != 'pass': if self.reject_spam:
self.log("DSPAM:",screener, self.log("DSPAM:",screener,
'REJECT: X-DSpam-Score: %f' % ds.probability) 'REJECT: X-DSpam-Score: %f' % ds.probability)
self.setreply('550','5.7.1','Your Message looks spammy') self.setreply('550','5.7.1','Your Message looks spammy')
@@ -1581,18 +1493,12 @@ class bmsMilter(Milter.Milter):
if self.spf and self.mailfrom != '<>': if self.spf and self.mailfrom != '<>':
# check that sender accepts quarantine DSN # check that sender accepts quarantine DSN
self.fp.seek(0) self.fp.seek(0)
if self.spf.result == 'pass' or self.cbv_needed: msg = mime.message_from_file(self.fp)
msg = mime.message_from_file(self.fp) rc = self.send_dsn(self.spf,msg,'quarantine')
if self.spf.result == 'pass':
rc = self.send_dsn(self.spf,msg,'quarantine')
else:
rc = self.do_needed_cbv(msg)
del msg
else:
rc = self.send_dsn(self.spf)
if rc != Milter.CONTINUE: if rc != Milter.CONTINUE:
self.fp = None self.fp = None
return rc return rc
del msg
if not ds.check_spam(screener,txt,self.recipients,classify=True): if not ds.check_spam(screener,txt,self.recipients,classify=True):
self.fp = None self.fp = None
return Milter.DISCARD return Milter.DISCARD
@@ -1635,22 +1541,6 @@ class bmsMilter(Milter.Milter):
quarantine=False) quarantine=False)
self.log("TRAINSPAM:",screener,'X-Dspam-Score: %f' % ds.probability) self.log("TRAINSPAM:",screener,'X-Dspam-Score: %f' % ds.probability)
def do_needed_cbv(self,msg):
q,template_name = self.cbv_needed
rc = self.send_dsn(q,msg,template_name)
self.cbv_needed = None
return rc
def need_cbv(self,policy,q,tname):
if policy == 'CBV':
if self.mailfrom != '<>' and not self.cbv_needed:
self.cbv_needed = (q,None)
elif policy == 'DSN':
if self.mailfrom != '<>' and not self.cbv_needed:
self.cbv_needed = (q,tname)
elif policy != 'OK': return True
return False
def eom(self): def eom(self):
if not self.fp: if not self.fp:
return Milter.ACCEPT # no message collected - so no eom processing return Milter.ACCEPT # no message collected - so no eom processing
@@ -1771,12 +1661,22 @@ class bmsMilter(Milter.Milter):
except Milter.error: except Milter.error:
self.addheader(name,val) # older sendmail can't insheader self.addheader(name,val) # older sendmail can't insheader
# Do not send CBV to internal domains (since we'll just get # do not send CBV to internal domains (since we'll just get
# the "Fraudulent MX" error). Whitelisted senders clearly do not # the "Fraudulent MX" error).
# need CBV. However, whitelisted domains might (to discover
# bogus localparts). Need a way to tell the difference.
if self.cbv_needed and not self.internal_domain: if self.cbv_needed and not self.internal_domain:
rc = self.do_needed_cbv(msg) q,res = self.cbv_needed
if res == 'softfail':
template_name = 'softfail'
elif res in ('fail','deny'):
template_name = 'fail'
elif res in ('unknown','permerror'):
template_name = 'permerror'
elif res == 'neutral':
template_name = 'neutral'
else:
template_name = 'strike3'
rc = self.send_dsn(q,msg,template_name)
self.cbv_needed = None
if rc == Milter.REJECT: if rc == Milter.REJECT:
# Do not feedback here, because feedback should only occur # Do not feedback here, because feedback should only occur
# for messages that have gone to DATA. Reputation lets us # for messages that have gone to DATA. Reputation lets us
@@ -1844,24 +1744,22 @@ class bmsMilter(Milter.Milter):
out.close() out.close()
return Milter.TEMPFAIL return Milter.TEMPFAIL
def send_dsn(self,q,msg=None,template_name=None): def send_dsn(self,q,msg,template_name):
sender = q.s sender = q.s
cached = cbv_cache.has_key(sender) cached = cbv_cache.has_key(sender)
if cached: if cached:
self.log('CBV:',sender,'(cached)') self.log('CBV:',sender,'(cached)')
res = cbv_cache[sender] res = cbv_cache[sender]
else: else:
m = None fname = template_name+'.txt'
if template_name: try:
fname = template_name+'.txt' template = file(template_name+'.txt').read()
try: self.log('CBV:',sender,'Using:',fname)
template = file(template_name+'.txt').read() except IOError:
m = dsn.create_msg(q,self.recipients,msg,template) template = None
self.log('CBV:',sender,'Using:',fname)
except IOError: pass
if not m:
self.log('CBV:',sender,'PLAIN') self.log('CBV:',sender,'PLAIN')
else: m = dsn.create_msg(q,self.recipients,msg,template)
if m:
if srs: if srs:
# Add SRS coded sender to various headers. When (incorrectly) # Add SRS coded sender to various headers. When (incorrectly)
# replying to our DSN, any of these which are preserved # replying to our DSN, any of these which are preserved
@@ -1885,10 +1783,7 @@ class bmsMilter(Milter.Milter):
return Milter.TEMPFAIL return Milter.TEMPFAIL
cbv_cache[sender] = res cbv_cache[sender] = res
self.log('REJECT:',desc) self.log('REJECT:',desc)
try: self.setreply('550','5.7.1',*desc.splitlines())
self.setreply('550','5.7.1',*desc.splitlines())
except TypeError:
self.setreply('550','5.7.1',"Callback failure")
return Milter.REJECT return Milter.REJECT
cbv_cache[sender] = res cbv_cache[sender] = res
return Milter.CONTINUE return Milter.CONTINUE
-41
View File
@@ -2,47 +2,6 @@ Title: Recent Changes
<h2> Recent Changes </h2> <h2> Recent Changes </h2>
<h3> 0.8.10 </h3>
SRS rejections now log the recipient.
I have finally implemented plain CBV (no DSN). The CBV policy
will do a plain CBV from now on, and the DSN policy is required
if you want to send a DSN.
I started checking the MAIL FROM fullname (human readable part
of an email) for porn keywords. There is now a banned IP database.
IPs are banned for too many bad MAIL FROMs or RCPT TOs, and remain banned
for 7 days.
<h3> 0.8.9 </h3>
I use the <code>%ifarch</code> hack to build milter and milter-spf
packages as noarch, while pymilter is built as native.
I removed the spf dependency from dsn.py, so pymilter can be used without
installing pyspf, and added a Milter.dns module to let python milters do
general DNS lookups without loading pyspf.
<h3> 0.8.8 </h3>
Programs do not belong in the /var/log directory. I moved the
milter apps to /usr/lib/pymilter. Since having the programs and
data in the same directory is convenient for debugging, it will
still use an executable present in the datadir.
Several general utility classes and functions are now in the Milter package
for possible use by other python milters. In addition to the trivial example
milter, a simple SPF only milter is included as a realistic example.
The spec file now build 3 RPMs:
<ul>
<li> pymilter is the milter module and Milter package for use by all python
milters.
<li> milter is the all-singing, all-dancing python milter application, with
supporting <code>/etc/init.d</code>, logrotate and other scripts.
<li> milter-spf is the simple SPF only milter application.
</ul>
<h3> 0.8.7 </h3> <h3> 0.8.7 </h3>
The spf module has been moved to the The spf module has been moved to the
+1 -1
View File
@@ -5,7 +5,7 @@ Title: Credits
<a href="mailto:Jim Niemira <urmane@urmane.org>">Jim Niemira</a> <a href="mailto:Jim Niemira <urmane@urmane.org>">Jim Niemira</a>
wrote the original C module and some quick wrote the original C module and some quick
and dirty python to use it. and dirty python to use it.
<a href="http://gathman.org/vitae">Stuart D. Gathman</a> <a href="mailto:Stuart Gathman <stuart@bmsi.com>">Stuart D. Gathman</a>
took that kludge and added threading and context objects to it, wrote a proper took that kludge and added threading and context objects to it, wrote a proper
OO wrapper (Milter.py) that handles attachments, did lots of testing, packaged OO wrapper (Milter.py) that handles attachments, did lots of testing, packaged
it with distutils, and generally transformed it from a quick hack to a it with distutils, and generally transformed it from a quick hack to a
+148 -105
View File
@@ -4,7 +4,8 @@ Title: Python Milter Mail Policy
These are the policies implemented by the <code>bms.py</code> milter These are the policies implemented by the <code>bms.py</code> milter
application. The milter and Milter modules do not implement any policies application. The milter and Milter modules do not implement any policies
by themselves. by themselves. Eventually, I'll get the bms.py milter moved to its
own package.
<h3> Classify connection </h3> <h3> Classify connection </h3>
@@ -76,119 +77,161 @@ altered accordingly.
<h2> SPF check </h2> <h2> SPF check </h2>
The MAIL FROM, connect IP, and HELO name are checked against Finally, the MAIL FROM, connect IP, and HELO name are checked against
any SPF records published via DNS for the alleged sender (MAIL FROM) any SPF records published via DNS for the alleged sender (MAIL FROM).
to determine the official SPF policy result. If there is no SPF record, we check for a local substitute under the
The offical SPF result is then logged in the Received-SPF header field, domain defined in the <code>[spf]delegate</code> configuration.
but certain results are subjected to further processing to create Further checks depend on the result.
an effective result for policy purposes.
If the official result is 'none', we try to turn it into an effective result of <table border=1>
'pass' or 'fail'. First, we check for a local substitute SPF record <tr><th>NONE</th><td>
under the domain defined in the <code>[spf]delegate</code> configuration. If there is no SPF record (official or delegated), then we
It is often useful to add local SPF records for correspondents that are initiate a "three strikes and your out" regime, which looks for
too clueless to add their own. If there is no local substitute, we use a "best <b>some</b> form of validated identification.
guess" SPF record of "v=spf1 a/24 mx/24 ptr" for MAIL FROM or "v=spf1 a/24 <ol>
mx/24" for HELO. In addition, a HELO that is a subdomain of MAIL FROM and <li>We try a "best guess" SPF record of "v=spf1 a/24 mx/24 ptr". If this
resolves to the connect IP results in an effective result of 'pass'. passes, good.
<li> We try to validate the HELO name. First check for an SPF record.
If there is no local SPF record, and the effective result is still not Otherwise, check whether the connect IP matches any A record for
'pass', we check for either a valid HELO name or a valid PTR record for the HELO name, or any A record for any MX name for the HELO name,
the connect IP. A valid HELO or PTR cannot look like a dynamic name or is at least in the same /24 subnet as any of the above.
as determined by the heuristic in <code>Milter.dynip</code>. (In other words, a HELO SPF "best guess" of "v=spf1 a/24 mx/24".)
If so, good. We consider the HELO validated. If the HELO SPF
If HELO has an SPF record, and the result is anything but pass, we reject check fails, we reject the email.
the connection: </ol>
<pre> <pre>
2005Jul30 19:45:16 [93991] connect from [221.200.41.54] at ('221.200.41.54', 3581) EXTERNAL DYN 2005Jul30 19:45:16 [93991] connect from [221.200.41.54] at ('221.200.41.54', 3581) EXTERNAL DYN
2005Jul30 19:45:18 [93991] hello from adelphia.net 2005Jul30 19:45:18 [93991] hello from adelphia.net
2005Jul30 19:45:19 [93991] mail from <wendy.stubbsua@link-it.com> () 2005Jul30 19:45:19 [93991] mail from <wendy.stubbsua@link-it.com> ()
2005Jul30 19:45:19 [93991] REJECT: hello SPF: fail 550 access denied 2005Jul30 19:45:19 [93991] REJECT: hello SPF: fail 550 access denied
</pre> </pre>
Note that HELO does not have any forwarding issues like MAIL FROM, and so <ol>
any result other than 'pass' or 'none' should be treated like 'fail'. <li> If there is a validated PTR name, and it doesn't look
like a dynamic name, good. We consider the connection validated.
Only if nothing about the SMTP envelope can be validated does the effective </ol>
result remain 'none. I call this the "3 strikes" rule. If any of the above can be validated, we continue on.
If none of the above can be validated, and the <code>[SPF]reject_noptr</code>
If the official result is 'permerror' (a syntax error in the sender's option is true, we reject the message immediately with the explanation
policy), we use the 'lax' option in pyspf to try various heuristics to guess that we need some form of valid identification before we accept an email.
what they really meant. For instance, the invalid mechanism "ip:1.2.3.4" is If <code>[SPF]reject_noptr</code> is false, we flag the message as
treated as "ip4:1.2.3.4". The result of lax processing is then used needing Call Back Validation.
as the effective result for policy purposes. The Call Back Valildation sends a DSN to the purported sender informing
them of the lack of identification. If the message is legitimate, the
With an effective SPF result in hand, we consult the sendmail access sender needs to know that their email setup is broken and should be corrected.
database to find our receiver policy for the sender. If the message is forged, the sender is informed of the forgery,
and their need to publish an SPF record or at least use a valid HELO name.
<table border=1> If the purported sender does not accept the DSN,
<tr><th>REJECT</th><td> then the message is rejected. The CBV status is cached to avoid
Reject the sender with a 550 5.7.1 SMTP code. The SMTP rejection annoying the purported sender with too many DSNs. Currently, the DSN
includes a detailed description of the problem. is repeated to the same sender once per month.
<p>
In this example, although 3com.com has no SPF record, we assume that
any legitimate mail from them will at least have a valid HELO or PTR.
<pre>
2005Jul30 23:52:03 [96777] connect from [222.252.233.200] at ('222.252.233.200', 29934) EXTERNAL DYN
2005Jul30 23:52:03 [96777] hello from 3mail.3com.com
2005Jul30 23:52:04 [96777] mail from <etec_nic_family@3mail.3com.com> ()
2005Jul30 23:52:04 [96777] REJECT: no PTR, HELO or SPF
</pre>
</td></tr> </td></tr>
<tr><th>CBV</th><td>
Do a Call Back Validation by connecting to an MX of the sender <tr><th>PASS</th><td>
and checking that using the sender as the RCPT TO is not rejected. A pass result normally lets the email continue on, but the domain is
We quit the CBV connection before actualling sending a message. tracked for reputation (and may be blocked), and may skip content scanning if
If the CBV is rejected, our SMTP connection is rejected with the it matches a whitelist.
same error code and message. CBV results are cached. <pre>
2005Jul24 17:44:26 [2104] mail from <gnucash-devel-bounces@gnucash.org> ('SIZE=4410',)
2005Jul24 17:44:26 [2104] Received-SPF: pass (mail.bmsi.com: domain of gnucash.org
designates 204.107.200.65 as permitted sender)
client-ip=204.107.200.65; envelope-from=gnucash-devel-bounces@gnucash.org; helo=cvs.gnucash.org;
</pre>
</td></tr> </td></tr>
<tr><th>DSN</th><td>
Do a Call Back Validation by connecting to an MX of the sender <tr><th>NEUTRAL</th><td>
and checking that using the sender as the RCPT TO is not rejected. A neutral result normally lets the email continue on, but the domain is not
Unlike a CBV, we continue on to data and send a detailed message tracked for reputation or matched against any whitelists.
explaining the problem. This can be useful for reporting PermError Highly forged domains listed in <code>[SPF]reject_neutral</code> are
or SoftFail to the sender. Keep in mind that for any result other rejected.
than 'pass', the sender could be forged, and your DSN could annoy the <pre>
wrong person. However, a SoftFail result is requesting such feedback 2005Jul24 17:41:37 [2070] connect from cp500627-a.dbsch1.nb.home.nl at ('84.27.225.3', 3465) EXTERNAL
for debugging and a PermError result needs to be fixed by the sender ASAP 2005Jul24 17:41:37 [2070] hello from cp500627-a.dbsch1.nb.home.nl
whether forged or not. DSN results are cached so that senders are 2005Jul24 17:41:38 [2070] mail from <nwarjejkw@yahoo.com> ()
annoyed only weekly. 2005Jul24 17:41:38 [2070] REJECT: SPF neutral for nwarjejkw@yahoo.com
</pre>
</td></tr> </td></tr>
<tr><th>OK</th><td>
Accept the sender. The message may still be rejected via reputation <tr><th>SOFTFAIL</th><td>
or content filtering. A softfail result normally lets the email continue on, but the domain is not
tracked for reputation or matched against any whitelists. Furthermore,
the message is flagged as needing Call Back Validation,
and the highly forged domains listed in <code>[SPF]reject_neutral</code> are
rejected as well.
<p>
At present, we also require a valid HELO or PTR to avoid rejecting
a softfail. But this should probably change to only require a
successful CBV.
<p>
The Call Back Valildation sends a DSN to the purported sender informing
them of the softfail. If the message is legitimate, the sender needs
to know about the softfail so that their email setup can be corrected.
If the message is forged, the sender is informed of the forgery, confirming
that SPF is protecting their reputation and encouraging a rapid transition
to a strict policy. If the purported sender does not accept the DSN,
then the message is rejected. The CBV status is cached to avoid
annoying the purported sender with too many DSNs. Currently, the DSN
is repeated to the same sender once per month.
<pre>
2005Jul24 15:41:33 [801] mail from <Aitp@horafeliz.com> ()
2005Jul24 15:41:33 [801] Received-SPF: softfail (mail.bmsi.com: transitioning domain of horafeliz.com
does not designate 221.184.83.185 as permitted sender)
client-ip=221.184.83.185; envelope-from=Aitp@horafeliz.com;
helo=p8185-ipad30funabasi.chiba.ocn.ne.jp;
2005Jul24 15:41:33 [801] rcpt to <david@example.com> ()
2005Jul24 15:41:35 [801] Subject: Microsoft, Adobe, Macromedia, Corel software. Up to 80% discount.
2005Jul24 15:41:35 [801] X-Mailer: Microsoft Outlook, Build 10.0.2605
2005Jul24 15:41:35 [801] CBV: Aitp@horafeliz.com
2005Jul24 15:41:38 [801] REJECT: CBV: 550 <Aitp@horafeliz.com>: User unknown
</pre>
</td></tr> </td></tr>
<tr><th>FAIL</th><td>
The message is rejected with a reference the SPF why page.
<pre>
2005Jul30 19:53:27 [94070] connect from [212.70.52.16] at ('212.70.52.16', 3192) EXTERNAL DYN
2005Jul30 19:53:27 [94070] hello from winzip.com
2005Jul30 19:53:27 [94070] mail from <dan@winzip.com> ()
2005Jul30 19:53:27 [94070] REJECT: SPF fail 550 SPF fail:
see http://openspf.com/why.html?sender=dan@winzip.com&ip=212.70.52.16
</pre>
</td></tr>
<tr><th>PERMERROR</th><td>
Permanent errors were called "unknown", and are still show that way
in the log. The message is rejected. Previously, we enabled "lax" parsing
of the SPF record, but rejecting is better because it informs the
sender about their problem. The next milter version will
look for a local substitute SPF record (as for a missing SPF record)
before rejecting. This will inform the sender of their problem, but
also let the receiver install a temporary workaround.
<pre>
2005Jul24 18:05:37 [2312] mail from <b-mihdbcgaacaa-becibijh-000-@msg.euxiphipops.com> ()
2005Jul24 18:05:37 [2312] REJECT: SPF unknown 550 SPF Permanent Error:
include mechanism missing domain: include
</pre>
The SPF record for msg.euxiphipops.com looked like this at the time of the
above error:
<pre>
msg.euxiphipops.com TXT "v=spf1 mx ptr a include"
</pre>
</td></tr>
<tr><th>TEMPERROR</th><td>
Temporary errors result in a 451 "Try again later" response. The sender
should retry the message at a later time.
<pre>
2005Jul24 07:33:13 [29846] mail from <quickenloans@rate.quicken.com> ('SIZE=73775', 'BODY=8BITMIME')
2005Jul24 07:33:43 [29846] TEMPFAIL: SPF error 450 SPF Temporary Error: DNS Timeout
</pre>
</td></tr>
</table> </table>
<h3> SPF policy syntax </h3>
First, the full sender is checked:
<pre>
SPF-Fail:abeb@adelphia.net DSN
</pre>
This says to accept mail from that adelphia.net user despite the
SPF fail, but only after annoying them with a DSN about their ISP's broken
policy.
If there is no match on the full sender, the domain is checked:
<pre>
SPF-Neutral:aol.com REJECT
</pre>
This says to reject mail from AOL with an SPF result of neutral.
This means AOL users can't use their AOL address with another mail service
to send us mail. This is good because the other mail service is
likely a badly configured greeting card site or a virus.
Finally, a default policy for the result is checked. While there are program
defaults, you should have defaults in the access database for SPF results:
<pre>
SPF-Neutral: CBV
SPF-Softfail: DSN
SPF-PermError: DSN
SPF-TempError: REJECT
SPF-None: REJECT
SPF-Fail: REJECT
SPF-Pass: OK
</pre>
<h2> Reputation </h2>
If the sender has not been rejected by this point, and if a GOSSiP server is
configured, we consult GOSSiP for the reputation score of the sender and
SPF result. The score is a number from -100 to 100 with a confidence
percentage from 0 to 100. A really bad reputation (less than -50 with
confidence greater than 3) is rejected. Note that the reputation is tracked
independently for each SPF result and sender combination. So aol.com:neutral
might have a really bad reputation, while aol.com:pass would be ok.
Furthermore, when a sender finally publishes an SPF policy and starts
getting SPF pass, their reputation is effectively reset.
+2 -14
View File
@@ -1,6 +1,4 @@
[milter] [milter]
# the directory with log and data files
datadir = /var/log/milter
# the socket used to communicate with sendmail. Must match sendmail.cf # the socket used to communicate with sendmail. Must match sendmail.cf
socket=/var/run/milter/pythonsock socket=/var/run/milter/pythonsock
# where to save original copies of defanged and failed messages # where to save original copies of defanged and failed messages
@@ -27,10 +25,7 @@ internal_connect = 192.168.0.0/16,127.*
;trusted_relay = 1.2.3.4, 66.12.34.56 ;trusted_relay = 1.2.3.4, 66.12.34.56
# Relaying to these domains is allowed from internal connections only. # Relaying to these domains is allowed from internal connections only.
# You might want to restrict aol.com, for instance, so that stupid ;private_relay = mycorp.com
# users don't forward their spam to aol for filtering and get your MTA
# blacklisted by aol.
;private_relay = aol.com, yahoo.com
# Reject external senders with hello names no legit external sender would use. # Reject external senders with hello names no legit external sender would use.
# SPF will do this also, but listing your own domain and mailserver here # SPF will do this also, but listing your own domain and mailserver here
@@ -62,7 +57,7 @@ porn_words = penis, breast, pussy, horse cock, porn, xenical, diet pill, d1ck,
p-e-n-i-s, hydrocodone, vicodin, xanax, vicod1n, x@nax, diazepam, p-e-n-i-s, hydrocodone, vicodin, xanax, vicod1n, x@nax, diazepam,
v1@gra, xan@x, cialis, ci@lis, frëe, xãnax, valíum, vãlium, via-gra, v1@gra, xan@x, cialis, ci@lis, frëe, xãnax, valíum, vãlium, via-gra,
x@n3x, vicod3n, penís, c0d1n, phentermine, en1arge, dip1oma, v1codin, x@n3x, vicod3n, penís, c0d1n, phentermine, en1arge, dip1oma, v1codin,
valium, rolex, sexual, fuck, adv1t, vgaira, medz, acai berry valium, rolex, sexual, fuck, adv1t
# reject mail with these case sensitive strings in the subject # reject mail with these case sensitive strings in the subject
spam_words = $$$, !!!, XXX, FREE, HGH spam_words = $$$, !!!, XXX, FREE, HGH
# attachments with these extensions will be replaced with a warning # attachments with these extensions will be replaced with a warning
@@ -191,11 +186,6 @@ blind = 1
# Map email addresses and aliases to dspam users # Map email addresses and aliases to dspam users
;dspam_users=david,goliath,spam,falsepositive ;dspam_users=david,goliath,spam,falsepositive
# List dspam users which train on all delivered messages, as opposed to
# "train on error" which trains only when a spam or falsepositive is reported.
# Training mode will build the dictionary faster, but requires close attention
# so as not to miss any spam or false positives.
;dspam_train=goliath
;david=david@foocorp.com,david.yelnetz@foocorp.com,david@bar.foocorp.com ;david=david@foocorp.com,david.yelnetz@foocorp.com,david@bar.foocorp.com
;goliath=giant@foocorp.com,goliath.philistine@foocorp.com ;goliath=giant@foocorp.com,goliath.philistine@foocorp.com
# address to forward spam to. milter will process these and not deliver # address to forward spam to. milter will process these and not deliver
@@ -221,8 +211,6 @@ blind = 1
# Use a dedicated GOSSiP server. If not specified, a local database # Use a dedicated GOSSiP server. If not specified, a local database
# will be used. # will be used.
;server=host:11900 ;server=host:11900
# To include peers of a peer in reputation, set ttl=2
;ttl=1
# If a local database is used, also consult these GOSSiP servers about # If a local database is used, also consult these GOSSiP servers about
# domains. Peer reputation is also tracked as to how often they # domains. Peer reputation is also tracked as to how often they
# agree with us, and weighted accordingly. # agree with us, and weighted accordingly.
+1 -1
View File
@@ -46,7 +46,7 @@ start() {
stop() { stop() {
# Stop daemons. # Stop daemons.
echo -n "Shutting down $prog: " echo -n "Shutting down $prog: "
killproc -d 9 milter killproc milter
RETVAL=$? RETVAL=$?
echo echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/milter [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/milter
+43 -57
View File
@@ -1,10 +1,5 @@
# This spec file contains 2 noarch packages in addition to the pymilter %define version 0.8.9
# module. To compile all three on 32-bit Intel, use: %define release 1
# rpmbuild -ba --target=i386,noarch pymilter.spec
%define __python python2.4
%define version 0.8.10
%define release 2%{?dist}.py24
# what version of RH are we building for? # what version of RH are we building for?
%define redhat7 0 %define redhat7 0
@@ -22,12 +17,22 @@
%define sysvinit milter.rc %define sysvinit milter.rc
%endif %endif
# RH9, other systems (single ps line per process) # RH9, other systems (single ps line per process)
%ifos Linux # whether to use system default python?
%define python python
#define python python2.4
%else
%define python python
%endif
%ifos aix4.1 %ifos aix4.1
%define libdir /var/log/milter %define libdir /var/log/milter
%else %else
%define libdir /usr/lib/pymilter %define libdir /usr/lib/pymilter
%endif %endif
# This spec file contains 2 noarch packages in addition to the pymilter
# module. To compile all three, use:
# rpmbuild -ba --target=i386,noarch pymilter.spec
%ifarch noarch %ifarch noarch
Name: milter Name: milter
Group: Applications/System Group: Applications/System
@@ -43,7 +48,7 @@ Prefix: %{_prefix}
Vendor: Stuart D. Gathman <stuart@bmsi.com> Vendor: Stuart D. Gathman <stuart@bmsi.com>
Packager: Stuart D. Gathman <stuart@bmsi.com> Packager: Stuart D. Gathman <stuart@bmsi.com>
Url: http://www.bmsi.com/python/milter.html Url: http://www.bmsi.com/python/milter.html
Requires: %{__python} >= 2.4, pyspf >= 2.0.4, pymilter Requires: %{python} >= 2.4, pyspf >= 2.0.4, pymilter
%ifos Linux %ifos Linux
Requires: chkconfig Requires: chkconfig
%endif %endif
@@ -85,7 +90,7 @@ cat >$RPM_BUILD_ROOT/etc/logrotate.d/milter <<'EOF'
compress compress
} }
/var/log/milter/banned_ips { /var/log/milter/banned_ips {
rotate 7 rotate 3
daily daily
copytruncate copytruncate
} }
@@ -107,14 +112,23 @@ find /var/log/milter/save -mtime +7 | xargs $R rm
EOF EOF
chmod a+x $RPM_BUILD_ROOT/etc/cron.daily/milter chmod a+x $RPM_BUILD_ROOT/etc/cron.daily/milter
%ifnos aix4.1 %ifos aix4.1
cat >$RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
#!/bin/sh
cd /var/log/milter
# uncomment to enable sgmlop if installed
#export PYTHONPATH=/usr/local/lib/python2.1/site-packages
exec /usr/local/bin/python bms.py >>milter.log 2>&1
EOF
%else # not aix4.1
cp start.sh $RPM_BUILD_ROOT%{libdir}
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
cp %{sysvinit} $RPM_BUILD_ROOT/etc/rc.d/init.d/milter cp %{sysvinit} $RPM_BUILD_ROOT/etc/rc.d/init.d/milter
cp spfmilter.rc $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter cp spfmilter.rc $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter
ed $RPM_BUILD_ROOT/etc/rc.d/init.d/milter <<'EOF' ed $RPM_BUILD_ROOT/etc/rc.d/init.d/milter <<'EOF'
/^python=/ /^python=/
c c
python="%{__python}" python="%{python}"
. .
w w
q q
@@ -122,13 +136,23 @@ EOF
ed $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter <<'EOF' ed $RPM_BUILD_ROOT/etc/rc.d/init.d/spfmilter <<'EOF'
/^python=/ /^python=/
c c
python="%{__python}" python="%{python}"
.
w
q
EOF
ed $RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
/^python=/
c
python="%{python}"
. .
w w
q q
EOF EOF
%endif # aix4.1 %endif # aix4.1
chmod a+x $RPM_BUILD_ROOT%{libdir}/start.sh
mkdir -p $RPM_BUILD_ROOT/var/run/milter
mkdir -p $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack mkdir -p $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack
cp -p rhsbl.m4 $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack cp -p rhsbl.m4 $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack
@@ -161,8 +185,10 @@ fi
%files %files
%defattr(-,root,root) %defattr(-,root,root)
%config %{libdir}/start.sh
/etc/logrotate.d/milter /etc/logrotate.d/milter
/etc/cron.daily/milter /etc/cron.daily/milter
%{libdir}/bms.py?
%ifos aix4.1 %ifos aix4.1
%defattr(-,smmsp,mail) %defattr(-,smmsp,mail)
%else %else
@@ -178,7 +204,6 @@ fi
%config(noreplace) /var/log/milter/neutral.txt %config(noreplace) /var/log/milter/neutral.txt
%config(noreplace) /var/log/milter/quarantine.txt %config(noreplace) /var/log/milter/quarantine.txt
%config(noreplace) /var/log/milter/permerror.txt %config(noreplace) /var/log/milter/permerror.txt
%config(noreplace) /var/log/milter/temperror.txt
%config(noreplace) /etc/mail/pymilter.cfg %config(noreplace) /etc/mail/pymilter.cfg
/usr/share/sendmail-cf/hack/rhsbl.m4 /usr/share/sendmail-cf/hack/rhsbl.m4
@@ -205,8 +230,8 @@ Prefix: %{_prefix}
Vendor: Stuart D. Gathman <stuart@bmsi.com> Vendor: Stuart D. Gathman <stuart@bmsi.com>
Packager: Stuart D. Gathman <stuart@bmsi.com> Packager: Stuart D. Gathman <stuart@bmsi.com>
Url: http://www.bmsi.com/python/milter.html Url: http://www.bmsi.com/python/milter.html
Requires: %{__python} >= 2.4, sendmail >= 8.13 Requires: %{python} >= 2.4, sendmail >= 8.13
BuildRequires: %{__python}-devel >= 2.4, sendmail-devel >= 8.13 BuildRequires: %{python}-devel >= 2.4, sendmail-devel >= 8.13
%description %description
This is a python extension module to enable python scripts to This is a python extension module to enable python scripts to
@@ -224,44 +249,18 @@ DSNs, and doing CBV.
%else # Redhat builds debug packages after 7.3 %else # Redhat builds debug packages after 7.3
LDFLAGS="-g" LDFLAGS="-g"
%endif %endif
env CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$LDFLAGS" %{__python} setup.py build env CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$LDFLAGS" %{python} setup.py build
%install %install
rm -rf $RPM_BUILD_ROOT rm -rf $RPM_BUILD_ROOT
%{__python} setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES %{python} setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES
mkdir -p $RPM_BUILD_ROOT/var/run/milter
mkdir -p $RPM_BUILD_ROOT%{libdir}
%ifos aix4.1
cat >$RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
#!/bin/sh
cd /var/log/milter
# uncomment to enable sgmlop if installed
#export PYTHONPATH=/usr/local/lib/python2.1/site-packages
exec /usr/local/bin/python bms.py >>milter.log 2>&1
EOF
%else # not aix4.1
cp start.sh $RPM_BUILD_ROOT%{libdir}
ed $RPM_BUILD_ROOT%{libdir}/start.sh <<'EOF'
/^python=/
c
python="%{__python}"
.
w
q
EOF
%endif
chmod a+x $RPM_BUILD_ROOT%{libdir}/start.sh
%if !%{redhat7} %if !%{redhat7}
#grep '.pyc$' INSTALLED_FILES | sed -e 's/c$/o/' >>INSTALLED_FILES grep '.pyc$' INSTALLED_FILES | sed -e 's/c$/o/' >>INSTALLED_FILES
%endif %endif
# start.sh is used by spfmilter and milter, and could be used by
# other milters running on redhat
%files -f INSTALLED_FILES %files -f INSTALLED_FILES
%defattr(-,root,root) %defattr(-,root,root)
%doc README HOWTO ChangeLog NEWS TODO CREDITS sample.py milter-template.py %doc README HOWTO ChangeLog NEWS TODO CREDITS sample.py milter-template.py
%config %{libdir}/start.sh
%dir %attr(0755,mail,mail) /var/run/milter
%endif # noarch %endif # noarch
@@ -269,18 +268,6 @@ chmod a+x $RPM_BUILD_ROOT%{libdir}/start.sh
rm -rf $RPM_BUILD_ROOT rm -rf $RPM_BUILD_ROOT
%changelog %changelog
* Mon Aug 25 2008 Stuart Gathman <stuart@bmsi.com> 0.8.10-2
- /var/run/milter directory must be owned by mail
* Mon Aug 25 2008 Stuart Gathman <stuart@bmsi.com> 0.8.10-1
- log rcpt for SRS rejections
- improved parsing into email and fullname (still 2 self test failures)
- implement no-DSN CBV, reduce full DSNs
- check for porn words in MAIL FROM fullname
- ban IP for too many bad MAIL FROMs or RCPT TOs
- temperror policy in access
- no CBV for whitelisted MAIL FROM except permerror, softfail
- Allow explicitly whitelisted email from banned_users.
- configure gossip TTL
* Mon Sep 24 2007 Stuart Gathman <stuart@bmsi.com> 0.8.9-1 * Mon Sep 24 2007 Stuart Gathman <stuart@bmsi.com> 0.8.9-1
- Use %ifarch hack to build milter and milter-spf packages as noarch - Use %ifarch hack to build milter and milter-spf packages as noarch
- Remove spf dependency from dsn.py, add dns.py - Remove spf dependency from dsn.py, add dns.py
@@ -299,7 +286,6 @@ rm -rf $RPM_BUILD_ROOT
- SPF moved to pyspf RPM - SPF moved to pyspf RPM
- wiretap archive option - wiretap archive option
- Do plain CBV if missing template - Do plain CBV if missing template
- SMTP AUTH policy in access
* Tue May 23 2006 Stuart Gathman <stuart@bmsi.com> 0.8.6-2 * Tue May 23 2006 Stuart Gathman <stuart@bmsi.com> 0.8.6-2
- Support CBV timeout - Support CBV timeout
- Support fail template, headers in templates - Support fail template, headers in templates
+13
View File
@@ -22,6 +22,19 @@ their quarantined mail and may notice your message. If your message is
important, please contact them via other means. You may also try sending important, please contact them via other means. You may also try sending
them a simple plain text message. them a simple plain text message.
If you never sent the above message, then your domain, %(sender_domain)s,
was forged - i.e. used without your knowlege or authorization by
someone attempting to steal your mail identity. This is a very
serious problem, and you need to provide authentication for your
SMTP (email) servers to prevent criminals from forging your
domain. The simplest step is usually to publish an SPF record
with your Sender Policy.
For more information, see: http://www.openspf.org
Your mail admin needs to publish a strict SPF record so that I can reject
those forgeries instead of bugging you with them.
If you need further assistance, please do not hesitate to contact me. If you need further assistance, please do not hesitate to contact me.
Kind regards, Kind regards,
+1 -1
View File
@@ -16,7 +16,7 @@ if sys.version < '2.2.3':
DistributionMetadata.download_url = None DistributionMetadata.download_url = None
# NOTE: importing Milter to obtain version fails when milter.so not built # NOTE: importing Milter to obtain version fails when milter.so not built
setup(name = "pymilter", version = '0.8.10', setup(name = "pymilter", version = '0.8.9',
description="Python interface to sendmail milter API", description="Python interface to sendmail milter API",
long_description="""\ long_description="""\
This is a python extension module to enable python scripts to This is a python extension module to enable python scripts to
-33
View File
@@ -1,33 +0,0 @@
To: %(sender)s
From: postmaster@%(receiver)s
Subject: Critical DNS configuration error
Auto-Submitted: auto-generated (configuration error)
This is an automatically generated Delivery Status Notification.
THIS IS A WARNING MESSAGE ONLY.
YOU DO *NOT* NEED TO RESEND YOUR MESSAGE.
Delivery to the following recipients has been delayed.
%(rcpt)s
Subject: %(subject)s
Received-SPF: %(spf_result)s
Your DNS server is not responding to TXT queries. In other words,
it is BROKEN. You need to get somebody to fix it ASAP. We
are attempting to do TXT queries to see if you have an SPF record.
See http://openspf.org
We are sending you this message to alert you to the fact that
you have problems with your DNS.
If you need further assistance, please do not hesitate to
contact me again.
Kind regards,
postmaster@%(receiver)s
+1 -1
View File
@@ -44,7 +44,7 @@ class TestMilter(bms.bmsMilter):
self._msg[field] = value self._msg[field] = value
self.headerschanged = True self.headerschanged = True
def addheader(self,field,value,idx=-1): def addheader(self,field,value):
if not self._body: if not self._body:
raise IOError,"addheader not called from eom()" raise IOError,"addheader not called from eom()"
self.log('addheader: %s=%s' % (field,value)) self.log('addheader: %s=%s' % (field,value))