xref: /openbsd/libexec/spamd/spamd.8 (revision cecf84d4)
1.\"	$OpenBSD: spamd.8,v 1.127 2015/04/14 17:29:06 deraadt Exp $
2.\"
3.\" Copyright (c) 2002 Theo de Raadt.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24.\"
25.Dd $Mdocdate: April 14 2015 $
26.Dt SPAMD 8
27.Os
28.Sh NAME
29.Nm spamd
30.Nd spam deferral daemon
31.Sh SYNOPSIS
32.Nm spamd
33.Bk -words
34.Op Fl 45bdv
35.Op Fl B Ar maxblack
36.Op Fl C Ar file
37.Op Fl c Ar maxcon
38.Op Fl G Ar passtime : Ns Ar greyexp : Ns Ar whiteexp
39.Op Fl h Ar hostname
40.Op Fl K Ar file
41.Op Fl l Ar address
42.Op Fl M Ar address
43.Op Fl n Ar name
44.Op Fl p Ar port
45.Op Fl S Ar secs
46.Op Fl s Ar secs
47.Op Fl w Ar window
48.Op Fl Y Ar synctarget
49.Op Fl y Ar synclisten
50.Ek
51.Sh DESCRIPTION
52.Nm
53is a fake mail daemon which rejects false mail.
54It is designed to be very efficient so that it does not slow down the
55receiving machine.
56.Pp
57.Nm
58considers sending hosts to be of three types:
59.Pp
60.Em blacklisted
61hosts are redirected to
62.Nm
63and
64.Em tarpitted
65i.e. they are communicated with very slowly
66to consume the sender's resources.
67Mail is rejected with either a 450 or 550 error message.
68A blacklisted host will not be allowed to talk to a real mail server.
69.Pp
70.Em whitelisted
71hosts do not talk to
72.Nm .
73Their connections are instead sent to a real mail server,
74such as
75.Xr smtpd 8 .
76.Pp
77.Em greylisted
78hosts are redirected to
79.Nm ,
80but
81.Nm
82has not yet decided if they are likely spammers.
83They are given a temporary failure message by
84.Nm
85when they try to deliver mail.
86.Pp
87When
88.Nm
89is run in default mode,
90it will greylist connections from new hosts.
91Depending on its configuration,
92it may choose to blacklist the host or,
93if the checks described below are met,
94eventually whitelist it.
95When
96.Nm
97is run in blacklist-only mode,
98using the
99.Fl b
100flag,
101it will consult a pre-defined set of blacklist addresses
102to decide whether to tarpit the host or not.
103.Pp
104When a sending host talks to
105.Nm ,
106the reply will be
107.Em stuttered .
108That is,
109the response will be sent back a character at a time, slowly.
110For blacklisted hosts,
111the entire dialogue is stuttered.
112For greylisted hosts,
113the default is to stutter for the first 10 seconds
114of dialogue only.
115.Pp
116The options are as follows:
117.Bl -tag -width Ds
118.It Fl 4
119For blacklisted entries, return error code 450 to the spammer (default).
120.It Fl 5
121For blacklisted entries, return error code 550 to the spammer.
122.It Fl B Ar maxblack
123The maximum number of concurrent blacklisted connections to stutter at.
124This value may not be greater than maxcon (see below).
125The default is
126.Ar maxcon
127\- 100.
128When this value is exceeded, new blacklisted connections will not be
129stuttered at.
130.It Fl b
131Run in blacklist-only mode.
132.It Fl C Ar file
133Load the certificate for TLS from the given
134.Ar file .
135.It Fl c Ar maxcon
136The maximum number of concurrent connections to allow.
137.Ar maxcon
138may not exceed
139.Va kern.maxfiles
140\- 200, and defaults to 800.
141.It Fl d
142Debug mode.
143.Nm
144does not
145.Xr fork 2
146into the background.
147.It Xo
148.Fl G
149.Ar passtime : Ns Ar greyexp : Ns Ar whiteexp
150.Xc
151Adjust the three time parameters for greylisting.
152.Ar passtime
153defaults to 25 (minutes),
154.Ar greyexp
155to 4 (hours),
156and
157.Ar whiteexp
158to 864 (hours, approximately 36 days).
159.It Fl h Ar hostname
160The hostname that is reported in the SMTP banner.
161.It Fl K Ar file
162Load the private key for TLS from the given
163.Ar file .
164.It Fl l Ar address
165Specify the local address to which
166.Nm
167is to
168.Xr bind 2 .
169By default
170.Nm
171listens on all local addresses.
172.It Fl M Ar address
173Specify a local IP address which is listed as a low priority MX record,
174used to identify and trap hosts that connect to MX hosts out of order.
175See
176.Sx GREYTRAPPING
177below for details.
178.It Fl n Ar name
179The SMTP version banner that is reported upon initial connection.
180.It Fl p Ar port
181Specify a different port number from the default port that
182.Nm
183should listen for redirected SMTP connections on.
184The default port is found by looking for the named service
185.Dq spamd
186using
187.Xr getservbyname 3 .
188.It Fl S Ar secs
189Stutter at greylisted connections for the specified amount
190of seconds, after which the connection is not stuttered at.
191The default is 10; maximum is 90.
192.It Fl s Ar secs
193Delay each character sent to the client by the specified
194amount of seconds.
195The default is 1; maximum is 10.
196.It Fl v
197Enable verbose logging.
198By default
199.Nm
200logs connections, disconnections and blacklist matches to
201.Xr syslogd 8
202at
203.Dv LOG_INFO
204level.
205With verbose logging enabled, message detail
206including subject and recipient information is logged at
207.Dv LOG_INFO ,
208along with the message body and SMTP dialogue being logged at
209.Dv LOG_DEBUG
210level.
211.It Fl w Ar window
212Set the socket receive buffer to this many bytes, adjusting the window size.
213.It Fl Y Ar synctarget
214Add target
215.Ar synctarget
216to receive synchronisation messages.
217.Ar synctarget
218can be either an IPv4 address for unicast messages
219or a network interface and optional TTL value for multicast messages
220to the group 224.0.1.240.
221If the multicast TTL is not specified, a default value of 1 is used.
222This option can be specified multiple times.
223See also
224.Sx SYNCHRONISATION
225below.
226.It Fl y Ar synclisten
227Listen on
228.Ar synclisten
229network interface for incoming synchronisation messages.
230This option can be specified only once.
231See also
232.Sx SYNCHRONISATION
233below.
234.El
235.Pp
236When run in default mode,
237connections receive the pleasantly innocuous temporary failure of:
238.Bd -literal -offset 4n
239451 Temporary failure, please try again later.
240.Ed
241.Pp
242This happens in the SMTP dialogue
243immediately after the DATA command is received from the client.
244.Nm
245will use the db file in
246.Pa /var/db/spamd
247to track these connections to
248.Nm
249by connecting IP address, HELO/EHLO, envelope-from, and envelope-to, or
250.Em tuple
251for short.
252.Pp
253A previously unseen tuple is added to the
254.Pa /var/db/spamd
255database, recording the time an initial connection attempt was seen.
256After
257.Em passtime
258minutes if
259.Nm
260sees a retried attempt to deliver mail for the same tuple,
261.Nm
262will whitelist the connecting address by adding it as a
263whitelist entry to
264.Pa /var/db/spamd .
265.Pp
266.Nm
267regularly scans the
268.Pa /var/db/spamd
269database and configures all whitelist addresses as the
270.Xr pf 4
271<spamd-white>
272table,
273allowing connections to pass to the real MTA.
274Any addresses not found in
275<spamd-white>
276are redirected to
277.Nm .
278.Pp
279An example
280.Xr pf.conf 5
281fragment is given below.
282In the example, the file
283.Pa /etc/mail/nospamd
284contains addresses of hosts who should be passed directly
285to the SMTP agent (thus bypassing
286.Nm ) .
287.Bd -literal -offset 4n
288table \*(Ltspamd-white\*(Gt persist
289table \*(Ltnospamd\*(Gt persist file "/etc/mail/nospamd"
290pass in on egress proto tcp from any to any port smtp \e
291    rdr-to 127.0.0.1 port spamd
292pass in on egress proto tcp from \*(Ltnospamd\*(Gt to any port smtp
293pass in log on egress proto tcp from \*(Ltspamd-white\*(Gt to any port smtp
294pass out log on egress proto tcp to any port smtp
295.Ed
296.Pp
297.Nm
298removes tuple entries from the
299.Pa /var/db/spamd
300database if delivery has not been retried within
301.Em greyexp
302hours from the initial time a connection is seen.
303The default is 4 hours as this is the most common setting after which
304MTAs will give up attempting to retry delivery of a message.
305.Pp
306.Nm
307removes whitelist entries from the
308.Pa /var/db/spamd
309database if no mail delivery activity has been seen from the
310whitelisted address by
311.Xr spamlogd 8
312within
313.Em whiteexp
314hours from the initial time an address
315is whitelisted.
316The default is 36 days to allow for the delivery of
317monthly mailing list digests without greylist delays every time.
318.Pp
319.Xr spamd-setup 8
320should be run periodically by
321.Xr cron 8 .
322When run in blacklist-only mode,
323the
324.Fl b
325flag should be specified.
326Use
327.Xr crontab 1
328to uncomment the entry in root's crontab.
329.Pp
330.Xr spamlogd 8
331should be used to update the whitelist entries in
332.Pa /var/db/spamd
333when connections are seen to pass to the real MTA on the
334.Em smtp
335port.
336.Pp
337.Xr spamdb 8
338can be used to examine and alter the contents of
339.Pa /var/db/spamd .
340See
341.Xr spamdb 8
342for further information.
343.Pp
344.Nm
345sends log messages to
346.Xr syslogd 8
347using
348.Em facility
349daemon and, with increasing verbosity,
350.Em level
351err, warn, info, and debug.
352The following
353.Xr syslog.conf 5
354section can be used to log connection details to a dedicated file:
355.Bd -literal -offset indent
356!spamd
357daemon.info	/var/log/spamd
358.Ed
359.Pp
360A typical entry shows the time of the connection and
361the IP address of the connecting host.
362When a host connects,
363the total number of active connections and
364the number of connections from blacklisted hosts is shown
365.Pq connected (xx/xx) .
366When a host disconnects,
367the amount of time spent talking to
368.Nm
369is shown.
370.Sh GREYTRAPPING
371When running
372.Nm
373in default mode,
374it may be useful to define
375.Em spamtrap
376destination addresses to catch spammers as they send mail from greylisted
377hosts.
378Such spamtrap addresses affect only greylisted connections to
379.Nm
380and are used to temporarily blacklist a host that is obviously sending spam.
381Unused email addresses or email addresses on spammers' lists are very
382useful for this.
383When a host that is currently greylisted attempts to send mail to a
384spamtrap address,
385it is blacklisted for 24 hours by adding the host to the
386.Nm
387blacklist
388<spamd-greytrap>.
389Spamtrap addresses are added to the
390.Pa /var/db/spamd
391database with the following
392.Xr spamdb 8
393command:
394.Pp
395.Dl # spamdb -T -a 'spamtrap@mydomain.org'
396.Pp
397See
398.Xr spamdb 8
399for further details.
400.Pp
401The file
402.Pa /etc/mail/spamd.alloweddomains
403can be used to specify a list of domainname suffixes, one per line, one of
404which must match each destination email address in the greylist.
405Any destination address which does not match one of the suffixes listed in
406.Pa spamd.alloweddomains
407will be trapped, exactly as if it were sent to a spamtrap address.
408Comment lines beginning with
409.Sq #
410and empty lines are ignored.
411.Pp
412For example, if
413.Pa spamd.alloweddomains
414contains:
415.Bd -literal -offset indent
416@humpingforjesus.com
417obtuse.com
418.Ed
419.Pp
420The following destination addresses
421.Em would not
422cause the sending host to be trapped:
423.Bd -literal -offset indent
424beardedclams@humpingforjesus.com
425beck@obtuse.com
426beck@snouts.obtuse.com
427.Ed
428.Pp
429However the following addresses
430.Em would
431cause the sending host to be trapped:
432.Bd -literal -offset indent
433peter@apostles.humpingforjesus.com
434bigbutts@bofh.ucs.ualberta.ca
435.Ed
436.Pp
437A low priority MX IP address may be specified with the
438.Fl M
439option.
440When
441.Nm
442has such an address specified, no host may enter new greylist
443tuples when connecting to this address; only existing entries
444may be updated.
445Any host attempting to make new deliveries to
446the low priority MX for which a tuple has not previously
447been seen will be trapped.
448.Pp
449Note that it is important to ensure that a host running
450.Nm
451with the low priority MX address active must see all the greylist
452changes for a higher priority MX host for the same domains.
453This is best done by the host itself receiving the connections to
454the higher priority MX on another IP address (which may be an IP alias).
455This will ensure that hosts are not trapped erroneously if the higher
456priority MX is unavailable.
457For example, on a host which is an existing MX record for a domain of
458value 10, a second IP address with MX of value 99 (a higher number, and
459therefore lower priority) would ensure that any RFC conformant client
460would attempt delivery to the IP address with the MX value of 10
461first, and should not attempt to deliver to the address with MX value 99.
462.Sh BLACKLIST-ONLY MODE
463When running in default mode, the
464.Xr pf.conf 5
465rules described above are sufficient.
466However when running in blacklist-only mode,
467a slightly modified
468.Xr pf.conf 5
469ruleset is required,
470redirecting any addresses found in the
471<spamd>
472table to
473.Nm .
474Any other addresses
475are passed to the real MTA.
476.Bd -literal -offset 4n
477table \*(Ltspamd\*(Gt persist
478pass in on egress proto tcp from \*(Ltspamd\*(Gt to any port smtp \e
479    rdr-to 127.0.0.1 port spamd
480.Ed
481.Pp
482Addresses can be loaded into the
483.Em table ,
484like:
485.Bd -literal -offset 4n
486# pfctl -q -t spamd -T replace -f /usr/local/share/spammers
487.Ed
488.Pp
489.Xr spamd-setup 8
490can also be used to load addresses into the
491<spamd>
492table.
493It has the added benefit of being able to remove addresses from
494blacklists, and will connect to
495.Nm
496over a localhost socket, giving
497.Nm
498information about each source of blacklist addresses, as well as custom
499rejection messages for each blacklist source
500that can be used to let any real person whose mail
501is deferred by
502.Nm
503know why their address has been listed
504from sending mail.
505This is important as it allows legitimate mail
506senders to pressure spam sources into behaving properly so that they
507may be removed from the relevant blacklists.
508.Sh CONFIGURATION CONNECTIONS
509.Nm
510listens for configuration connections on the port identified by the
511named service
512.Dq spamd-cfg
513(see
514.Xr services 5 ) .
515The configuration socket listens only on the INADDR_LOOPBACK
516address.
517Configuration of spamd is done by connecting to the configuration
518socket, and sending blacklist information, one blacklist per line.
519Each blacklist consists of a name, a message to reject mail
520with, and addresses in CIDR format, all separated by semicolons (;):
521.Bd -literal -offset indent
522tag;"rejection message";aaa.bbb.ccc.ddd/mm;aaa.bbb.ccc.ddd/mm
523.Ed
524.Pp
525The rejection message must be inside double quotes.
526A \e" will produce a double quote in the output.
527\en will produce a newline.
528%A will expand to the connecting IP address in dotted quad format.
529%% may be used to produce a single % in the output.
530\e\e will produce a single \e.
531.Nm
532will reject mail by displaying all the messages from all blacklists in which
533a connecting address is matched.
534.Xr spamd-setup 8
535is normally used to configure this information.
536.Sh SYNCHRONISATION
537.Nm
538supports realtime synchronisation of spamd databases between
539a number of spamd
540daemons running on multiple machines,
541using the
542.Fl Y
543and
544.Fl y
545options.
546The databases are synchronised for greylisted and trapped entries;
547whitelisted entries and entries made manually using
548.Xr spamdb 8
549are not updated.
550.Pp
551The following example will accept incoming multicast and unicast
552synchronisation messages, and send outgoing multicast messages through
553the network interface
554.Ar em0 :
555.Bd -literal -offset indent
556# /usr/libexec/spamd -y em0 -Y em0
557.Ed
558.Pp
559The second example will increase the multicast TTL to a value of 2,
560add the unicast targets
561.Ar foo.somewhere.org
562and
563.Ar bar.somewhere.org ,
564and accept incoming unicast messages received on
565.Ar bge0
566only.
567.Bd -literal -offset indent
568# /usr/libexec/spamd -y bge0 -Y em0:2 \e
569	-Y foo.somewhere.org -Y bar.somewhere.org
570.Ed
571.Pp
572If the file
573.Pa /etc/mail/spamd.key
574exists,
575.Nm
576will calculate the message-digest fingerprint (checksum) for the file
577and use it as a shared key to authenticate the synchronisation messages.
578The file itself can contain any data.
579For example, to create a secure random key:
580.Bd -literal -offset indent
581# dd if=/dev/random of=/etc/mail/spamd.key bs=2048 count=1
582.Ed
583.Pp
584The file needs to be copied to all hosts
585sending or receiving synchronisation messages.
586.Sh FILES
587.Bl -tag -width "/etc/mail/spamd.alloweddomainsXX" -compact
588.It /etc/mail/spamd.alloweddomains
589Required suffixes for greytrapping.
590.It /etc/mail/spamd.conf
591Default configuration file.
592.It /etc/mail/spamd.key
593Authentication key for synchronisation messages.
594.It /var/db/spamd
595Greylisting database.
596.El
597.Sh SEE ALSO
598.Xr pf.conf 5 ,
599.Xr services 5 ,
600.Xr spamd.conf 5 ,
601.Xr syslog.conf 5 ,
602.Xr pfctl 8 ,
603.Xr spamd-setup 8 ,
604.Xr spamdb 8 ,
605.Xr spamlogd 8 ,
606.Xr syslogd 8
607.Sh HISTORY
608The
609.Nm
610command first appeared in
611.Ox 3.3 .
612.Sh BUGS
613.Nm
614currently uses the user
615.Dq _spamd
616outside a chroot jail when running in default mode, and requires
617the greylisting database in
618.Pa /var/db/spamd
619to be owned by the
620.Dq _spamd
621user.
622This is wrong and should change to a distinct user from the
623one used by the chrooted
624.Nm
625process.
626