|
this translation is deprecated - please click BACK and compare the translation with the 'Updated version of Original Article' for updates. Sorry to all that I haven't had the time to translate the newest copies...
Postfix + Amavisd-New/ClamAV + DSPAM, Mailfilter Gateway
1. Pendahuluan
Peringatan:
- Dokumentasi ini hanya cocok untuk DSPAM versi 3.x.x
- Contoh installasi dan konfigurasi dijalankan di lingkungan linux Gentoo. Kemungkinan besar letak file
konfigurasi dan beberapa perintah tidak cocok untuk linux distro lain (atau sistem operasi lain), perlu ada
penyesuaian
- Dokumen ini lebih ditekankan pada konfigurasi postfix + dspam, untuk postfixnya sendiri anda dianggap telah memahami dengan baik.
|
Catatan:
- Tulisan ini lebih bersifat penyesuaian (karena adanya konfigurasi baru) untuk DSPAM versi 3.x.x.
- Tulisan yang membahas DSPAM versi 2.10.x masih bisa dilihat di sini.
|
Skenario
Semua email masuk/keluar, di relay melalui mailfilter gateway. Selanjutnya mailfilter gateway akan
melakukan proses scanning virus, dan pengklasifikasian spam.
Email yang diidentifikasi mengandung virus akan dikarantina (tidak dikirimkan ke backend server). Sedangkan
email yang diidentifikasi tidak mengandung virus, akan diproses oleh aplikasi antispam utk pengklasifikasian
spam/non-spam. Setelah proses pengklasifikasian selesai, semua email (baik spam atau non-spam), akan dikirim
ke backend server. Selanjutnya email yang sampai di backend server akan diteruskan ke mailbox user.
Ketika email sudah dikirimkan ke server backend maka tuntaslah sudah tugas si mailfilter gateway tsb. Proses pemisahan email spam dan non-spam sepenuhnya diserahkan ke server backend (yang mengelola mailbox user), atau bisa diserahkan ke masing-masing user, melalui fitur filtering di MUA-nya masing-masing (outlook, eudora, horde, pine dsb).
Kira-kira kalau digambarkan pemrosesan email di mailfilter gateway, sebelum email dikirim ke mailbox user, adalah sebagai berikut:
| Virus-Free mail |
> |
Postfix SMTP Server |
> |
smtp-amavis localhost:10024 |
> |
dspam localhost:10025 |
> |
Postfix queue |
> |
SMTP Backend Server |
| Virus-Infected mail |
> |
Postfix SMTP Server |
> |
smtp-amavis localhost:10024 |
> |
localhost:10026 |
> |
Drop mail ke quarantine folder |
> |
Kirim notifikasi ke virus-admin (juga ke pengirim jika dirasa perlu) |
Persiapan
Pastikan backend server sudah berjalan dengan baik (bisa mengirim dan menerima email dengan baik). MTA yang
digunakan di backend server terserah anda, tergantung selera dan kebutuhan. Bisa qmail, postfix, exim 3/4, ms
exchange, kombinasi qmail/vpopmail, qmail/vmailmgr dsb. Pada prinsipnya mailfilter gateway bisa dipasang
sebagai frontend untuk existing mailserver (apapun MTA-nya).
Selanjutnya install postfix di server yang terpisah dari existing mailserver anda. Pastikan postfix
berfungsi dengan baik. Server ini akan kita jadikan sebagai maifilter gateway. Aplikasi tambahan yang perlu
terinstall di server ini adalah mysql server (untuk keperluan dspam).
2. Installasi dan Konfigurasi ClamAV
Installasi
Code listing 2.1 |
# emerge clamav
|
Konfigurasi
Konfigurasi untuk clamav tidak banyak dan sederhana.
Code listing 2.2: /etc/clamav.conf |
LogFile /tmp/clamd.log
LogFileMaxSize 2M
LogTime
LogSyslog
PidFile /var/run/clamd.pid
DatabaseDirectory /var/lib/clamav
LocalSocket /var/run/clamav/clamd
MaxThreads 10
ReadTimeout 300
MaxDirectoryRecursion 15
User clamav
AllowSupplementaryGroups
ScanOLE2
ScanArchive
ArchiveMaxFileSize 10M
ArchiveMaxRecursion 5
ArchiveMaxFiles 1000
ArchiveMaxCompressionRatio 200
|
Kita harus memastikan bahwa database ClamAV selalu up2date, sehingga virus-virus terbaru pun bisa tetap dikenali. Pastikan freshclam (program untuk mengupdate databases ClamAV) bisa berjalan dengan baik.
Code listing 2.3: /etc/freshclam.conf |
HTTPProxyServer proxy.example.com
HTTPProxyPort 3128
|
Setting jg /etc/conf.d/clamd
Code listing 2.4: /etc/conf.d/clamd |
START_CLAMD=yes
CLAMD_OPTS=""
CLAMD_LOG=""
START_FRESHCLAM=yes
FRESHCLAM_OPTS="-d -c 2"
FRESHCLAM_LOG="/var/log/clam-update.log"
|
Selanjutnya jalankan daemon clamd, freshclam dan pastikan kedua program tersebut akan
dijalankan ketika booting.
Code listing 2.5 |
# mkdir /var/run/clamav
# chown clamav:clamav /var/run/clamav
# /etc/init.d/clamd start
# rc-update add clamd default
|
3. Installasi dan Konfigurasi Amavisd-New
Installasi
Code listing 3.1 |
# emerge amavisd-new
|
Catatan:
emerge otomatis menginstall dependancy yang diperlukan.
Kalau menginstall dari source, setidaknya beberapa modul perl berikut harus sudah terinstall:
Archive::Tar (Archive-Tar-x.xx)
Archive::Zip (Archive-Zip-x.xx)
Compress::Zlib (Compress-Zlib-x.xx)
Convert::TNEF (Convert-TNEF-x.xx)
Convert::UUlib (Convert-UUlib-x.xxx)
MIME::Base64 (MIME-Base64-x.xx)
MIME::Parser (MIME-Tools-x.xxxx)
Mail::Internet (MailTools-1.58 or later have workarounds for Perl 5.8.0 bugs)
Net::Server (Net-Server-x.xx)
Net::SMTP (libnet-x.xx) (use libnet-1.16 or latter for performance)
Digest::MD5 (Digest-MD5-x.xx)
IO::Stringy (IO-stringy-x.xxx)
Time::HiRes (Time-HiRes-x.xx) (use 1.49 or later, some older cause
problems)
Unix::Syslog (Unix-Syslog-x.xxx)
Beberapa program archiver jg diperlukan, seperti unzip, unarj dsb (bisa dilihat di
/etc/amavisd.conf)
|
Konfigurasi
Kita bisa membaca file /etc/amavisd.conf, dan mengkonfigurasi sesuai kebutuhan. Tapi minimal kita
harus mengkonfigurasi beberapa hal berikut.
Code listing 3.2: /etc/amavisd.conf |
$MYHOME = '/var/amavis'
$mydomain = 'example.com'; (sesuaikan dengan domain anda)
$daemon_user = 'clamav';
$daemon_group = 'clamav';
$forward_method = 'smtp:127.0.0.1:10025';
$notify_method = 'smtp:127.0.0.1:10026';
@bypass_spam_checks_acl = qw( . );
$virus_admin = "admin\@example.com";
$QUARANTINEDIR = '/var/virusmails';
['Clam Antivirus-clamd',
\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd"],
qr/\bOK$/, qr/\bFOUND$/,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],
|
Direktori yang didefinisikan harus dibuat dan set owner/permissionnya dengan tepat
Code listing 3.3 |
# mkdir /var/amavis
# chown clamav:clamav /var/amavis
# chmod 750 /var/amavis
# mkdir /var/virusmails
# chown clamav:clamav /var/virusmails
|
Jalankan amavisd-new dan pastikan akan dijalankan ketika booting.
Code listing 3.4 |
# /etc/init.d/amavisd start
# rc-update add amavisd default
|
4. Installasi dan Konfigurasi DSPAM
Installasi
Khusus utk DSPAM, diinstall dari source, karena tidak ada didalam portage. Source diambil dari
http://www.nuclearelephant.com/projects/dspam/
Code listing 4.1 |
# mkdir /root/sources
# cd /root/sources
# wget http://www.nuclearelephant.com/projects/dspam/sources/dspam-3.0.0.rc2.tar.gz
# tar zxvf dspam-3.0.0.rc2.tar.gz
# cd dspam-3.0.0.rc2
|
Buat user dspam
Code listing 4.2 |
# adduser -d /var/dspam -s /bin/false dspam
|
Baca file ddspam-3.0.0.rc2/README, sesuai skenario konfigurasi yang digunakan adalah sebagai
berikut
Code listing 4.3 |
#./configure \
--with-dspam-home=/var/dspam \
--with-dspam-home-owner=dspam \
--with-dspam-home-group=postdrop \
--with-dspam-owner=dspam \
--with-dspam-group=postdrop \
--with-dspam-mode=4510 \
--with-delivery-agent=/usr/sbin/sendmail \
--with-storage-driver=mysql_drv \
--with-mysql-includes=/usr/include/mysql \
--with-mysql-libraries=/usr/lib/mysql \
--disable-trusted-user-security \
--enable-large-scale \
--enable-virtual-users \
--enable-long-usernames \
--enable-opt-in \
--enable-spam-subject
# make
# make install
|
Buat databases dspam di mysql. Dan setup konfigurasi mysql.
Code listing 4.4 |
# mysql -u root -pPASSWORDMYSQL -e "create database dspam"
# mysql -u root -pPASSWORDMYSQL -e "grant all on dspam.* to dspam@localhost identified by 'DSPAMPASS'"
# mysql -u dspam -pDSPAMPASS dspam < tools.mysql_drv/mysql_objects.sql.speed.optimized
# mysql -u dspam -pDSPAMPASS dspam < tools.mysql_drv/virtual_users.sql
# cp tools.mysql_drv/purge.sql /var/dspam
|
Code listing 4.5: /var/dspam/mysql.data |
/var/run/mysqld/mysqld.sock (atau mungkin /tmp/mysqld.sock)
dspam
DSPAMPASS
dspam
|
Code listing 4.6 |
# chown dspam:postdrop /var/dspam/msyql.data
# chmod 440 /var/dspam/mysql.data
|
Jalankan program maintenance database dspam (purge.sql) sehari sekali dari crontab. Program ini akan menghapus token yang sudah kadaluwarsa. Supaya database tidak terus membengkak :D
Code listing 4.7: /etc/crontab |
0 0 * * * dspam /usr/bin/mysql -u dspam -p'DSPAMPASS' dspam < /var/dspam/purge.sql
|
5. Konfigurasi tambahan untuk postfix
Postfix yang sudah terinstall (dan berjalan dengan baik), perlu sedikit diubah konfigurasinya.
Code listing 5.1: /etc/postfix/master.cf |
smtp inet n - n - - smtpd
-o content_filter=smtp-amavis:[127.0.0.1]:10024
smtp-amavis unix - - n - 2 lmtp
-o smtp_send_xforward_command=yes
127.0.0.1:10025 inet n - n - - smtpd
-o cleanup_service_name=pre-cleanup
-o content_filter=dspam:dummy
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
127.0.0.1:10026 inet n - n - - smtpd
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
dspam unix - n n - - pipe
flags=Rhq user=dspam argv=/usr/local/bin/dspam --mode=teft --deliver=innocent,spam
--feature=chained,noise -i -f ${sender} -- %u --user ${recipient}
cleanup unix n - n - 0 cleanup
-o header_checks=
-o mime_header_checks=
-o nested_header_checks=
-o body_checks=
pre-cleanup unix n - n - 0 cleanup
-o canonical_maps=
-o sender_canonical_maps=
-o recipient_canonical_maps=
-o masquerade_domains=
-o virtual_alias_maps=
-o always_bcc=
-o sender_bcc_maps=
-o recipient_bcc_maps=
local unix - n n - - local
-o content_filter=
-o myhostname=localhost
-o local_recipient_maps=
-o relay_recipient_maps=
-o mynetworks=127.0.0.0/8
-o mynetworks_style=host
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
dspam-add unix - n n - - pipe
flags=Rhq user=dspam argv=/usr/local/bin/dspam --mode=teft --user ${user}@${nexthop} --class=spam --source=error
dspam-fp unix - n n - - pipe
flags=Rhq user=dspam argv=/usr/local/bin/dspam --mode=teft --user ${user}@${nexthop} --class=innocent --source=error
|
Code listing 5.2: /etc/postfix/main.cf |
relay_domains = $mydestination example.com
transport_maps = regexp:/etc/postfix/transport_regexp,
hash:/etc/postfix/transport.domain
dspam_destination_recipient_limit = 1
dspam-add_destination_recipient_limit = 1
dspam-fp_destination_recipient_limit = 1
|
Untuk proses training spam atau false-positive email ke dspam. Dengan regexp + konfigurasi di master.cf
(dspam-add/dspam-fp). Kita tidak perlu mensetup alias peruser. Semua email yang diidentifikasikan sbg spam,
dikirim ke user@addspam.example.com. Dan email false-positive, dikirim ke user@fp.example.com. Tentu DNS
addspam.example.com dan fp.example.com, harus ditujukan ke ip mailfilter gateway.
Code listing 5.3: /etc/postfix/transport_regexp |
/^.*@addspam.(.*)$/ dspam-add:${1}
/^.*@fp.(.*)$/ dspam-fp:${1}
|
Arahkan email ke smtp backend server
Code listing 5.4: /etc/postfix/transport.domain |
example.com smtp:xyz.xyz.xyz.xyz
|
Code listing 5.5 |
# postmap /etc/postfix/transport.domain
# postfix reload
|
6. Finishing
Contoh Konfigurasi utk per-user procmailrc
Code listing 6.1: ~user/.procmailrc |
VERBOSE=off
MAILDIR=$HOME/mail
:0 H
* ^X-DSPAM-Result: Spam
SPAM
|
Setting Primary MX record domain
Code listing 6.2: db-example.com. |
example.com. IN MX 10 mailgateway.example.com.
mailgateway IN A mailgateway.ip.add.here
addspam IN CNAME mailgateway
fp IN CNAME mailgateway
mail IN A mail.ip.add.here
|
Setting MTA backend server
Set outgoing mail agar direlay ke mailfilter gateway.
Mentraining DSPAM
Setiap email yang anda kategorikan sebagai spam, anda dikirimkan ke alamat
user@addspam.example.com. Jika ada false-positive (email bukan spam, tapi dikategorikan oleh dspam sebagai spam),
forward email tersebut ke alamat user@fp.exampe.com. Sedikit demi sedikit, dspam akan semakin faham mana email yang anda kategorikan sebagai spam dan mana yang bukan spam.
Setiap user bebas mengkategorikan email seperti apa yang dia kategorikan sebagai spam dan mana yang bukan. Karena mungkin saja, menurut user A, email ini spam, dan untuk user B, dengan email yang identik, menurutnya itu bukan spam.
Catatan: Berdasarkan pengalaman (tentunya pengalaman saya pribadi :D), dengan mentraining kurang lebih 100 email, akurasi dari dspam sudah cukup baik.
|
Penting: Email yang dikirim ke user@addspam.example.com adalah email yang kita kategorikan sebagai spam, dan lolos dari spam filter. Yang ditangkep oleh spam filter akan mempunyai header X-DSPAM-Result: Spam. Sebaiknya anda setting email anda agar memisahkan SPAM ke folder lain (misalnya menggunakan procmail seperti yg saya contohkan diatas) |
Untuk mempercepat proses training, kita bisa memanfaatkan email yang sudah kita pilah-pilah sebagai spam/non-spam (misalnya hasil dari spamassassin) dan mengimportnya ke dspam. Cocok untuk membuat databases account yang akan di set sebagai global classification user.
Dari website dspam, kita bisa mendownload email yang dimaksud diatas. Di sana ditulis sebagai SA-Training-Corpus.
Code listing 6.3 |
# cd /root/sources
# wget http://www.nuclearelephant.com/projects/dspam/SA-Corpus.tar.gz
# tar zxvf SA-Corpus.tar.gz
# cd SA-Corpus
# ./train.pl user@example.com
|
Catatan: Perlu dibuatkan file SA-Corpus.tar.gz yang serupa, untuk email-email berbahasa Indonesia. Ada yang beminat? |
7. Mensetup CGI Client
DSPAM cgi, harus dijalankan sebagai user dspam (dan bukan user apache) supaya bisa mengakses file /var/dspam (yang owner-nya user dspam). Untuk keperluan tersebut, saya set file wrapper, sebelumnya saya ganti semua file cgi aslinya menjadi FILE_orig.cgi.
Catatan:
Ini bukan satu-satunya cara, bisa saja anda setup virtual host dan set suexec user utk virtual host tsb.
|
Code listing 7.1: /root/sources/suexec.sh |
cp -Rp /root/sources/dspam-3.0.0.rc2/cgi /var/www/localhost/htdocs/dspam
cd /var/www/localhost/htdocs/dspam
for a in *.cgi; do
echo "#!/bin/sh" > `basename $a .cgi`.tmp
echo "exec /usr/sbin/suexec2 dspam users ./`basename $a .cgi`_orig.cgi" >> `basename $a .cgi`.tmp
done
for b in *.cgi; do
mv $b `basename $b .cgi`_orig.cgi
done
for c in *.tmp; do
mv $c `basename $c .tmp`.cgi
done
chown -R dspam:users /var/www/localhost/htdocs/dspam
chmod 755 /var/www/localhost/htdocs/dspam
chmod 755 /var/www/localhost/htdocs/dspam/*.cgi
cat << HTACCESS > .htaccess
Options ExecCGI
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/dspam.auth
Require valid-user
HTACCESS
|
Set user/password
Code listing 7.2 |
htpasswd2 -c /etc/dspam.auth user@example.com
|
Jangan lupa edit file /var/www/localhost/htdocs/dspam/dspam_orig.cgi pada bagian berikut:
Code listing 7.3: /var/www/localhost/htdocs/dspam/dspam_orig.cgi |
$CONFIG{'LARGE_SCALE'} = 1; # --enable-large-scale
|
DSPAM cgi, memerlukan paket dev-perl/GD-Graph3d
Code listing 7.4 |
emerge -p GD-Graph3d
|
Setelah semuanya selesai, anda bisa mengaksesnya melalui URL (misalnya dspam cgi disimpan di web localhost) http://localhost/dspam/dspam.cgi
Figure 7.1: proses autentikasi |
 |
Figure 7.2: tampilan dspam cgi |
 |
8. Referensi
9. Revisi ...
| Versi |
Tgl/Bln/Thn |
Keterangan |
| 1.0 |
05/06/2004 |
* Tulisan pertama untuk DSPAM versi 3.x.x
|
The contents of this document are licensed under the Creative Commons - Attribution / Share Alike license.
Copyright 2004. Cecep Mahbub. Questions, comments, corrections are welcome.
|