This is an old revision of the document!
Table of Contents
Exim4 - Access Control
Exim allows you to apply access control lists at various points of the SMTP transaction by specifying an ACL to use and defining its conditions in exim.conf.
HELO checking
You could start with the HELO string.
# Specify the ACL to use after HELO acl_smtp_helo = check_helo # Conditions for the check_helo ACL: check_helo: deny message = Gave HELO/EHLO as "friend" log_message = HELO/EHLO friend condition = ${if eq {$sender_helo_name}{friend} {yes}{no}} deny message = Gave HELO/EHLO as our IP address log_message = HELO/EHLO our IP address condition = ${if eq {$sender_helo_name}{$interface_address} {yes}{no}} accept
WARNING: Pursue HELO checking at your own peril. The HELO is fairly unimportant in the grand scheme of SMTP these days, so don't put too much faith in whatever it contains. Some spam might seem to use a telltale HELO string, but you might be surprised at how many legitimate messages start off with a questionable HELO as well. Anyway, it's just as easy for a spammer to send a proper HELO than it is to send HELO im.a.spammer, so consider yourself lucky if you're able to stop much spam this way.
HELO checking
Often spammers send for the HELO argument the name or the IP of your host. Here my own domain is “sharewiz.net” and my own IP is 5.42.134.35.
acl_check_helo: accept hosts = +own_hosts # If the HELO pretend to be this host deny condition = ${if or { \ {eq {${lc:$sender_helo_name}}{sharewiz.net}} \ {eq {${lc:$sender_helo_name}}{5.42.134.35}} \ } {true}{false} } # by default we accept accept
Remote host IP checking
Allow connections from our own hosts and a white-list (Some hosts from big internet providers) with no more check. We refuse connections with some hosts.
acl_check_host: accept hosts = +own_hosts : /etc/exim4/filters/host_white.list deny log_message = match host_reject.list hosts = /etc/exim4/filters/host_reject.list accept
Remote host IP checking by DNS black-list
Hosts listed by the dns list sbl-xbl.spamhaus.org are spammers or relays for spams. Often if you refuse the connection for one of these hosts then a new try is done by another relay some seconds later. A better solution is to do the rejection when the RCPT is received. Then the spammer does not try again.
acl_check_rcpt: . . . drop log_message = match sbl-xbl.spamhaus.org dnslists = sbl-xbl.spamhaus.org
Sender checking
To refuse some senders.
acl_check_sender: deny senders = /etc/exim4/filters/sender_reject.list accept
Sender Address or Remote Host ACL
You can perform a check on the sender address or remote host. This shows how to do that after the RCPT TO command; if you reject here, as opposed to rejecting after the MAIL FROM, you'll have better data to log, such as who the message was intended for.
# Specify the ACL to use after RCPT TO acl_smtp_rcpt = check_recipient # Conditions for the check_recipient ACL check_recipient: # [...] drop hosts = /etc/exim_reject_hosts drop senders = /etc/exim_reject_senders # [ Probably a whole lot more... ]
This example uses two plain text files as blacklists. Add appropriate entries to these files - hostnames/IP addresses to /etc/exim_reject_hosts, addresses to /etc/exim_reject_senders, one entry per line.
Recipient: no hack
(From /usr/share/doc/exim4-doc-html/html/C043.txt.gz):
Deny if the local part contains @ or % or / or | or !. These are rarely found in genuine local parts, but are often tried by people looking to circumvent relaying restrictions.
Also deny if the local part starts with a dot. Empty components aren't strictly legal in RFC 2822, but Exim allows them because this is common. However, actually starting with a dot may cause trouble if the local part is used as a file name (e.g. for a mailing list).
acl_check_rcpt: . . . # refuse if the recipient string is a hack, # see exim file example C043.txt.gz deny local_parts = ^.*[@%!/|] : ^\\.
Recipient: emails addresses to catch spams
You can publish a sacrified email address in a web page to trap spammers (some spammers crawl other web pages to get emails). When this email address matches then an error is returned and all the message reception is dropped. There are changes that the spammer software will not retry with this recipient removed.
When you write to a suspicious company wich could send you spam or when you write in a newsgroup, you can use a special email, with date (like echant-td-n040531@sharewiz.net) or with an included identifier (like echant-tr-lemonde@sharewiz.net). Then if you receive spam for this email you can put it in the drop list (in this example: /etc/exim4/filters/recipients_drop.list).
acl_check_rcpt: . . . drop log_message = match recipients_drop.list. recipients = /etc/exim4/filters/recipients_drop.list
I use this script in cron.daily/ to update my emails with a date incorporated. The letter before the date is used to trace the origin (web, news, email).
- /etc/cron.daily/email-date-sharewiz
#!/bin/bash # # Update my email to include todays date. set -e T=$(tempfile) D=$(date '+%y%m%d') function mod_file { EMAIL="$1" LETTRE="$2" CONF="$3" if [ -f "$CONF" -a -r "$CONF" ]; then lockfile-create "$CONF" sed "s/${EMAIL}-td-${LETTRE}[0-9]\{6\}@sharewiz.net/${EMAIL}-td-${LETTRE}${D}@sharewiz.net/g" <"$CONF" >"$T" cp "$T" "$CONF" lockfile-remove "$CONF" fi } # The first line will replace echant-td-n040625@sharewiz.net # with echant-td-n040626@sharewiz.net mod_file echant n /home/john/.kde/share/config/knoderc mod_file echant e /home/john/.sylpheed/accountrc mod_file echant e /home/john/.initvar # For apache we should reload but it is done by # logrotate from time to time. mod_file echant w /etc/apache-extern/httpd.conf rm $T
Content ACL
It is also possible to perform content scanning using a regex against the body of a message, though obviously this can cause Exim to use more CPU than it otherwise would need to, especially on large messages.
# Specify the ACL to use after DATA acl_smtp_data = check_message # Conditions for the check_messages ACL check_message: deny message = "Sorry, Charlie: $regex_match_string" regex = ^Subject:: .*Lower your self-esteem by becoming a sysadmin accept