Spam Filter for Postfix
From NeilDocs
This document is still under construction. Most of this document is a shorter version of [1] written by Patrick Ben Koetter <patrick.koetter@state-of-mind.de> Mark Martinec <Mark.Martinec+amavis@ijs.si>
- Install Software:
- Spamassasin
- amavisd-new
- clamav
- clamav-update
- Edit /etc/sysconfig/freshclam to allow clamav to update
- Edit /etc/freshclam.conf (also to allow clamav to update)
- Create clamd.conf (it doesn't need to have anything in it)
- Edit amavisd.conf, edit or add the following lines:
$inet_socket_port = 10024; # listen on this local TCP port(s) $virus_admin = 'admin@example.com'; # notifications recip
$mailfrom_notify_admin = 'admin@example.com'; # notifications sender $mailfrom_notify_recip = 'admin@example.com'; # notifications sender $mailfrom_notify_spamadmin = 'admin@example.com'; # notifications sender $final_virus_destiny = D_DISCARD; $final_banned_destiny = D_BOUNCE; $final_spam_destiny = D_DISCARD; $final_bad_header_destiny = D_BOUNCE;
- Start services
service amavisd start service clamd.amavisd start service spamassassin start
- Edit master.cf, Add the following lines:
amavisfeed unix - - n - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o smtpd_delay_reject=no
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o smtpd_restriction_classes=
-o mynetworks=127.0.0.0/8
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters
-o local_header_rewrite_clients=
- To check for configuration errors type in
postfix reload && tail -f /var/log/maillog
- Test the connection to amavisd that Postfix will use once configured
$ telnet localhost 10024 220 [127.0.0.1] ESMTP amavisd-new service ready EHLO localhost 250-[127.0.0.1] 250-VRFY 250-PIPELINING 250-SIZE 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250 XFORWARD NAME ADDR PROTO HELO QUIT 221 2.0.0 [127.0.0.1] amavisd-new closing transmission channel
- Test the connection to Postfix that amavisd will use to reinsert messages into the flow of email
$ telnet 127.0.0.1 10025 220 mail.example.com ESMTP Postfix (2.3.2) EHLO localhost 250-mail.example.com 250-PIPELINING 250-SIZE 40960000 250-ETRN 250-STARTTLS 250-AUTH PLAIN CRAM-MD5 LOGIN DIGEST-MD5 250-AUTH=PLAIN CRAM-MD5 LOGIN DIGEST-MD5 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN QUIT 221 2.0.0 Bye
- Test the entire chain:
$ telnet localhost 10024 220 [127.0.0.1] ESMTP amavisd-new service ready HELO localhost 250 [127.0.0.1] MAIL FROM: <> 250 2.1.0 Sender OK RCPT TO: <postmaster> 250 2.1.5 Recipient postmaster OK DATA 354 End data with <CR><LF>.<CR><LF> From: virus-tester To: undisclosed-recipients:; Subject: amavisd test - simple - no spam test pattern
This is a simple test message from the amavisd-new test-messages. . 250 2.6.0 Ok, id=30897-02, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 079474CE44 QUIT 221 2.0.0 [127.0.0.1] amavisd-new closing transmission channel
- Edit main.cf adding the following line:
content_filter=amavisfeed:[127.0.0.1]:10024
- Reload the postfix configuration yet again
postfix reload
- Use the test messages at /usr/share/doc/amavisd-new-2.5.2/test-messages/ to test configuration
- Unzip test messages (you have to use crazy methods because they packaged files that include viruses and they wanted it to be able to passed through firewalls
perl -pe 's/./chr(ord($&)^255)/sge' <sample.tar.gz.compl | zcat | tar xvf -
- Send a valid message
sendmail -i your-address@example.com <sample-nonspam.txt
- Send a spam message
sendmail -i your-address@example.com <sample-spam-GTUBE-junk.txt
- Send a virus message
sendmail -i your-address@example.com <sample-virus-simple.txt
- Verify that the maillog shows valid messages being passed and Spam and Viruses being rejected.
