SQLGrey - Greylisting Improvements with SPF\DNSWL
Posted: 03 Oct 2015 20:31
Hi Guys,
I just want to share something i implemented on my system with greylisting,
first, i most say that greylisting is great! and you all should use it because spammers, hackers etc.. rarely send the mails 2 times in X intervals
they have no real MTA doing the work for them.. and if they have one and your greylisting is set to higher waiting value,
30 minutes for instance.. and you're using RBLs queries.. you can trust that in those 30 minutes they will be listed and
when they try to come again, their window is closed!
but there is also the delays, greylisting may kill your enemies but it can also injure your allies,
and this may delay your win in battle.
until fully operated database of the dynamic white-listing by SQLGrey we will suffer delays,
the first idea here is to eliminate delays for those we can trust,
and also deny spoofers from getting in.
so, how to achieve this?
pretty simple... SPF!
since SPF becoming more and more usable by companies and others, i thought to myself..
if the sender-domain publish SPF and the IP that send the mail is authorized we know for sure that this
mail is not coming from spam-bot, open relay, etc., but from a legitimate mail system,
so why delay him?
and by saying this, we can have another advantage..
if the sender-domain using restrictive SPF (with the -all signed) it mean that ONLY the IPs/domain
represented in their SPF is allowed to send emails on-behalf of their domain,
so way not deny IPs that try to pretend as they come from that domain at the postfix\greylisting (MTA) level?
with simple DNS query i'm keeping the message out from hitting Greylisting database,
MailScanner rules.. SpamAssassin.. Virus Scan..
saving me processing throughput, CPU, Memory.. etc.
Another technic i implemented was the use of DNSWL.org,
i like to use it as another method to avoid greylisting, but you can disable it if you like.
its rule is that if the client IP is listed in DNSWL for that sender-domain
and it have low\med\high reputation we will allow him to pass greylisting,
if it has "no-trust" reputation we send him to the greylist database.
ok, first download the file and overwrite it,
be sure you are using sqlgrey 1.8.0 because i modified this file,
i'm not related to the developers team so if you're using other version you may want to consider..
check version:
[root@efa ~]# sqlgrey --version
sqlgrey 1.8.0
if it's 1.8.0 we good to go, else.. well you do it at your own risk.
run:
cd /usr/sbin
curl https://transfer.sh/ajZVN/sqlgrey > sqlgrey
now add to /etc/sqlgrey/sqlgrey.conf those lines:
vi /etc/sqlgrey/sqlgrey.conf
spf_autowhitelist = 1
dnswl_autowhitelist = 1
#dnswl_reject_unauthorized = 1
replace sqlgrey-check_policy_service order in /etc/postfix/main.cf
so you don't have those queries on your trusted network IPs,
take "check_policy_service inet:127.0.0.1:2501" out from smtpd_recipient_restrictions
and put it in smtpd_client_restrictions with permit_mynetworks like this:
smtpd_client_restrictions = permit_sasl_authenticated, permit_mynetworks, check_policy_service inet:127.0.0.1:2501
restart the services:
service sqlgrey restart
service postfix restart
you can disable those checks anytime, for now, leave dnswl_reject_unauthorized commented (with '#'),
its not RFC compliance, it means that if the IP is listed on DNSWL for a different
domain it will be rejected at the MTA level, its like an SPF perspective but the IT guys
not ready yet to take DNSWL seriously, so lots of mail servers have relaying servers
delivering the mails for them, if an IP is listed for the sender-domain, sqlgrey will let him pass greylisting..
if the IP is listed for other domain, it still ok but without SPF we greylist the suspect.
ok, the script calculation is this:
SPF Pass = immediately allow him to pass greylisting.
SPF Fail = reject message: "senderdomain.com using restrictive SPF policy and i don't see your name on it!"
SPF None,Neutral,SoftFail - Message will be greylisting.
DNSWL: only if SPF result is None,Neutral,SoftFail DNSWL will make it's query,
DNSWL - Pass - relaying IP matches the domain in DNSWL list and have low\med\high reputation = immediately allow him to pass greylisting.
DNSWL - Fail - relaying IP NOT matches the domain in DNSWL list = dnswl_reject_unauthorized action (greylist default).
now we can make reconnect_delay with high value like 30 or even 60 minutes,
and lowering the awl_age value for like 20 days, making greylisting more efficient..
you can trust that your greylisting database also be empty if you swim on the big pool.
check X-Greylist or /var/log/maillog results to know how sqlgrey deal with the incoming mails..
and by the way, it's highly recommended to run\configure unbound as a recursive and caching DNS that already shipped with the EFA
to minimize DNS queries.
Good luck,
Zohman.
I just want to share something i implemented on my system with greylisting,
first, i most say that greylisting is great! and you all should use it because spammers, hackers etc.. rarely send the mails 2 times in X intervals
they have no real MTA doing the work for them.. and if they have one and your greylisting is set to higher waiting value,
30 minutes for instance.. and you're using RBLs queries.. you can trust that in those 30 minutes they will be listed and
when they try to come again, their window is closed!
but there is also the delays, greylisting may kill your enemies but it can also injure your allies,
and this may delay your win in battle.
until fully operated database of the dynamic white-listing by SQLGrey we will suffer delays,
the first idea here is to eliminate delays for those we can trust,
and also deny spoofers from getting in.
so, how to achieve this?
pretty simple... SPF!
since SPF becoming more and more usable by companies and others, i thought to myself..
if the sender-domain publish SPF and the IP that send the mail is authorized we know for sure that this
mail is not coming from spam-bot, open relay, etc., but from a legitimate mail system,
so why delay him?
and by saying this, we can have another advantage..
if the sender-domain using restrictive SPF (with the -all signed) it mean that ONLY the IPs/domain
represented in their SPF is allowed to send emails on-behalf of their domain,
so way not deny IPs that try to pretend as they come from that domain at the postfix\greylisting (MTA) level?
with simple DNS query i'm keeping the message out from hitting Greylisting database,
MailScanner rules.. SpamAssassin.. Virus Scan..
saving me processing throughput, CPU, Memory.. etc.
Another technic i implemented was the use of DNSWL.org,
i like to use it as another method to avoid greylisting, but you can disable it if you like.
its rule is that if the client IP is listed in DNSWL for that sender-domain
and it have low\med\high reputation we will allow him to pass greylisting,
if it has "no-trust" reputation we send him to the greylist database.
ok, first download the file and overwrite it,
be sure you are using sqlgrey 1.8.0 because i modified this file,
i'm not related to the developers team so if you're using other version you may want to consider..
check version:
[root@efa ~]# sqlgrey --version
sqlgrey 1.8.0
if it's 1.8.0 we good to go, else.. well you do it at your own risk.
run:
cd /usr/sbin
curl https://transfer.sh/ajZVN/sqlgrey > sqlgrey
now add to /etc/sqlgrey/sqlgrey.conf those lines:
vi /etc/sqlgrey/sqlgrey.conf
spf_autowhitelist = 1
dnswl_autowhitelist = 1
#dnswl_reject_unauthorized = 1
replace sqlgrey-check_policy_service order in /etc/postfix/main.cf
so you don't have those queries on your trusted network IPs,
take "check_policy_service inet:127.0.0.1:2501" out from smtpd_recipient_restrictions
and put it in smtpd_client_restrictions with permit_mynetworks like this:
smtpd_client_restrictions = permit_sasl_authenticated, permit_mynetworks, check_policy_service inet:127.0.0.1:2501
restart the services:
service sqlgrey restart
service postfix restart
you can disable those checks anytime, for now, leave dnswl_reject_unauthorized commented (with '#'),
its not RFC compliance, it means that if the IP is listed on DNSWL for a different
domain it will be rejected at the MTA level, its like an SPF perspective but the IT guys
not ready yet to take DNSWL seriously, so lots of mail servers have relaying servers
delivering the mails for them, if an IP is listed for the sender-domain, sqlgrey will let him pass greylisting..
if the IP is listed for other domain, it still ok but without SPF we greylist the suspect.
ok, the script calculation is this:
SPF Pass = immediately allow him to pass greylisting.
SPF Fail = reject message: "senderdomain.com using restrictive SPF policy and i don't see your name on it!"
SPF None,Neutral,SoftFail - Message will be greylisting.
DNSWL: only if SPF result is None,Neutral,SoftFail DNSWL will make it's query,
DNSWL - Pass - relaying IP matches the domain in DNSWL list and have low\med\high reputation = immediately allow him to pass greylisting.
DNSWL - Fail - relaying IP NOT matches the domain in DNSWL list = dnswl_reject_unauthorized action (greylist default).
now we can make reconnect_delay with high value like 30 or even 60 minutes,
and lowering the awl_age value for like 20 days, making greylisting more efficient..
you can trust that your greylisting database also be empty if you swim on the big pool.
check X-Greylist or /var/log/maillog results to know how sqlgrey deal with the incoming mails..
and by the way, it's highly recommended to run\configure unbound as a recursive and caching DNS that already shipped with the EFA
to minimize DNS queries.
Good luck,
Zohman.