• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Xin chào ! Nếu đây là lần đầu tiên bạn đến với diễn đàn, xin vui lòng danh ra một phút bấm vào đây để đăng kí và tham gia thảo luận cùng VnPro.

Announcement

Collapse
No announcement yet.

Chống spam bằng SpamAssassin

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Chống spam bằng SpamAssassin

    Chống spam bằng SpamAssassin


    Nội dung
    Giới thiệu
    Cài đặt, cấu hình cơ bản
    Mở rộng, nâng cao
    Tham khảo
    Giới thiệu

    SpamAssassin phát hiện và đánh dấu spam mail bằng cách phân tích thông tin trong header và nội dung mail. SpamAssassin tiêu tốn khá nhiều tài nguyên (cpu, memory, thời gian xử lý) của server, đặc biệt khi phải xử lý những mail có size lớn. Cấu hình để SpamAssassin hoạt động tốt, đồng thời giảm nhẹ sự tiêu tốn tài nguyên cho server là một vấn đề quan trọng.

    Bài viết này giới thiệu cách dùng SpamAssassin và procmail để đánh dấu spam mail cho Postfix server (postfix 2.x). Phương pháp này có những đặc điểm

    ít thay đổi cấu hình mặc định của Postfix (chỉ sửa một dòng trong file main.cf, không thay đổi file master.cf)
    giảm tải cho server bằng cách dùng spamc/spamd (không dùng trực tiếp chương trình spamassassin) và chọn cỡ mail thích hợp
    cho phép mỗi user tự xây dựng quy tắc kiểm tra spam riêng cho mình
    chú ý: ở đây chỉ dùng SpamAssassin để đánh dấu mail. Việc xử lý những mail bị đánh dấu spam (như xóa, phân loại vào hộp thư riêng) được thực hiện ở mail client.
    Bắt đầu viết: tháng 5 năm 2003.
    Thay đổi lần cuối vào lúc: Sun Feb 1 12:47:44 JST 2004.


    Cài đặt và cấu hình


    Mail đến server sẽ được xử lý như sau: postfix → procmail → spamassassin → hộp thư của user.

    Bài viết này giả sử postfix, spamassassin, và procmail đã được cài đặt và hoạt động. Những file cấu hình cần thiết và vị trí của chúng giả sử như sau

    postfix: /etc/postfix/main.cf
    procmail: /etc/procmailrc
    SpamAssassin: /etc/mail/spamassassin/local.cf
    Trước hết, sửa file main.cf để procmail xử lý mail
    ### chỉ cần uncomment (xóa #) dòng này
    mailbox_command = /usr/bin/procmail
    Tiếp đến, tạo một file /etc/procmailrc như sau
    ### tôi thích dùng Maildir
    MAILDIR=$HOME
    DEFAULT=$MAILDIR/Maildir/
    DROPPRIVS=yes

    # spam thường có size nhỏ hơn 10 KiB (10*1024=10240 bytes),
    # kiểm tra những file lớn chỉ làm tốn tài nguyên của server!
    :0fw
    * < 10240
    | /usr/bin/spamc
    Sau đó lập những quy tắc kiểm tra mail cho SpamAssassin. File local.cf ghi những quy tắc chung cho mọi user.
    # thường chỉ nhận mail tiếng Việt, tiếng Anh
    ok_locales vi en
    # ngưỡng spam, nên sử dụng những giá trị từ 5-10
    required_hits 5
    # thay đổi tiêu đề mail nếu là spam
    rewrite_subject 1
    # đánh dấu spam
    subject_tag [*** SPAM ***]

    # với SpamAssassin 3.x: thay thế "rewrite_subject" và "subject_tag" bằng
    # rewrite_header Subject [*** SPAM ***]

    # đây là mail của những người quan trọng,
    # không bao giờ được đánh dấu spam!
    whitelist_from gf@domain-1.name
    whitelist_from *@domain-2.name
    Khởi động SpamAssassin (xem script khởi động phía dưới) với option: SPAMDOPTIONS="-d -c -a -m5", trong đó
    -d: (daemonize) chế độ daemon
    -c: (create-prefs) tạo file cấu hình riêng cho các user
    -a: (auto-whitelist) tự động điều chỉnh whitelist
    -m: (max-children) số process tối đa
    Gõ "man spamd" để xem thêm về các option.

    Sau đây là một ví dụ về script khởi động /etc/init.d/spamassassin (tham khảo từ file của FC1).

    #!/bin/sh
    # spamassassin This script starts and stops the spamd daemon
    #
    # chkconfig: 3 80 30
    #
    # description: spamd is a daemon process which uses SpamAssassin to check
    # email messages for SPAM. It is normally called by spamc
    # from a MDA.

    # Source function library.
    . /etc/rc.d/init.d/functions

    # Source networking configuration.
    . /etc/sysconfig/network

    # Check that networking is up.
    [ ${NETWORKING} = "no" ] && exit 0

    # Source spamd configuration.
    if [ -f /etc/sysconfig/spamassassin ] ; then
    . /etc/sysconfig/spamassassin
    else
    SPAMDOPTIONS="-d -c -a -m5 -H"
    fi

    [ -f /usr/bin/spamd -o -f /usr/local/bin/spamd ] || exit 0
    PATH=$PATH:/usr/bin:/usr/local/bin

    # See how we were called.
    case "$1" in
    start)
    # Start daemon.
    echo -n "Starting spamd: "
    daemon spamd $SPAMDOPTIONS
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/spamassassin
    ;;
    stop)
    # Stop daemons.
    echo -n "Shutting down spamd: "
    killproc spamd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/spamassassin
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    status)
    status spamd
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    esac

    exit 0
    Sau khi khởi động, spamd (spamassassin daemon) sẽ chờ ở cổng 783 của localhost (address 127.0.0.1).
    ### khởi động spamassassin
    /etc/init.d/spamassassin start

    ### kiểm tra bằng nmap
    $ nmap localhost

    ### kết quả nmap
    ...
    783/tcp open hp-alarm-mgr
    ...
    Đến đây kết thúc phần cấu hình. Khởi động lại postfix (lệnh "postfix reload"), gửi thử 1 mail và kiểm tra phần header
    ### đây là ví dụ về header một mail bình thường, không phải spam
    X-Spam-Checker-Version: SpamAssassin ver (YYYY-MM-DD) on ServerName
    X-Spam-Level: *
    X-Spam-Status: No, hits=1.2 required=5.0 tests=xxx autolearn=xxx version=x.yz

    ### đây là ví dụ về header của một spam mail
    X-Spam-Checker-Version: SpamAssassin ver (YYYY-MM-DD) on ServerName
    X-Spam-Level: ******************
    X-Spam-Status: Yes, hits=18.3 required=5.0 tests=FORGED_AOL_HTML,
    FORGED_MUA_AOL_FROM,HTML_90_100,HTML_IMAGE_ONLY_02 ,HTML_MESSAGE,
    MIME_HTML_NO_CHARSET,MIME_HTML_ONLY,MIME_HTML_ONLY _MULTI,
    MISSING_MIMEOLE,MISSING_OUTLOOK_NAME,NO_DNS_FOR_FR OM,RCVD_IN_DSBL,
    RCVD_IN_NJABL,RCVD_IN_NJABL_PROXY,RCVD_IN_SORBS,RC VD_IN_SORBS_HTTP,
    RCVD_IN_SORBS_MISC autolearn=spam version=x.yz
    Tham khảo, thông tin thêm
    1. mẫu thử spam
    2. ví dụ về một spam mail sau khi qua bộ lọc SpamAssassin
    3 http://www.peregrinehw.com/downloads...TALL-RH9-NOTES
    4. tại sao dùng spamc/spamd hiệu quả hơn dùng trực tiếp chương trình spamasassin?

    man spamc: Spamc is the client half of the spamc/spamd pair. It should be used in place of "spamassassin" in scripts to process mail... Spamc has extremely low overhead in loading, so it should be much faster to load than the whole spamassassin program.


    man spamd: The purpose of this program is to provide a daemonized version of the spamassassin executable. The goal is improving throughput performance for automated mail checking. This is intended to be used alongside "spamc", a fast, low-overhead C client program.

    5. Theo cấu hình spamd như trong bài viết này, mỗi user có thể dùng bộ lọc mặc định (là file /etc/mail/spamassassin/local.cf do system admin quản lý), hoặc có thể tự điều chỉnh bộ lọc riêng cho mình nếu không thỏa mãn với cấu hình của bộ lọc mặc định. Cấu hình bộ lọc spam cho user nằm ở file $HOME/.spamassassin/user_prefs

    Mỗi khi kiểm tra mail, spamd sẽ sử dụng bộ lọc user_prefs trước (ưu tiên), nếu không tìm thấy user_prefs, spamd sẽ dùng bộ lọc mặc định local.cf. Những option để cấu hình user_prefs hoàn toàn giống như của local.cf

    6. Xem list tất cả những option của bộ lọc spam ở đây
    Last edited by camaptrang; 26-09-2007, 07:42 AM.

    Hướng dẫn cài đặt cấu hình Data Loss Prevention - MyQLP Appliance (Open Source)


    Hướng dẫn cài đặt và cấu hình Mdeamon 12.x

    Hướng dẫn cài đặt cấu hình ISA 2006 và Exchange 2003 - Mô hình Front-End Back-End

    Cài đặt và cấu hình Cacti - Giám Sát và Quản Lý Hệ Thống Mạng

    Hướng dẫn cài đặt cấu hình Retrospect Backup Server

    Cài đặt và cấu hình phần mềm FSA Audit Files Server

    CAMAPTRANG
    http://www.asterisk.vn

  • #2
    Cho mình hoi ve DSPAM.

    Chao anh camaptrang. Cho minh hoi ve cau hinh DSPAM hay la book ending spam. hehe cam on anh nhieu.

    Comment


    • #4
      Chao,

      That ra SpamAssassin thi dung che rule base (khong tu hoc rule moi, co the setup cach hoc rule moi nhung hoi phuc tap)

      Con DSPAM thi dung co che statistic (thong ke) co the tu dong hoc nhung statistic moi (cach nay hieu qua hon), xem sample config phia duoi.

      Nhung noi tom lai, la ca SpamAssassin hay DSPAM deu khong the han che spam, chi co the danh dau Spam ma thoi, co nghia la Spam mail da enter vo mail server roi, sau do moi duoc filter --> cach nay lam he thong cua ta ton nhieu tai nguyen nhu CPU,RAM,HDD to xu ly ---> khong tot (neu ta phai thue server + duong truyen (tinh theo MB usage)

      Hien gio co nhung cach khac de chong SPAM (o muc SMTP session), nhung check EHLO, senderID, sender IP, sender address, recipeint add, grey_list, RBL,.... cach nay hieu qua hon ---> vi SMTP tu SPAM sender se bi reject truoc khi duoc queue vo mail queue.

      Cac ban co the tham khoa them tren internet, neu can lien he

      Zippo

      DSPAM: cai nay can co MySQL database

      postfix: main.cf
      virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf, hash:/etc/postfix/dspam-transport

      postfix: master.cf
      dspam unix - n n - 5 pipe
      flags=Rhq user=dspam:dspam argv=/usr/local/bin/dspam --client --user $sender --class=$nexthop --source=error

      vi /etc/postfix/dspam-transport
      spam@xxxx.edu.vn dspam:spam
      nonspam@xxxx.edu.vn dspam:innocent

      postmap /etc/postfix/dspam-transport


      DSPAM:

      Download source code and extract

      wget http://dspam.nuclearelephant.com/sou...m-3.6.8.tar.gz
      gunzip dspam-3.6.8.tar.gz
      tar –xvf dspam-3.6.8.tar
      cd dspam-3.6.8


      ./configure --sysconfdir=/etc --with-dspam-home=/var/dspam --enable-domain-scale \
      --with-storage-driver=mysql_drv --enable-daemon \
      --with-mysql-includes=/usr/local/mysql/include/mysql \
      --with-mysql-libraries=/usr/local/mysql/lib/mysql \
      --enable-virtual-users --enable-preferences-extension \
      --enable-daemon \
      --enable-clamav \

      gmake

      vi /etc/dspam.conf

      Home /var/dspam
      StorageDriver /usr/local/lib/libmysql_drv.so
      #TrustedDeliveryAgent
      DeliveryHost 127.0.0.1
      DeliveryPort 10026
      DeliveryIdent localhost
      DeliveryProto SMTP
      ############################################
      Trust root
      Trust dspam
      Trust postfix
      ################# MYSQL Settings ############
      MySQLServer /tmp/mysql.sock
      MySQLUser dspam
      MySQLPass xxxxxxxxxxx
      MySQLDb dspam
      MySQLCompress true
      MySQLConnectionCache 10
      MySQLVirtualTable dspam_virtual_uids
      MySQLVirtualUIDField uid
      MySQLVirtualUsernameField username
      MySQLUIDInSignature on
      SupressWebStats on
      Notifications off
      ParseToHeaders on
      ChangeModeOnParse on
      ChangeUserOnParse auto
      ServerMode auto
      ServerParameters "--deliver=innocent"
      ServerIdent "localhost.localdomain"
      ServerPID /var/run/dspam.pid
      ServerDomainSocketPath "/tmp/dspam.sock"
      ProcessorBias on
      TrainingMode teft
      TestConditionalTraining on
      ImprobabilityDrive off
      Feature chained
      Feature whitelist
      Algorithm graham burton
      PValue graham
      ImprobabilityDrive off
      Preference "spamAction=deliver"
      Preference "signatureLocation=message"
      Preference "showFactors=off"
      AllowOverride trainingMode
      AllowOverride spamAction spamSubject
      AllowOverride statisticalSedation
      AllowOverride enableBNR
      AllowOverride enableWhitelist
      AllowOverride signatureLocation
      AllowOverride showFactors
      AllowOverride optIn optOut
      AllowOverride whitelistThreshold
      HashRecMax 98317
      HashAutoExtend on
      HashMaxExtents 0
      HashExtentSize 49157
      HashMaxSeek 100
      HashConnectionCache 10
      PurgeSignatures 14
      PurgeNeutral 90
      PurgeUnused 90
      PurgeHapaxes 30
      PurgeHits1S 15
      PurgeHits1I 15
      LocalMX 127.0.0.1
      SystemLog off
      UserLog off
      Opt out
      ClamAVPort 3310
      ClamAVHost 127.0.0.1
      ClamAVResponse accept


      mysql –u root -p (if you have set password for MySQL root)
      CREATE database dspam;
      GRANT ALL Privileges on dspam.* to ‘dspam’@’localhost’ \
      IDENTIFIED BY ‘xxxxx’;
      USE dspam;
      create table dspam_token_data (
      uid smallint unsigned not null,
      token char(20) not null,
      spam_hits int not null,
      innocent_hits int not null,
      last_hit date not null
      ) type=MyISAM;

      create unique index id_token_data_01 on dspam_token_data(uid,token);

      create table dspam_signature_data (
      uid smallint unsigned not null,
      signature char(32) not null,
      data blob not null,
      length smallint not null,
      created_on date not null
      ) type=MyISAM;

      create unique index id_signature_data_01 on dspam_signature_data(uid,signature);
      create index id_signature_data_02 on dspam_signature_data(created_on);

      create table dspam_stats (
      uid smallint unsigned primary key,
      spam_learned int not null,
      innocent_learned int not null,
      spam_misclassified int not null,
      innocent_misclassified int not null,
      spam_corpusfed int not null,
      innocent_corpusfed int not null,
      spam_classified int not null,
      innocent_classified int not null
      ) type=MyISAM;

      create table dspam_preferences (
      uid smallint unsigned not null,
      preference varchar(32) not null,
      value varchar(64) not null
      ) type=MyISAM;

      create unique index id_preferences_01 on dspam_preferences(uid, preference);
      create table dspam_virtual_uids (
      uid smallint unsigned primary key AUTO_INCREMENT,
      username varchar(128)
      ) type=MyISAM;
      create unique index id_virtual_uids_01 on dspam_virtual_uids(username);



      Create 2 default DSPAM update accounts

      mysql
      use dsapm;
      INSERT INTO `dspam_virtual_uids` (`uid`, `username`) VALUES \
      (1, 'spam@xxxxx.edu.vn'),
      (2, 'nonspam@xxxx.edu.vn');
      Nguyen Van Hoa
      Phone: 0903-850-225
      email: nvhoa@yahoo.com
      chat: hoarmit

      Comment


      • #5
        Originally posted by Zippo
        Chao,

        That ra SpamAssassin thi dung che rule base (khong tu hoc rule moi, co the setup cach hoc rule moi nhung hoi phuc tap)

        Con DSPAM thi dung co che statistic (thong ke) co the tu dong hoc nhung statistic moi (cach nay hieu qua hon), xem sample config phia duoi.

        Nhung noi tom lai, la ca SpamAssassin hay DSPAM deu khong the han che spam, chi co the danh dau Spam ma thoi, co nghia la Spam mail da enter vo mail server roi, sau do moi duoc filter --> cach nay lam he thong cua ta ton nhieu tai nguyen nhu CPU,RAM,HDD to xu ly ---> khong tot (neu ta phai thue server + duong truyen (tinh theo MB usage)

        Hien gio co nhung cach khac de chong SPAM (o muc SMTP session), nhung check EHLO, senderID, sender IP, sender address, recipeint add, grey_list, RBL,.... cach nay hieu qua hon ---> vi SMTP tu SPAM sender se bi reject truoc khi duoc queue vo mail queue.

        Cac ban co the tham khoa them tren internet, neu can lien he

        Zippo
        Hoàn toàn đồng ý với Zippo, hiii bài viết SpamAssassin đó của James cũng khá lâu rồi, nhưng nếu nhìn nó các bạn mới tiếp cận với Linux hay IT dễ dàng nhìn ra một vài phương cách đánh dấu Spam của Linux.
        (thực ra mình post mấy cái này sau một vài tranh cải về nhận định chặn Spam bên box khác)
        Last edited by camaptrang; 27-10-2007, 05:12 AM.

        Hướng dẫn cài đặt cấu hình Data Loss Prevention - MyQLP Appliance (Open Source)


        Hướng dẫn cài đặt và cấu hình Mdeamon 12.x

        Hướng dẫn cài đặt cấu hình ISA 2006 và Exchange 2003 - Mô hình Front-End Back-End

        Cài đặt và cấu hình Cacti - Giám Sát và Quản Lý Hệ Thống Mạng

        Hướng dẫn cài đặt cấu hình Retrospect Backup Server

        Cài đặt và cấu hình phần mềm FSA Audit Files Server

        CAMAPTRANG
        http://www.asterisk.vn

        Comment


        • #6
          Hi,

          Cái này có thể chạy trên RH4 ko bác camap ? Cho xin cái file guide config and maintain của nó đi...thanks

          Nice Weekend!
          Att ~¿ 21°00.00N , HCMC

          Comment


          • #8
            Cám ơn camaptrang va zippo nhiều về bài trả lời. Theo được biết từ một người bạn hiện họ đã triển khai project Asas (http://www.rpath.org/rbuilder/project/asas/) và rất hiệu quả. Xin hỏi hai bác co' kinh ghiệm gì qua cái project này không xin chỉ giáo đàn em đi sau. Chân thành cảm ơn. Cái project thằng em đang deploy hơi chúi chut'.

            mail from internet --> front-end(exchange 2003)--> Asas --> back-end(exchange 2003)

            Liệu cái này có hoạt động hiệu quả không. Hay co gi problem. Xin các bác cho ý kiến thằng em cai'. Thanks

            Hihi nếu tiện cho thằng em này diện kiến mấy bác được không? làm chầu cafe sáng la được coi như làm wen. Còn chỉ giáo thì từ từ cũng được mzừ.

            Comment


            • #9
              Hướng dẫn cài đặt và sử dụng DSPAM

              Xin chào các bạn !

              Hiện nay mình đang học sử dụng DSPAM vào hệ thống mail của minh, nhưng mình chưa hiểu cách cài đặt và sử dụng DSPAM vào hệ thống như thế nào.
              Mong các bạn sớm chỉ giúp, xin chân thành cảm ơn !

              TQT



              Originally posted by camaptrang View Post
              Hoàn toàn đồng ý với Zippo, hiii bài viết SpamAssassin đó của James cũng khá lâu rồi, nhưng nếu nhìn nó các bạn mới tiếp cận với Linux hay IT dễ dàng nhìn ra một vài phương cách đánh dấu Spam của Linux.
              (thực ra mình post mấy cái này sau một vài tranh cải về nhận định chặn Spam bên box khác)
              Thai Quoc Thang

              Comment


              • #10
                Cảm ơn anh, đây là bài viết mà em tìm kiếm phải nói kiến thức thật sự hữu ích .

                Comment

                Working...
                X