-
Notifications
You must be signed in to change notification settings - Fork 6
/
ppolicy.conf
412 lines (370 loc) · 17.6 KB
/
ppolicy.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Configuration file for PPolicy
#
# Copyright (c) 2005,2006,2007,2008 JAS
#
# Author: Petr Vokac <vokac@kmlinux.fjfi.cvut.cz>
#
# $Id$
#
import logging
#
# logging (FATAL, ERROR, WARN, INFO, DEBUG)
#
#logLevel = logging.INFO
logLevel = logging.DEBUG
#
# if you install ppolicy from tar.gz package, basePath should be
# set to the directory where you did `tar xzf ppolicy-2.x.tar.gz`
#
#basePath = '/path/to/root/of/ppolicy'
#
# use Psyco for python code optimalization
# (set this option to False if you want to see correct code lines
# in logging output)
#
usePsyco = True
#
# contact in case of some problems
# (without correct values some check modules doesn't work right)
#
admin = 'postmaster@example.com' # recomended: postmaster
domain = 'example.com' # recommended: your.domain.name, default: host.domain
#
# Database settings
#
databaseAPI = 'MySQLdb'
database = { 'host' : 'localhost',
'port' : 3306,
'db' : 'ppolicy',
'user' : 'ppolicy',
'passwd' : 'secret',
# 'cp_min' : 3, # connection pool min conns
# 'cp_max' : 5, # connection pool max conns
# 'cp_noisy': 0, # noisy connection pool logging
}
#
# PPolicy daemon command port. This port is used to manage
# and debug ppolicy daemon.
#
commandPort = 10030
#
# PPolicy daemon listen port. This port is used by Postfix
# check_policy_service. You can specify array of ports with
# different configuration in check method.
#
#ppolicyPort = [ 10031, 10032, 10033 ]
ppolicyPort = 10031
#
# Cache
#
# choose cache engine
# local store results in local RAM (requires cacheSize option)
# memcache use memcache (requires cacheServers option)
cacheEngine = 'local'
# cache size (number of records) for local engine. Increasing this value
# can lead to higher performance but it also uses more memory
# (approx. 100b for each record, default value: 10000)
cacheSize = 10000
# array cache servers for memcache, see python memcache documentation
# for details
cacheServers = [ '127.0.0.1:11211' ]
#
# State file
# store cached data between ppolicy restarts
#
stateFile = '/etc/postfix/ppolicy.state'
#
# Define check modules and its parameters. These modules can be
# referenced by its unique name in check function.
# format: { name: (type, param), ... }
# name ... unique module name
# type ... module type (SPF, List, Greylist, ...)
# param .. dictionary of module parameters, e.g. { param: "sender", ... }
#
modules = {
'dumpfile': ('DumpDataFile', { 'fileName': '/tmp/dump.dat' }),
'dumpdb': ('DumpDataDB', {}),
'spf': ('SPF', {}),
'dos': ('DOS', { 'params': 'sender' }),
'trap': ('Trap', {}),
'list': ('List', {
'table': 'list', 'param': 'recipient', 'column': 'key' }),
'list_cached': ('List', {
'table': 'list', 'param': 'recipient',
'cacheCaseSensitive': True, 'column': 'key',
'cacheAll': True }),
'list_multi': ('List', {
'table': 'list_multi',
'param': [ 'sender', 'recipient' ],
'column': [ 'sender', 'recipient' ] }),
'list_multi_cached': ('List', {
'table': 'list_multi',
'param': [ 'sender', 'recipient' ],
'column': [ 'sender', 'recipient' ],
'cacheCaseSensitive': True, 'cacheAll': True }),
'list_amavis_domain_score': ('List', {
'table': 'amavis_domain_score',
'param': 'sender_domain', 'column': 'domain',
'retcols': [ 'score', 'cnt' ],
'cacheCaseSensitive': False,
'cacheAll': True, 'cacheAllRefresh': 60*60 }),
'list_amavis_whitelist_sender': ('List', {
'table': 'amavis_sender_recipient_score',
'param': 'sender', 'column': 'recip',
'cacheCaseSensitive': False,
'cacheAll': True, 'cacheAllRefresh': 60*60 }),
'list_bw': ('ListBW', {
'param': 'recipient',
'tableWhitelist': 'list_w', 'tableBlacklist': 'list_b',
'mappingWhitelist': { 'recipient': 'key' },
'mappingBlacklist': { 'recipient': 'key' }}),
'list_bw_cached': ('ListBW', {
'param': 'recipient',
'tableWhitelist': 'list_w', 'tableBlacklist': 'list_b',
'mappingWhitelist': { 'recipient': 'key' },
'mappingBlacklist': { 'recipient': 'key' },
'cacheCaseSensitive': False, 'cacheAll': True }),
'list_bw_sender': ('ListMailDomain', {
'param': 'sender',
'tableWhitelist': 'whitelist_sender',
'tableBlacklist': 'blacklist_sender' }),
'list_bw_client_address': ('ListBW', {
'param': 'client_address',
'tableWhitelist': 'whitelist_client_address',
'tableBlacklist': 'blacklist_client_address',
'mappingWhitelist': { 'client_address': 'key' },
'mappingBlacklist': { 'client_address': 'key' },
'cacheAll': True }),
'list_bw_client_name': ('ListMailDomain', {
'param': 'client_name',
'tableWhitelist': 'whitelist_client_name',
'tableBlacklist': 'blacklist_client_name' }),
'lookup_db': ( 'LookupDB', { 'param': 'sender',
'table': 'lookup_db',
'retcols': [ 'col1', 'col2', 'col3' ],
'mapping': { 'sender': ( 'key', 'VARCHAR(50)' ) } }),
'lookup_db_cache': ( 'LookupDB', { 'param': 'sender',
'table': 'lookup_db',
'retcols': [ 'col1', 'col2', 'col3' ],
'mapping': { 'sender': ( 'key', 'VARCHAR(50)' ) },
'cacheAll': True }),
'lookup_ldap': ( 'LookupLDAP', { 'param': 'recipient',
'uri': 'ldap://ldap1.domain.tld ldap://ldap2.domain.tld',
'base': 'ou=People,dc=domain,dc=tld',
'filter': '(mail=%m)', 'attributes': 'cn' } ),
'verify_mx': ('Verification', { 'param': 'sender', 'vtype': 'mx' }),
'verify_connection': ('Verification', { 'param': 'sender' }),
'verify_domain': ('Verification', { 'param': 'sender', 'vtype': 'domain' }),
'verify_user': ('Verification', { 'param': 'sender', 'vtype': 'user' }),
'resolve_ip_name': ('Resolve', { 'param': 'client_address', 'type': 'ip->name' }),
'resolve_name_ip': ('Resolve', { 'param': 'client_name', 'type': 'name->ip' }),
'resolve_name_mx': ('Resolve', { 'param': 'client_name', 'type': 'name->mx' }),
'resolve_ip_name_ip': ('Resolve', { 'param': 'client_address', 'type': 'ip->name->ip' }),
'resolve_ip1_name_ip2': ('Resolve', { 'param': 'client_address', 'type': 'ip1->name->ip2' }),
'resolve_ip_name_mx': ('Resolve', { 'param': 'client_address', 'type': 'ip->name->mx' }),
'resolve_name_ip_name': ('Resolve', { 'param': 'client_name', 'type': 'name->ip->name' }),
'resolve_name1_ip_name2': ('Resolve', { 'param': 'client_name', 'type': 'name1->ip->name2' }),
'greylist': ('Greylist', {}),
'dnsbl_zen': ('Dnsbl', { 'dnsbl': 'ZEN' }),
'dnsbl_njabl': ('Dnsbl', { 'dnsbl': 'NJABL' }),
'dnsbl_sbl': ('Dnsbl', { 'dnsbl': 'SBL' }),
'dnsbl_xbl': ('Dnsbl', { 'dnsbl': 'XBL' }),
'dnsbl_spamcop': ('Dnsbl', { 'dnsbl': 'SPAMCOP' }),
'dnsbl_sorbs': ('Dnsbl', { 'dnsbl': 'SORBS' }),
'dnsbl_maps': ('Dnsbl', { 'dnsbl': 'MAPS-RBLPLUS' }),
'dnsblscore': ('DnsblScore', { 'dnsbl':
[ 'DNS_FROM_AHBL_RHSBL', 'DNS_FROM_RFC_BOGUSMX',
'DNS_FROM_RFC_DSN', 'DNS_FROM_SECURITYSAGE',
'DNS_FROM_SECURITYSAGE', 'RCVD_IN_BL_SPAMCOP_NET',
'RCVD_IN_DSBL', 'RCVD_IN_NJABL_PROXY',
'RCVD_IN_NJABL_SPAM', 'RCVD_IN_SBL', 'RCVD_IN_SORBS_DUL',
'RCVD_IN_SORBS_SOCKS', 'RCVD_IN_SORBS_WEB',
'RCVD_IN_SORBS_ZOMBIE', 'RCVD_IN_WHOIS_BOGONS',
'RCVD_IN_WHOIS_HIJACKED', 'RCVD_IN_WHOIS_INVALID',
'RCVD_IN_XBL' ] }),
'dnsbldynamic': ('DnsblDynamic', { 'dnsbl': [ 'NJABLDYNA', 'SORBSDUL' ] }),
'country': ( 'Country', { 'param': 'client_address',
'dataPath': '/usr/share/GeoIP/GeoIP.dat' }),
'p0f': ( 'P0f', {}),
'sleep': ( 'Sleep', { 'sleep': 60 }),
# '': ('', {}),
}
#
# PPolicy connection limit
#
connLimit = 100
#
# What to return if number of connection to ppolicy daemon reaches its limit
# see RFC1893 for mail enhanced status codes
#
returnOnConnLimit = ('450', 'reached connection limit to ppolicy, retry later')
#returnOnFatalError = ('dunno', '')
#
# What to return when fatal error (e.g. uncatched exception) happen
# see RFC1893 for mail enhanced status codes
#
returnOnFatalError = ('450', 'fatal error when checking SMTP data, retry later')
#returnOnFatalError = ('dunno', '')
#
# Method for checking requests
#
def check(factory, data, port):
# this is similar to postfix reject_unknown_client rule, but it is
# less restrictive, because postfix checks ip after translating
# ip->name->ip, but here we require only existence of DNS reverse record
#if data.get('client_name', '') == '':
# result '450', "we don't accept mail from domain without DNS PTR record"
# if we want to be a bit more restrictive, we can require that reverse DNS
# name has some A record (ip1->name->ip2), one of A record match original
# IP address (ip->name->ip), has MX or A record (ip->name->mx)
#res, resEx = factory.check('resolve_ip_name_mx', data)
#if res < 0:
# result '450', "DNS records for %s are incorrect" % data.get('client_address')
# here we are using greylisting but only if client_address score is higher
# then defined threshold (6). The score is computed as sum of scores defined
# by spamassassin for various DNS blacklist
#res, resEx = factory.check('dnsblscore', data)
#if res > 6:
# res, resEx = factory.check('greylist', data)
# if res < 0:
# result '450', resEx
# use greylisting if client_address is probably from dynamic IP range
# and it doesn't successfully pass SPF checking
#res, resEx = factory.check('dnsbldynamic', data)
#if res > 0:
# res, resEx = factory.check('spf', data)
# if spf < 0:
# res, resEx = factory.check('greylist', data)
# if res < 0:
# result '450', resEx
# verify that we can contact sender by connecting its to mailserver
#res, resEx = factory.check('verify_connection', data)
#if res < 0:
# return '450', resEx
# verify that sender exist if mail coming from suspicious client_address
#res, resEx = factory.check('dnsblscore', data)
#if res > 6:
# res, resEx = factory.check('verify_user', data)
# if res < 0:
# result '450', resEx
# use spam traps to block sites that send mail to random users
# (this module is not fully tested - be careful when you want to use it)
#res, resEx = factory.check('trap', data, [ 'spamtrap1@example.com', 'spamtrap2@example.com' ])
#if res > 0:
# return '450', 'you are sending too many mails to random users, slow down...'
#elif res == DOS.CHECK_RESULT_TRAP:
# return '550', "this is spam trap email address, don't use it or you will be blacklisted"
# DOS module can be used to limit number of incoming mail/time
# You should not block mail to postmaster and from mailer-daemon
# (this module is not fully tested - be careful when you want to use it)
#if data.get('sender', '') != '' and data.get('recipient', '').lower()[:11] != 'postmaster':
# res, resEx = factory.check('dos', data)
# if res < 0:
# return '450', 'you are sending too many mails, slow down...'
# Reject all suspicious mail with information for sender how to
# add his address/domain/client_address to the whitelist
#res, resEx = factory.check('dnsblscore', data)
#if res > 6:
# res, resEx = factory.check('list', data)
# if res < 0:
# return '550', "you are sending mail from suspicious address and your mail can't be delivered, if you want to pass these restrictions, you can add your address to our whitelist on following site http://www.example.com/mail/whitelist"
# Slow down reception of suspicious mail (be careful using this
# method, because it can lead to DOS for all incoming SMTP requests)
#res, resEx = factory.check('dnsblscore', data)
#if res > 6:
# res, resEx = factory.check('list', data)
# time.sleep(5)
# From Russia and China accept only mail from mailservers with correct
# reverse records
#if factory.check('country')[1] in [ 'RU', 'CN' ]:
# if data.get('client_name', '') == '':
# return return '550', "we don't accept RU, CN mail from mailservers without correct DNS configuration"
# Complex example applied only to mail with recipient address in
# form @subdomain.example.com. If sender is not in whitelist
# (whitelist_sender) and is not mailer-daemon, than test mail must
# pass further tests. First we declare DNSBL score threshold
# according results SPF, Resolve and DNS name <-> helo name
# correspondence. Correctly configured mailserver should pass all
# these check without problems but if some of them fail, then we
# lower threshold for DNSBL score. If DnsblScore exceed threshold
# then further tests are used to decide which mail we accept or
# reject. "Correct" DNS records are tested and "temporary failure"
# error is returned in case this test fail. Then it is checked if
# we can contact sender mailserver and "temporary failure" is
# returned in the test fails. Last rule make greylisting all these
# suspicious mails
#if data.get('recipient', '').lower()[-len('@subdomain.example.com'):] == '@subdomain.example.com':
# sender_ok = False
# if data.get('sender', '') == '':
# sender_ok = True
# else:
# res, resEx = factory.check('whitelist_sender', data)
# sender_ok = res > 0
# if not sender_ok:
# dnsblTreshold = 5
# if data.get('client_name', '').lower() != data.get('helo_name', '').lower():
# dnsblTreshold -= 0.5
# res, resEx = factory.check('resolve_ip_name', data)
# if res < 0:
# dnsblTreshold -= 1
# res, resEx = factory.check('spf', data)
# if res < 0:
# dnsblTreshold -= 1
# res, resEx = factory.check('dnsblscore', data)
# logging.getLogger().debug("CONF: check threshold/score: %s/%s" % (dnsblTreshold, res))
# if res > dnsblTreshold:
# res, resEx = factory.check('resolve_ip_name_mx', data)
# if res < 0:
# return '450', 'Your client address is suspicious, it doesnt have correct DNS records. To whitelist your mail see http://www.example.com/mail'
# res, resEx = factory.check('verify_connection', data)
# if res < 0:
# return '550', 'Your client address is suspicious and your mailserver address cant be verified. To whitelist your mail see http://www.example.com/mail/'
# res, resEx = factory.check('greylist', data)
# if res < 0:
# wt = ''
# if resEx.rfind(' ') != -1:
# wt = " after %s" % resEx[resEx.rfind(' '):]
# return '450', "Your client address is suspicious, greylist in progress, try again later%s. To whitelist your mail see http://www.example.com/mail/" % wt
# resource usage at the beginning of check method
# import resource
# import gc
# gc.collect()
# data['resource_gc_start'] = "%s, %s" % (len(gc.get_objects()), len(gc.garbage))
# data['resource_usage_start'] = str(resource.getrusage(resource.RUSAGE_SELF))
# tests, results are stored in 'data' dictionary, can be used for debugging
# modules and for analysis to find new way to identify spam sources
res, resEx = factory.check('list', data)
res, resEx = factory.check('list_cached', data)
res, resEx = factory.check('list_multi', data)
res, resEx = factory.check('list_multi_cached', data)
res, resEx = factory.check('list_bw', data)
res, resEx = factory.check('list_bw_cached', data)
res, resEx = factory.check('list_bw_sender', data)
res, resEx = factory.check('list_bw_client_address', data)
res, resEx = factory.check('list_bw_client_name', data)
res, resEx = factory.check('lookup_db', data)
res, resEx = factory.check('lookup_db_cache', data)
res, resEx = factory.check('lookup_ldap', data)
res, resEx = factory.check('dos', data)
res, resEx = factory.check('trap', data, [ 'spamtrap1@example.com', 'spamtrap2@example.com' ])
res, resEx = factory.check('spf', data)
# res, resEx = factory.check('verify_connection', data)
res, resEx = factory.check('resolve_name_mx', data)
res, resEx = factory.check('greylist', data)
res, resEx = factory.check('dnsbl_xbl', data)
res, resEx = factory.check('dnsblscore', data)
res, resEx = factory.check('dnsbldynamic', data)
res, resEx = factory.check('country', data)
res, resEx = factory.check('p0f', data)
# resource usage at the end of check method
# gc.collect()
# data['resource_gc_stop'] = "%s, %s" % (len(gc.get_objects()), len(gc.garbage))
# data['resource_usage_stop'] = str(resource.getrusage(resource.RUSAGE_SELF))
# save request info in database (e.g. for statistical overview)
factory.check('dumpdb', data)
# save request info in file
#factory.check('dumpfile', data)
return 'dunno', ''