You are on page 1of 3

Amavisd-new COVER STORY

Filtering spam and viruses at the mail server with Amavisd-new

SCAN MANAGER

Deutsche Post WorldNet


Sometimes the best time to stop bad mail is before it arrives. Amavisd-

new is an Open Source interface for integrating spam and virus filtering
a daemonized set of master and child
with your mail server. BY LARKIN CUNNINGHAM processes. Amavisd-new acts as an SMTP
server, receiving email messages from
your SMTP server (e.g., Postfix, exim, or
qmail), processing the messages, and

T
he majority of viruses are propa- duces the risk of spam and viruses sending them or reinjecting them back
gated via email. While it is still reaching your desktop. An additional ad- into your SMTP server.
possible to receive viruses from vantage of providing this extra layer of Amavisd-new supports anti-spam
floppy disks and CD-ROMs, or from In- protection is that, by using a virus tools such as SpamAssasin [2], as well
ternet worms and rootkits that directly checker on your desktop that is different as a wide range of commercial and open
attack vulnerabilities in your operating from the content checker on your SMTP source virus checkers. The popular Clam
system, you are much more likely to re- server, you reduce the risk of a virus Antivirus [3] is supported in three ways;
ceive viruses via email – often by inad- passing undetected. the clamd daemon (the best perfor-
vertently opening seemingly innocent Amavisd-new [1] is an Open Source mance), the Mail::ClamAV Perl package
attachments. tool that serves as an interface from a (not so good performance) and the clam-
Of course it is important to have an mail server to virus scanners and other scan command line option (as a backup
up-to-date virus checker on your desk- forms of content checkers. Although when clamd is unavailable, for exam-
top, but defense in depth is the best ap- some virus tools provide their own ple). Many other popular virus checkers
proach, and this is why you should be mechanisms for filtering mail at the are also supported, including F-Prot,
protected from spam and viruses at your server, Amavisd-new offers performance Sophos, Grisoft’s AVG, KasperskyLab
receiving SMTP server. Virus protection advantages in some environments, and AVP, AntiVir, F-Secure, McAfee and
at the mail server prevents undesirable it also provides a single, vendor-neutral Panda. But be aware of the licensing for
email from reaching your desktop, and it configuration point for managing both the product you choose. Obviously
also keeps viruses out of your POP3 or virus and spam filtering. ClamAV will not incur any license fee,
IMAP account. Filtering from the mail but some of the other options may have
server reduces the load on your desktop High Performance a license fee for an SMTP server that is
PC or laptop, reduces the amount of Amavisd-new is a flexible, high perfor- significantly greater than the desktop li-
bandwidth you will use, and greatly re- mance Perl-based application that runs as cense fee.

W W W. L I N U X - M A G A Z I N E . C O M ISSUE 62 JANUARY 2006 35


COVER STORY Amavisd-new

You can configure Amavisd-new to bases are also sup-


block attachments with commonly dan- ported, including
gerous extensions, such as .exe, .bat, Oracle and DB2.
and .vbs (particularly dangerous to Win- Be aware that
dows clients who may be using the mail many of the tables
server.) You can also specify a wide have serial / se-
range of decoders/decompressors to ex- quence primary
amine archives such as .cpio, .rpm, .deb, keys, so for Ora-
. zoo, .tar, .gz, and .bz2. cle, you’ll need to
Amavisd-new can theoretically sup- add several se-
port any SMTP server, but it works bet- quences and trig-
ter with the usual suspects, including gers in addition to
Sendmail, exim, and qmail. Amavisd- the tables.
new works best with Postfix [4], which You must spec-
can reinject mail back into itself after ify two DSNs
content filtering. Figure 1: Amavisd-new is just one big Perl script. (Data Source
Names). One DSN
Installation Requirements you have set up the background applica- is for lookups and the other for storage
To install Amavisd-new, you need a tions, the installation is relatively straight- (logging). You can improve performance
working Perl installation. Perl 5.8.2 or forward. Amavisd-new does not require by using a database that is very fast for
greater is recommended. Though earlier the compilation of any code, since it uses read-only access to do lookups and a da-
versions of Perl will work, later versions the Perl interpreter. tabase that is fast for writes for storage.
work better. You need to install a num- Amavisd-new also lets you specify multi-
ber of Perl packages (Table 1). Be sure to Configuring Amavisd-new ple DSNs to allow for failover.
update any packages you already have to with SQL
the latest versions. There are several ways to configure Policies
Obviously, for effective spam filtering, Amavisd-new. You can define your Ama- If you are familiar with firewall configura-
the latest Mail::SpamAssassin package visd-new configuration using the ama- tion, you will be familiar with the term
should be installed. Spammers attempt visd.conf file, lists files, hash lookup policy. A firewall policy is a set of instruc-
to stay one step ahead of SpamAssassin, files, regular expressions, and LDAP or tions to a firewall specifying what to do
so you should always update the SQL lookups. with certain types of network traffic. For
SpamAssassin package as soon as a new The SQL solution offers you the most example, a firewall policy might specify
version becomes available. freedom to build a front-end configura- whether to block traffic to a certain net-
You should also install a number of ad- tion tool using a scripting language such work port or whether to redirect traffic
ditional programs to allow for the widest as PHP. You can use any database that from one port to a different port. An
range of decoding and decompressing of supports standard SQL and is supported Amavisd-new policy is similar. With each
email attachments. These additional pro- by Perl DBD/DBI libraries. SQL DDL policy, you can direct Amavisd-new to
grams include gzip, bzip2, arc, lha, rar, (Data Definition Language) is provided bypass spam checking or virus filtering,
zoo, pax, cpio, freeze, ripole, cabextract, in the README.sql file to create tables, be tougher or more lenient with spam,
and many others. See the Amavisd-new indexes, and some sample data. tag the spam email’s subject line with a
website [1] for more on installation. After Notes are included for MySQL, Post- marker (like {Spam?}), and forward all
greSQL, and SQLite. Many other data- spam to a designated spam account.
Table 1: Required Perl
Packages Table 2: Some of the options in the policy table
Archive::Tar virus_lover Do not reject the email even if virus infected
Archive::Zip spam_lover Do not reject the email even if identified as spam
Compress::Zlib Note: The _lover options do not tell Amavisd-new not to scan, just to ignore the results of the scan.
Convert::TNEF bypass_virus_checks Do not scan the email for viruses
Convert::UUlib bypass_spam_checks Do not scan the email for spam and do not add the X-Spam headers
MIME::Base64 spam_modifies_subj Add some text (a tag) to the beginning of the subject if it is spam
MIME::Parser virus_quarantine_to An email account to send all virus infected emails to
Mail::Internet spam_quarantine_to An email account to send all spam to
Net::Server spam_tag_level The SpamAssassin score above which spam emails get X-Spam headers
Net::SMTP spam_tag2_level The SpamAssassin score above which spam gets the subject tagged
Digest::MD5 spam_kill_level The SpamAssassin score above which ‘evasive’ action is taken, determined
IO::Stringy by $final_spam_destiny in the configuration file (default is to discard the
Time::HiRes email, i.e. Send it to a blackhole)
Unix::Syslog spam_subject_tag The text to use for the spam tag (see spam_modifies_subj)
BerkeleyDB spam_subject_tag2 The text to use for the high scoring spam tag

36 ISSUE 62 JANUARY 2006 W W W. L I N U X - M A G A Z I N E . C O M


Amavisd-new COVER STORY

Black or white listed emails are added to


Logging and the Law the mailaddr table with a unique identi-
A hot topic for ISPs at the moment is a fier. The rows in the wblist table specify
potential requirement to store email the email address and target user to
data for up to three years. This is in re-
which the rule applies.
sponse to recent terrorist atrocities and
is designed to give law enforcement
agencies information to track the activi-
Logging and Archiving
ties of terrorists, in addition to telephone One of the newer features of Amavisd-
and mobile phone call and SMS logs. new is the ability to log all email activity.
While storing email content would inevi- The logging information is comprehen-
tably lead to a massive storage burden sive and includes information such as
for ISPs, the archiving of the logging in- senders, recipients, times, dates, sub-
formation generated by Amavisd-new jects, and spam or virus scores. Logging Figure 2: Amavisd-new provides detailed
could address many of the requirements lets you keep accurate statistics on the logging information that allows for informa-
of any future European or local govern- level of clean versus spam versus virus tive charts.
ment legislation.
emails received. The fact that you can
record these statistics at the user level taking a look at the Postfix and Amavisd-
Each email domain or user can have gives the system administrator an oppor- new combination. Particularly for ISPs,
its own policy. You can specify a policy tunity to see where content checking re- there is an imperative to providing cus-
to cover all email accounts within a do- sources are most needed. This gives an tomers with spam and virus filtering,
main and also decide to have additional ISP (Internet Service Provider) the op- whether it is free or as an add-on to their
policies for individual email accounts portunity to bill for bandwidth, process- service.
within the same domain. For example, ing time, the number of messages pro- Growing levels of spam and viruses
you might have a default policy to cover cessed, or the number of spam or virus and greater numbers of customers are
all users in a domain (like a catch-all emails processed. putting a strain on the infrastructure of
policy), but perhaps Tom’s email ac- many ISPs. An open source solution
count is being flooded with spam. An in- Conclusion using Postfix and Amavisd-new could be
dividual policy for Tom’s account could For those who are considering building a the answer. Both Postfix and Amavisd-
have a lower tolerance. Table 2 details robust and scalable architecture for bat- new can be configured to use MySQL,
just some of the policy options. tling spam and viruses, I recommend PostgreSQL, or Oracle for retrieving data.
A user table allows you to assign poli- It is possible to have a central database
cies to specific domains and individual Administration and accessed by multiple Postfix and Ama-
email accounts. The user table’s email Statistics Made Easy visd-new servers. And it is possible to
field determines whether multiple email employ multiple databases, allowing for
Using a database instead of configura-
accounts or just a single email account tion files allows for easy administration.
greater fault tolerance. By using a num-
will be affected by the policy. For exam- The database option also allows for dy- ber of failover techniques, including
ple, the email @domain.com refers to all namic updating of configuration data configuration of DSN records, it is possi-
email accounts in the domain.com do- without having to reload the Amavisd- ble to build a scalable, fully fault toler-
main. But, tom@domain.com refers to a new daemons. The same is true if you ant, and load balanced infrastructure. ■
single email address. If both @domain. opt to configure your Postfix users and
com and tom@domain.com exist in the domains in a SQL database. By query- INFO
users table, precedence is given to the ing the storage database using SQL, it is
[1] Amavisd-new:
specific email address. easy to garner useful information on
http://www.ijs.si/software/amavisd/
spam and virus statistics. You could
[2] SpamAssassin:
achieve this using phpMyAdmin, for ex-
Black and White Listing http://spamassassin.apache.org
ample, if MySQL is the chosen database.
When important emails you want to re- [3] Clam Antivirus:
An ISP with a large number of custom- http://www.clamav.net
ceive continually get blocked because
ers could develop an interface that
they are identified as spam, you can take [4] Postfix SMTP Server:
would allow customers to update their http://www.postfix.org
action to ensure that the sender of the own policies to be more or less aggres-
emails is exempt from spam checking by sive against spam or viruses. It would
adding them to the white list. Con- also allow users to view statistics on the Larkin Cunningham is an IT Consul-
versely, when you continually receive
THE AUTHOR

levels of clean, spam, and virus infected tant specializing in the areas of
spam from a source you know is a spam- emails. These types of statistics can only Linux Administration, Java, Applica-
mer, you can add the email address to help in the education of email users. Fig- tion Frameworks, Oracle and just
the blacklist. ure 2 shows an example of the type of about anything in the open source
Amavisd-new’s black and white lists statistics you can easily present to cus- community that makes the lives of
tomers. The example was developed IT Managers easier and Finance Di-
work by cross referencing the mailaddr
using ColdFusion MX 7, but you could rectors happier. He can be contacted
(email address) table with the user table
also use PHP with jpGraph. at larkin.cunningham@gmail.com.
and the wblist (white / black list) table.

W W W. L I N U X - M A G A Z I N E . C O M ISSUE 62 JANUARY 2006 37

You might also like