http://isg.ee.ethz.ch/tools/postgrey/
Anyone running amavisd-new will have this stuff, but just in case:
- Code: Select all
yum install perl-Net-Server perl-IO-Multiplex perl-BerkeleyDB perl-Net-DNS
visit:
http://www.lfarkas.org/linux/packages/
and see if a more appropriate rpm can be found (although since this is a Perl program
there may not be much difference) and change the download location as needed (also change
the version if needed):
- Code: Select all
cd /usr/local/src
wget http://www.lfarkas.org/linux/packages/fc4/i386/RPMS/postgrey-1.27-0.noarch.rpm
rpm -Uvh postgrey-1.27-0.noarch.rpm
If you run Postfix chrooted:
- Code: Select all
cp /etc/passwd /var/spool/postfix/etc/passwd
You will find some whitelist files here:
/etc/postfix/postgrey_whitelist_clients
/etc/postfix/postgrey_whitelist_clients.local
/etc/postfix/postgrey_whitelist_recipients
- Code: Select all
vi /etc/rc.d/init.d/postgrey
OPTIONS="--unix=$SOCKET"
to:
OPTIONS="--unix=$SOCKET --inet=127.0.0.1:60000 --delay=29"
save and exit. Notice I greylist for only 29 seconds.
Then start Postgrey
- Code: Select all
/etc/rc.d/init.d/postgrey start
and check that it is listening on port 60000:
- Code: Select all
lsof | grep postgrey | grep LISTEN
for more info: 'perldoc postgrey'
We are going to set up greylisting such that it attempts to only
greylist certain clients hopefully avoiding greylisting clients
likely to be mainstream servers.
- Code: Select all
vi /etc/postfix/check_client_fqdn
and insert:
- Code: Select all
/^unknown$/ greylist
/^[^\.]*[0-9][^0-9\.]+[0-9]/ greylist
/^[^\.]*[0-9]{5}/ greylist
/^([^\.]+\.)?[0-9][^\.]*\.[^\.]+\..+\.[a-z]/ greylist
/^[^\.]*[0-9]\.[^\.]*[0-9]-[0-9]/ greylist
/^[^\.]*[0-9]\.[^\.]*[0-9]\.[^\.]+\..+\./ greylist
/^(dhcp|dialup|ppp|adsl)[^\.]*[0-9]/ greylist
- Code: Select all
vi /etc/postfix/main.cf
(if you aleady have something in smtpd_restriction_classes
then you would add greylist to the list)
smtpd_restriction_classes = greylist
greylist = check_policy_service inet:127.0.0.1:60000
At The Very Bottom of smtpd_recipient_restrictions add:
check_client_access regexp:/etc/postfix/check_client_fqdn
This example shows both policyd-weight and postgrey selective greylisting:
- Code: Select all
smtpd_recipient_restrictions =
permit_mynetworks,
reject_unauth_destination,
reject_unlisted_recipient,
reject_unauth_pipelining,
check_recipient_access hash:/etc/postfix/polw_recipient_exceptions,
check_client_access hash:/etc/postfix/polw_client_exceptions,
check_sender_access hash:/etc/postfix/polw_sender_exceptions,
check_policy_service inet:127.0.0.1:12525,
check_client_access regexp:/etc/postfix/check_client_fqdn
- Code: Select all
postfix reload
Remember that reject_unlisted_recipient can be used to reject mail to invalid recipients
quicker than smtpd_reject_unlisted _recipient (which would reject after greylisting).
However, it is required that you do in fact have a list of valid recipients for your
address class (such as relay_recipient_maps would be used with the relay_domains
address class). See:
http://www.postfix.org/postconf.5.html#smtpd_reject_unlisted_recipient
http://www.postfix.org/postconf.5.html#relay_recipient_maps
If you know in advance which senders/clients/recipients you never want greylisted
you can OK them in one of the polw_*_exceptions maps - but be aware of what would
happen if you were to place other restrictions after these access maps.
- Code: Select all
tail -f /var/log/maillog
Jan 25 21:01:09 sfa postfix/policydweight[2383]: weighted check: NOT_IN_SBL_XBL_SPAMHAUS=-1.5
NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_NE_HELO=1.5 RESOLVED_IP_IS_NOT_HELO=1.5
(check from: .example. - helo: .wyrsck. - helo-domain: .wyrsck.)
FROM_NOT_FAILED_HELO(DOMAIN)=3 <client=192.168.1.41> <helo=wyrsck>
<from=garyv@example.com> <to=garyv@example.com>, rate: 1.5
Jan 25 21:01:09 sfa postfix/policydweight[2383]: decided action=DUNNO
NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_NE_HELO=1.5
RESOLVED_IP_IS_NOT_HELO=1.5 (check from: .example. - helo: .wyrsck.
- helo-domain: .wyrsck.) FROM_NOT_FAILED_HELO(DOMAIN)=3 <client=192.168.1.41>
<helo=wyrsck> <from=garyv@example.com> <to=garyv@example.com>, rate: 1.5
Jan 25 21:01:09 sfa postfix/smtpd[2379]: NOQUEUE: reject: RCPT from unknown[192.168.1.41]:
450 <unknown[192.168.1.41]>: Client host rejected: Greylisted, see
http://isg.ee.ethz.ch/tools/postgrey/he ... .com.html; from=<garyv@example.com>
to=<garyv@example.com> proto=ESMTP helo=<wyrsck>
A couple minutes later I tried again:
Jan 25 21:04:03 sfa postfix/policydweight[2383]: decided action=DUNNO
using cached result; rate: 1.5
Jan 25 21:04:03 sfa postgrey[2303]: delayed 174 seconds: client=192.168.1.41,
from=garyv@example.com, to=garyv@example.com
Jan 25 21:04:04 sfa postfix/smtpd[2396]: 134C07EE4D: client=unknown[192.168.1.41]
and I could send mail.
I'm not sure if logwatch will complain.
This is a lifesaver for a system in trouble.
In master.cf one might also consider lowering this setting from a default of 50:
- Code: Select all
smtp inet n - n - - smtpd
-o smtpd_client_connection_count_limit=21
Personally I have only seen dictionary attacks exceed this, but your situation may be different, so please test.


