Difference between revisions of "Blok Spam Menggunakan Postfix dan Bogofilter"

From OnnoWiki
Jump to navigation Jump to search
(New page: install postfix apt-get install postfix install bogofilter apt-get install bogofilter What: This document describes how to use bogofilter to filter mail that passes through a post...)
 
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
install postfix
+
Disini akan di terangkan cara menggunakan bogofilter untuk mem-filter [[e-mail]] yang melalui [[postfix]].
  
apt-get install postfix
+
==Teori==
  
install bogofilter
+
Kita akan mensetup bogofilter di [[mail server]] dan akan mem-filter semua mail yang masuk.
 +
Ada beberapa keuntungan yang akan di peroleh karena hal tersebut, yaitu:
  
apt-get install bogofilter
+
# Pengguna [[e-mail]] non-unix / non-linux akan memperoleh keuntungan dari bogofilter.
 +
# Bogofilter akan belajar banyak karena akan memperoleh akses ke corpus yang sangat besar.
  
What:
+
Di samping itu, juga ada mekanisme bagi pengguna untuk mendaftarkan message spam baru / non-spam termasuk memperbaiki klasifikasi yang salah.
  
This document describes how to use bogofilter to filter mail that
+
==Asumsi==
passes through a postfix mail server.
 
  
Theory:
+
* Langkah yang di terangkan disini membutuhkan privilege sebagai root.
 +
* Postfix di install di /usr. Jika kita menginstall dari repo kemungkinan akan berada disitu. Kalau kita menginstall menggunakan [[source code]] maka kemungkinan akan ada di /usr/local/
 +
* Bogofilter di install di /usr/bin/bogofilter di mail server.
  
The idea is to setup bogofilter on the mail server and have it filter
+
==Instalasi==
all incoming mail.
 
  
There are several advantages to doing so:
+
instalasi postfix
  
  1. Mail users on non-Unix platforms will benefit from bogofilter spam
+
  apt-get install postfix
    filtering.
 
2. bogofilter learns better since it has access to a larger corpus.
 
  
There is also a mechanism for users to register new spam/non-spam
+
instalsi bogofilter
messages, as well as correcting misclassifications.
 
  
Assumptions:
+
apt-get install bogofilter
  
- Most of the steps described here require root privileges.
+
beri training bogofilter
- postfix is installed into /usr. If you installed postfix
 
  from rpm, it is probably installed there. If you installed from
 
  source, it is installed into /usr/local unless you changed its
 
  configuration.
 
- bogofilter is installed in /usr/bin/bogofilter on the mail server.
 
  
Installation:
+
mkdir /home/bogofilter
 +
touch /home/bogofilter/wordlist.db
 +
chmod -Rf 777 /home/bogofilter/wordlist.db
 +
cd /home/bogofilter
 +
bogofilter -d /home/bogofilter -M -s < spam.mbx
 +
bogofilter -d /home/bogofilter -M -n < nonspam.mbx
  
- Build the initial spam and non-spam databases by feeding your corpus of mail.
+
==Melakukan Filter==
  
  Assuming there are two files in mbox format in /home/bogofilter, you say:
+
* Buat script untuk menjalankan bogofilter, misalnya /home/bogofilter/postfix-filter.sh yang berisi
  
  # cd /home/bogofilter
+
mkdir /home/bogofilter
  # bogofilter -d . -s < spam.mbx
+
vi /home/bogofilter/postfix-filter.sh
  # bogofilter -d . -n < nonspam.mbx
 
Filtering:
 
  
- Create a script to invoke bogofilter, say
+
#!/bin/sh
  /home/bogofilter/postfix-filter.sh, modeled on the following:
+
 +
FILTER=/usr/bin/bogofilter
 +
FILTER_DIR=/home/bogofilter/
 +
# WARNING! The -i is crucial, else you may see
 +
# messages truncated at the first period that is alone on a line
 +
# (which can happen with several kinds of messages, particularly
 +
# quoted-printable)
 +
# -G is ignored before Postfix 2.3 and tells it that the message
 +
# does not originate on the local system (Gateway submission),
 +
# so Postfix avoids some of the local expansions that can leave
 +
# misleading traces in headers, such as local address
 +
# canonicalizations.
 +
POSTFIX="/usr/sbin/sendmail -G -i"
 +
export BOGOFILTER_DIR=/home/bogofilter
 +
 +
# Exit codes from <sysexits.h>
 +
EX_TEMPFAIL=75
 +
EX_UNAVAILABLE=69
 +
 +
cd $FILTER_DIR || \
 +
{ echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; }
 +
 +
# Clean up when done or when aborting.
 +
trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15
 +
 +
# bogofilter -e returns: 0 for OK, nonzero for error
 +
rm -f msg.$$ || exit $EX_TEMPFAIL
 +
$FILTER -p -u -e > msg.$$ || exit $EX_TEMPFAIL
 +
 +
exec <msg.$$ || exit $EX_TEMPFAIL
 +
rm -f msg.$$ # safe, we hold the file descriptor
 +
exec $POSTFIX "$@"
 +
exit $EX_TEMPFAIL
  
        #!/bin/sh
+
* Set supaya script bisa di jalankan! Semoga kumpulan kata-kata yang awal kita masukan ke bogofilter cukup lumayan untuk memberikan training awal. Memang kadang kala akan terjadi kesalahan klasifikasi.Jika terjadi salah klasifikasi maka HARUS dibetulkan kemudian.
  
        FILTER=/usr/bin/bogofilter
+
==Modifikasi /etc/postfix/master.cf==
        FILTER_DIR=/var/spool/filter
 
        # WARNING! The -i is crucial, else you may see
 
        # messages truncated at the first period that is alone on a line
 
        # (which can happen with several kinds of messages, particularly
 
        # quoted-printable)
 
        # -G is ignored before Postfix 2.3 and tells it that the message
 
        # does not originate on the local system (Gateway submission),
 
        # so Postfix avoids some of the local expansions that can leave
 
        # misleading traces in headers, such as local address
 
        # canonicalizations.
 
        POSTFIX="/usr/sbin/sendmail -G -i"
 
        export BOGOFILTER_DIR=/home/bogofilter
 
  
        # Exit codes from <sysexits.h>
+
Modifikasi /etc/postfix/master.cf agar dapat menjalankan filter.
        EX_TEMPFAIL=75
 
        EX_UNAVAILABLE=69
 
  
        cd $FILTER_DIR || \
+
vi /etc/postfix/master.cf
            { echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; }
 
  
        # Clean up when done or when aborting.
+
Setelah kalimat yang berawalan "smtp " dan di akhiri dengan "smtpd" (pastikan ada "d" di akhir!). Tambahkan kalimat berikut, kita perlu meng-ident dengan spasi atau tab:
        trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15
 
  
         # bogofilter -e returns: 0 for OK, nonzero for error
+
         -o content_filter=filter:
        rm -f msg.$$ || exit $EX_TEMPFAIL
 
        $FILTER -p -u -e > msg.$$ || exit $EX_TEMPFAIL
 
  
        exec <msg.$$ || exit $EX_TEMPFAIL
+
Di akhir file, tambahkan dua kalimat berikut
        rm -f msg.$$ # safe, we hold the file descriptor
 
        exec $POSTFIX "$@"
 
        exit $EX_TEMPFAIL
 
  
   Make sure the script is executable!
+
filter   unix  -      n      n      -      -      pipe
 +
  flags=Rq user=filter argv=/home/bogofilter/postfix-filter.sh -f ${sender} -- ${recipient}
  
  Given a good initial corpus, it is better to have bogofilter update
+
Selanjutnya di setiap mail yang masuk akan di tambahkan kalimat header:
  its lists based on the message classification, since it is quite
 
  likely to get it right.  Misclassifications MUST be corrected later.
 
  
- Modify your /etc/postfix/master.cf to run the filter.
+
        X-Bogosity: ...
  
    After the line that starts "smtp " and ends in "smtpd" (don't
+
Sebuah e-mail yang di klasifikasikan oleh bogofilter sebagai spam akan mempunyai header
    confuse it with the one that ends in "smtp", mind the "d"!) and add the
 
    following line, you must indent it with some spaces or tabs:
 
  
            -o content_filter=filter:
+
        X-Bogosity: Spam ...
 
 
    At the end of the file, add the following two lines:
 
  
        filter    unix  -      n      n      -      -      pipe
+
Perlu di catat bahwa nama header bisa di konfigurasi saat compile dan dapat di ubah.
            flags=Rq user=filter argv=/home/bogofilter/postfix-filter.sh -f ${sender} -- ${recipient}
 
  
- Now, every incoming message will have the header line
+
Kita perlu mengedukasi pengguna bagaimana cara memilah spam berdasarkan nilai yang ada di header X-Bogosity.  E-mail spam sebaiknya dimasukan folder / mailbox spam, daripada di delete / di buang.
  
        X-Bogosity: ...
+
==Registrasi dan Koreksi==
  
  added to the headers.
+
Untuk menggunakan external filter di Postfix, kita perlu membuat Unix group di server dengan nama "filter".
  A bogofilter classified spam messages will have the entry:
 
  
        X-Bogosity: Spam ...
+
Selanjutnya, kita dapat membuat account user dengan nama "filter" di server dan menjadi anggota group "filter". Ini akan menjadi account yang tidak mempunyai hak tinggi yang akan digunakan oleh script.
  
  Note that the actual header name is configurable at compile time and
+
adduser --disabled-password --shell /bin/false --disabled-login filter
  may have been changed.
 
  
- Educate your users on how to filter their spam based on the value of
+
Pastikan tidak ada user lain yang menjadi anggota group "filter". Login ke account "filter" sebaiknya di kunci misalnya mengunakan perintah
  the X-Bogosity header.  Spam messages should be diverted to a spam
 
  mailbox, rather than deleted.
 
  
 +
passwd -l filter
  
Registration and Correction:
+
sebaiknya di file /etc/passwd di set agar user "filter" akan memperoleh shell yang salah misalnya /bin/false
  
  To use external filtering with Postfix, create a Unix group on the
+
vi /etc/passwd
  server named "filter".
 
  
  Next, create a user account named "filter" on the server and make it a
+
filter:x:1001:1001:,,,:/home/filter:/bin/false
  member of group "filter".  This will be a least-privileged account
 
  used by the scripts.
 
  
  No other user should belong to group "filter".  Logins for the
+
Atur pengguna agar mengirimkan mail yang salah klasifikasi ke mailbox tertentu dan pastikan agar database di update secara periodik.
  "filter" account should be locked (e. g. 'passwd -l filter' on Linux and
 
  Solaris) and the shell in /etc/passwd should be set to an invalid
 
  shell such as /bin/false.
 
  
  Arrange for users to send misclassified mail to a particular mailbox
+
Jika kita tidak dapat mengatur adanya sambungan yang periodik, hilangkan opsi "-u" dari perintah bogofilter di script dan update database jika di inginkan dengan cara mendaftarkan mail lainnya.
  and make sure that the database is updated regularly.
 
  
  If you cannot arrange for regular corrections, remove the "-u" from
+
Pastikan script dapat di jalankan
  the bogofilter command in the script above, and update the database
 
  as the need arises by registering more mail.
 
  
- Make sure the script is executable
+
# chmod +x /home/bogofilter/postfix-filter.sh
  
        # chmod +x /home/bogofilter/postfix-filter.sh
+
Ubah kepemilikan /home/bogofilter agar dimiliki oleh user "filter"
  
- Change the ownership of /home/bogofilter to the filter user
+
# chown -R filter:filter /home/bogofilter
  
      # chown -R filter:filter /home/bogofilter
+
Selesai!
  
- Done!
+
Penulis:
  
Author:
 
 
  David Relson <relson@osagesoftware.com>
 
  David Relson <relson@osagesoftware.com>
 
  Matthias Andree <matthias.andree@gmx.de>
 
  Matthias Andree <matthias.andree@gmx.de>
 
 
 
  
 
==Pranala Menarik==
 
==Pranala Menarik==
  
 
* [[Teknik Anti Spam]]
 
* [[Teknik Anti Spam]]

Latest revision as of 10:28, 7 January 2011

Disini akan di terangkan cara menggunakan bogofilter untuk mem-filter e-mail yang melalui postfix.

Teori

Kita akan mensetup bogofilter di mail server dan akan mem-filter semua mail yang masuk. Ada beberapa keuntungan yang akan di peroleh karena hal tersebut, yaitu:

  1. Pengguna e-mail non-unix / non-linux akan memperoleh keuntungan dari bogofilter.
  2. Bogofilter akan belajar banyak karena akan memperoleh akses ke corpus yang sangat besar.

Di samping itu, juga ada mekanisme bagi pengguna untuk mendaftarkan message spam baru / non-spam termasuk memperbaiki klasifikasi yang salah.

Asumsi

  • Langkah yang di terangkan disini membutuhkan privilege sebagai root.
  • Postfix di install di /usr. Jika kita menginstall dari repo kemungkinan akan berada disitu. Kalau kita menginstall menggunakan source code maka kemungkinan akan ada di /usr/local/
  • Bogofilter di install di /usr/bin/bogofilter di mail server.

Instalasi

instalasi postfix

apt-get install postfix

instalsi bogofilter

apt-get install bogofilter

beri training bogofilter

mkdir /home/bogofilter
touch /home/bogofilter/wordlist.db 
chmod -Rf 777 /home/bogofilter/wordlist.db 
cd /home/bogofilter
bogofilter -d /home/bogofilter -M -s < spam.mbx
bogofilter -d /home/bogofilter -M -n < nonspam.mbx

Melakukan Filter

  • Buat script untuk menjalankan bogofilter, misalnya /home/bogofilter/postfix-filter.sh yang berisi
mkdir /home/bogofilter
vi /home/bogofilter/postfix-filter.sh
#!/bin/sh

FILTER=/usr/bin/bogofilter
FILTER_DIR=/home/bogofilter/
# WARNING! The -i is crucial, else you may see
# messages truncated at the first period that is alone on a line
# (which can happen with several kinds of messages, particularly
# quoted-printable)
# -G is ignored before Postfix 2.3 and tells it that the message
# does not originate on the local system (Gateway submission),
# so Postfix avoids some of the local expansions that can leave
# misleading traces in headers, such as local address
# canonicalizations.
POSTFIX="/usr/sbin/sendmail -G -i"
export BOGOFILTER_DIR=/home/bogofilter

# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69

cd $FILTER_DIR || \
{ echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; }

# Clean up when done or when aborting.
trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15

# bogofilter -e returns: 0 for OK, nonzero for error
rm -f msg.$$ || exit $EX_TEMPFAIL
$FILTER -p -u -e > msg.$$ || exit $EX_TEMPFAIL

exec <msg.$$ || exit $EX_TEMPFAIL
rm -f msg.$$ # safe, we hold the file descriptor
exec $POSTFIX "$@"
exit $EX_TEMPFAIL
  • Set supaya script bisa di jalankan! Semoga kumpulan kata-kata yang awal kita masukan ke bogofilter cukup lumayan untuk memberikan training awal. Memang kadang kala akan terjadi kesalahan klasifikasi.Jika terjadi salah klasifikasi maka HARUS dibetulkan kemudian.

Modifikasi /etc/postfix/master.cf

Modifikasi /etc/postfix/master.cf agar dapat menjalankan filter.

vi /etc/postfix/master.cf

Setelah kalimat yang berawalan "smtp " dan di akhiri dengan "smtpd" (pastikan ada "d" di akhir!). Tambahkan kalimat berikut, kita perlu meng-ident dengan spasi atau tab:

       -o content_filter=filter:

Di akhir file, tambahkan dua kalimat berikut

filter    unix  -       n       n       -       -       pipe
  flags=Rq user=filter argv=/home/bogofilter/postfix-filter.sh -f ${sender} -- ${recipient}

Selanjutnya di setiap mail yang masuk akan di tambahkan kalimat header:

       X-Bogosity: ...

Sebuah e-mail yang di klasifikasikan oleh bogofilter sebagai spam akan mempunyai header

       X-Bogosity: Spam ...

Perlu di catat bahwa nama header bisa di konfigurasi saat compile dan dapat di ubah.

Kita perlu mengedukasi pengguna bagaimana cara memilah spam berdasarkan nilai yang ada di header X-Bogosity. E-mail spam sebaiknya dimasukan folder / mailbox spam, daripada di delete / di buang.

Registrasi dan Koreksi

Untuk menggunakan external filter di Postfix, kita perlu membuat Unix group di server dengan nama "filter".

Selanjutnya, kita dapat membuat account user dengan nama "filter" di server dan menjadi anggota group "filter". Ini akan menjadi account yang tidak mempunyai hak tinggi yang akan digunakan oleh script.

adduser --disabled-password --shell /bin/false --disabled-login filter

Pastikan tidak ada user lain yang menjadi anggota group "filter". Login ke account "filter" sebaiknya di kunci misalnya mengunakan perintah

passwd -l filter

sebaiknya di file /etc/passwd di set agar user "filter" akan memperoleh shell yang salah misalnya /bin/false

vi /etc/passwd
filter:x:1001:1001:,,,:/home/filter:/bin/false

Atur pengguna agar mengirimkan mail yang salah klasifikasi ke mailbox tertentu dan pastikan agar database di update secara periodik.

Jika kita tidak dapat mengatur adanya sambungan yang periodik, hilangkan opsi "-u" dari perintah bogofilter di script dan update database jika di inginkan dengan cara mendaftarkan mail lainnya.

Pastikan script dapat di jalankan

# chmod +x /home/bogofilter/postfix-filter.sh

Ubah kepemilikan /home/bogofilter agar dimiliki oleh user "filter"

# chown -R filter:filter /home/bogofilter

Selesai!

Penulis:

David Relson <relson@osagesoftware.com>
Matthias Andree <matthias.andree@gmx.de>

Pranala Menarik