This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Enable Spamassassin Bayes

We have ASG V6.  Spam threshold is set to quarantine at 4 and reject at 8.  We have blocked a few legitimate emails at the 4 level so any lower for us and we would probably block too much legitimate mail.  We have bl.spamcop.net, sbl.spamhaus.org, list.dsbl.org, relays.ordb.org, and xbl.spamhaus.org for RBL's in use.  I was trying to figure out if the BAYES feature of spamassassin is used by default but it doesn't appear to be.  I've seen others posting spam email contents with Bayes information in them.  I have never seen any spam email in proxy content manager with Bayes filtering in it.  How does one go about using this feature??  We still get very obvious spam inside our network with buzz words in the body such as V I A GrA, and other variations of this word and other drugs.  It seems obvious that a spam program should block stuff as obvious as this.  So, how do I learn this spamassassin to block using the bayes feature??


This thread was automatically locked due to age.
  • I've tried turning on use_bayes in local.cf, but I can't get it to actually use the feature.  If I run SpamAssassin from the command line, it uses the Bayesian analysis, but it's not running on incoming emails.  It also doesn't use it when I run spamc by hand.  I ran spamd -D from the command line, and the debug output reports the following problem:

    [21065] dbg: bayes: no dbs present, cannot tie DB R/O: /tmp/spamd-21065-init/.spamassassin/bayes_toks

    Looking at /usr/sbin/spamd, it seems that it changes its home directory to a /tmp directory before loading all the modules (presumably for security reasons); however, it seems that it's then looking there for the bayesian databases, where they obviously won't be.

    Am I the only one having this problem (I'm running 6.301)?

    Thanks for any help you can give me.

    Andrew
  • Hi,

    The path is incorrect /tmp there. I think that is due to your manual run with spamassassin.
    However do these checks please, to see if it has created it's own DB. Since spamassassin runs with nobody the database should be at /var/lib/nobody/.spamassassin/

    Then also spamassassin by default don't use bayes until it have 200 spam and 200 ham.

    Well do this.
    1: Check /var/lib/nobody/.spamassassin/ does it have bayes files in it?
    2: If not Make your changes to /etc/mail/spamassassin/local.cf and then restart spamassassin, /var/mdw/scripts/spamassassin restart

    Hope this will help. I run 6.301 and i have no problems. [:)]
  • I have also done some changes to the location of the bayesdb due to it's size after some time.

    Normaly you have /var/lib/nobody/.spamassassin/ as your database path.
    / in ASL is not very large so I moved it to /var/storage/bayesdb and then securing that path.

    Run as root and stop your spamassassin deamon (stop spamchecking from the smtp proxy webgui)
    1: cd /var/storage
    2: mkdir bayesdb
    3: chmod 700 bayesdb
    4: chown nobody:nobody bayesdb
    5: mv /var/lib/nobody/.spamassassin/* /var/storage/bayesdb/
    6: ln -s /var/storage/bayesdb/bayes.mutex bayes.mutex
    7: ln -s /var/storage/bayesdb/bayes_seen bayes_seen
    8: ln -s /var/storage/bayesdb/bayes_toks bayes_toks
    9: Start spamassassin and check  /var/log/contentfilter.log | grep spamd for errors. Should not be a problem but you never know. [;)]


    Now your files are stored at the larger area of /var/storage [:)]
    This is how it should look with rights and so on...
    firewall:/var/storage/bayesdb # ll
    -rw-r--r--  1 nobody nobody      360 Aug  5 11:14 bayes.mutex
    -rw-------  1 nobody nobody  2711552 Aug  5 11:14 bayes_seen
    -rw-------  1 nobody nobody 10379264 Aug  5 11:14 bayes_toks



     Note!! If you have to update your locations in the backup.ini, Just add var/storage/bayesdb at the end of the file.
  • In the contentfilter.log, I was getting the same error messages:

    2006:08:05-00:11:50 (none) spamd[21065]: bayes: no dbs present, cannot tie DB R/O: /tmp/spamd-21065-init/.spamassassin/bayes_toks 

    But then, suddenly it started working.  Not sure what changed, but whatever....

    Thanks for your help.

    Andrew
  • Hi,

    Okey [:)]
    But you have your db files at /var/lib/nobody/.spamassassin/ ?
    They should not be at /tmp that is bad.

    Please double check this.
  • My DB files are indeed where they should be.

    If you look at the startup script for spamassassin, you'll see that it creates a home directory in temp and then initializes all the modules there, causing it to look for them there.  However, when it processes a message, it seems to go back and look for them in the right place.  I haven't tracked it all down yet.

    If you want to see for yourself, edit the spamassassin startup script to turn on debug mode for spamd.  I don't have access to the firewall right now, so I'll post more explicit instructions in a bit.

    Andrew
  • Okey thats good. My thougt was that he continued to run from /tmp and that is not that good [[;)]]

    I have not gone that deep in the scripts [[;)]]
    I dont have that error in any of my logs as far as i can see. I tried the backup the other day on an new hardware and everything worked directly. No errors what so ever.

    The error could be a one and only apperance due to the lac of db files perheps? Or du you get it over and over again?

    Okey please do so if someone else have this issue it might help them. [:)]

    Btw here is my new local.cf
    # This is the right place to customize your installation of SpamAssassin.
    #
    # See 'perldoc Mail::SpamAssassin::Conf' for details of what can be
    # tweaked.
    #
    # Only a small subset of options are listed below
    #
    ################################################## #########################
    # Add *****SPAM***** to the Subject header of spam e-mails
    #
    # rewrite_header Subject *****SPAM*****

    # Save spam messages as a message/rfc822 MIME attachment instead of
    # modifying the original message (0: off, 2: use text/plain instead)
    #
    # report_safe 1

    # Set which networks or hosts are considered 'trusted' by your mail
    # server (i.e. not spammers) (My internal network)
    #
    trusted_networks 192.168.0.

    # Set file-locking method (flock is not safe over NFS, but is faster)
    #
    lock_method flock

    # Set the threshold at which a message is considered spam (default: 5.0)
    #
    # required_score 5.0

    # Email BULK checking (Not working due to need of seperate software)
    #use_pyzor 1
    #use_dcc 1
    #use_razor2 1


    # Blacklisted recipients
    blacklist_to sales@mydomain.com info@mydomain.com home@mydomain.com root@mydomain.com majordomo@mydomain.com test@mydomain.com uucp@mydomain.com help@mydomain.com service@mydomain.com support@mydomain.com guest@mydomain.com contact@mydomain.com billing@mydomain.com advertising@mydomain.com accounting@mydomain.com accounts@mydomain.com admin@mydomain.com administrator@mydomain.com mail@mydomain.com webmaster@mydomain.com

    # Whitelisted recipients
    whitelist_from pal@hisdomain.com *@otherpaldomain.com


    # Use Bayesian classifier (default: 1)
    #
    use_bayes 1
    use_bayes_rules 1
    bayes_use_hapaxes 1
    bayes_auto_expire 1
    bayes_expiry_max_db_size 10000000
    bayes_min_ham_num 200
    bayes_min_spam_num 200

    # Bayesian classifier auto-learning (default: 1)
    # Threshold have to be min 0.1 for ham and min 6.0 for spam
    bayes_auto_learn 1
    bayes_auto_learn_threshold_nonspam 0.1
    bayes_auto_learn_threshold_spam 6.0
    bayes_learn_to_journal 0

    # Set headers which may provide inappropriate cues to the Bayesian
    # classifier
    #
    bayes_ignore_header X-LOC-Sender-is-local
    bayes_ignore_header X-Bogosity
    bayes_ignore_header X-Virus-Scanned
    bayes_ignore_header X-Authentication-Warning
    bayes_ignore_header X-Trailer
    bayes_ignore_header X-Spam
    bayes_ignore_header X-Spam-Flag
    bayes_ignore_header X-Spam-Status
    bayes_ignore_header X-Spam-Score
    bayes_ignore_header X-Spam-Report
    bayes_ignore_header ReSent-Date
    bayes_ignore_header ReSent-From
    bayes_ignore_header ReSent-Message-ID
    bayes_ignore_header ReSent-Subject
    bayes_ignore_header ReSent-To
    bayes_ignore_header Resent-Date
    bayes_ignore_header Resent-From
    bayes_ignore_header Resent-Message-ID
    bayes_ignore_header Resent-Subject
    bayes_ignore_header Resent-To


    use_auto_whitelist 0

    # Custom score settings
    #
    # Always get low score for internal network
    score ALL_TRUSTED -100

    # Astaro score settings
    #
    score DRUGS_ERECTILE 2
    score DRUGS_ANXIETY_EREC 2
    score HTML_MIME_NO_HTML_TAG 1
    score HTML_MESSAGE 0.0
    score HTML_FONT_BIG 1
    score RCVD_NUMERIC_HELO 2
    score RCVD_BY_IP 1

    # Astaro extra adjust for asia emails
    score MIME_BASE64_TEXT 0.5

    # Astaro DELL and backhair...
    score J_BACKHAIR_11 0.5
    score J_BACKHAIR_12 0.5
    score J_BACKHAIR_13 0.5
    score J_BACKHAIR_14 0.5
    score J_BACKHAIR_15 0.5
    score J_BACKHAIR_16 0.5
    score J_BACKHAIR_17 0.5
    score J_BACKHAIR_21 0.5
    score J_BACKHAIR_21 0.5
    score J_BACKHAIR_22 0.5
    score J_BACKHAIR_23 0.5
    score J_BACKHAIR_24 0.5
    score J_BACKHAIR_25 0.5
    score J_BACKHAIR_26 0.5
    score J_BACKHAIR_27 0.5
    score J_BACKHAIR_31 0.5
    score J_BACKHAIR_31 0.5
    score J_BACKHAIR_32 0.5
    score J_BACKHAIR_33 0.5
    score J_BACKHAIR_34 0.5
    score J_BACKHAIR_35 0.5
    score J_BACKHAIR_36 0.5
    score J_BACKHAIR_37 0.5
    score J_BACKHAIR_41 0.5
    score J_BACKHAIR_41 0.5
    score J_BACKHAIR_42 0.5
    score J_BACKHAIR_43 0.5
    score J_BACKHAIR_44 0.5
    score J_BACKHAIR_45 0.5
    score J_BACKHAIR_46 0.5
    score J_BACKHAIR_47 0.5
    score J_BACKHAIR_51 0.5
    score J_BACKHAIR_51 0.5
    score J_BACKHAIR_52 0.5
    score J_BACKHAIR_53 0.5
    score J_BACKHAIR_54 0.5
    score J_BACKHAIR_55 0.5
    score J_BACKHAIR_56 0.5
    score J_BACKHAIR_57 0.5


    # Franks custom score
    # Special haxx
    #
    # Blacklisted addresses scoring and learning
    header USER_IN_BLACKLIST_TO     eval:check_to_in_blacklist()
    describe USER_IN_BLACKLIST_TO   User is listed in 'blacklist_to'
    tflags USER_IN_BLACKLIST_TO     learn
    #
    score USER_IN_BLACKLIST_TO 15.000

    # Whitelisted addresses scoring and learning nice
    #
    header USER_IN_WHITELIST        eval:check_from_in_whitelist()
    describe USER_IN_WHITELIST      From: address is in the user's white-list
    tflags USER_IN_WHITELIST        nice
    #
    score USER_IN_WHITELIST -15.000

    ##############
    # SenderBase information 
    # these are experimental example rules

    # sa.senderbase.org for SpamAssassin queries
    # query.senderbase.org for other queries
    header __SENDERBASE eval:check_rbl_txt('sb', 'sa.senderbase.org.')
    tflags __SENDERBASE net

    # S23 = domain daily magnitude, S25 = date of first message from this domain
    header SB_NEW_BULK              eval:check_rbl_sub('sb', 'sb:S23 > 6.2 && (time - S25  0.3" means at least a 59% volume spike
    header SB_NSP_VOLUME_SPIKE      eval:check_rbl_sub('sb', 'sb:S5 =~ /NSP/ && S41 > 3.0 && S40 - S41 > 0.3')
    describe SB_NSP_VOLUME_SPIKE    Sender IP hosted at NSP has a volume spike
    tflags SB_NSP_VOLUME_SPIKE      net

    # S5 = category, S40 = IP daily magnitude, S41 = IP monthly magnitude
    # note: accounting for rounding, "> 0.3" means at least a 59% volume spike
    header SB_ISP_VOLUME_SPIKE      eval:check_rbl_sub('sb', 'sb:S5 =~ /ISP/ && S41 > 3.0 && S40 - S41 > 0.3')
    describe SB_ISP_VOLUME_SPIKE    Sender IP hosted at ISP has a volume spike
    tflags SB_ISP_VOLUME_SPIKE      net

    #
    score __SENDERBASE 1.000
    score SB_NEW_BULK 3.000
    score SB_NSP_VOLUME_SPIKE 3.0000
    score SB_ISP_VOLUME_SPIKE 1.0000
    #############

    #
    # Gif
    full     SARE_GIF_ATTACH   /name=\"[a-zA-Z0-9.-]{3,18}\.gif\"/i
    describe SARE_GIF_ATTACH   Email has a inline gif and digits

    #############
    # Special score
    #
    # Extra points for softfail and negative score for pass
    # (Not working what i can see)
    score SPF_PASS -8.000
    score SPF_FAIL 8.000
    score SPF_SOFTFAIL 6.000
    score SPF_HELO_PASS -6.000
    score SPF_HELO_FAIL 6.000
    score SPF_HELO_SOFTFAIL 6.000

    # Extra points for picture spam
    score SARE_GIF_ATTACH 8.000
    score SARE_GIF_STOX 8.000

    # Bayers scoring
    score BAYES_99 15.000
    score BAYES_95 12.500
    score BAYES_80 8.000
    score BAYES_60 4.000
    score BAYES_50 0.000
    score BAYES_40 -4.000
    score BAYES_20 -8.000
    score BAYES_05 -12.500
    score BAYES_00 -15.000
  • This is just a note. I just realized that I have not written this before.

    If you customwrite your own /etc/mail/spamassassin/local.cf 
    New changes by Astaro will not be active. 
    They will be placed at /etc/mail/spamassassin/local.cf.rpmnew 

    So after every new spam-up2date or system-up2date have a check in the local.cf.rpmnew file to see if you have any new changes. There might be improvments that we might miss otherwise. Then just move them to local.cf and restart spamassassin.
    /var/mdw/scripts/spamassassin restart

    Happy hacking... [:)]
  • Before you upgrade to 6.303 backup your database!

     
    The folder content (the databases) /var/lib/nobody/.spamassassin might or will be deleted or overwritten. Plasing you back at square 1 again.
     

    Only important if you have moved the database to an other location


    Due to the new patch (6.303) today I hade to remake my links. 
    As I have posted before I moved the database from /var/lib/nobody/.spamassassin to /var/storage/bayesdb

    Today they updated the spam daemon [:)] and due to that the linkt that I have made in /var/lib/nobody/.spamassassin was removed.

    Just remake them like this if you also have done like I have.
    1: cd /var/lib/nobody/.spamassassin
     2: ln -s /var/storage/bayesdb/bayes.mutex bayes.mutex
    3: ln -s /var/storage/bayesdb/bayes_seen bayes_seen
    4: ln -s /var/storage/bayesdb/bayes_toks bayes_toks
    5: /var/mdw/scripts/spamassassin restart

    Then you are back to where you where before [:D]