Tag Archives: antispam

Postfix and AntiSpam Smtp Proxy – ASSP

http://www.howtoforge.com/antispam_smtp_proxy

perl -MCPAN -e shell

install Compress::Zlib
install Digest::MD5
install Email::Valid
install File::ReadBackwards
install Mail::SPF::Query
install Mail::SRS
install Net::DNS
install Sys::Syslog
install Time::HiRes

cd /usr/src/
wget http://downloads.sourceforge.net/project/assp/ASSP%20V2%20multithreading/2.4.1%2014085/ASSP_2.4.1_14085_install.zip
unzip ASSP_2.4.1_14085_install.zip

mkdir -p /usr/share/assp/spam
mkdir /usr/share/assp/notspam
mkdir /usr/share/assp/errors
mkdir /usr/share/assp/errors/spam
mkdir /usr/share/assp/errors/notspam

mv -f assp/* /usr/share/assp
rm -fr ASSP_2.4.1* assp changelog.txt Install.txt MacOSX-launchd.txt quickstart.txt Win32-quickstart-guide.txt
chown -R 0.0 /usr/share/assp
cd /usr/share/assp
perl assp.pl

http://hostname:55555

login: root
password: nospam4me

Server Setup
-> Run ASSP as a Daemon (AsADaemon)
-> SMTP Destination -> 127.0.0.1:25
-> Listen Port -> 192.168.122.1:25
Recipients -> Local Domains -> faix.cz
Relaying -> Accept All Mail (acceptAllMail) -> 192.168.122.|127.0.0.1
Security -> Web Admin Password

/etc/postfix/master.cf
localhost:smtp inet n – n – – smtpd

service postfix restart

/etc/init.d/assp

#########################
#!/bin/sh -e

# Start or stop ASSP (Anti-Spam SMTP Proxy)
#
# Script by Abey Marquez <abeymarquez@gmail.com>
# v1.0.1 Changed 'force-reload' to force a restart if it can't reload the config. Also changed 'restart' to start the proc if not running.
# v1.0.0 I'm not an expert but I tried to make this as LSB compliant as possible. Should work really nice with Ubuntu.

### BEGIN INIT INFO
# Provides: ASSP (Anti-Spam SMTP Proxy)
# Required-Start: $syslog, $local_fs
# Required-Stop: $syslog, $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop ASSP
# Description: Start or stop ASSP (Anti-Spam SMTP Proxy)
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NAME=assp.pl
HOME=/usr/share/assp
DAEMON=$HOME/$NAME
PIDFILE=$HOME/pid
INITSCRIPT=/etc/init.d/assp

. /lib/lsb/init-functions

case "$1" in

start)
log_daemon_msg "Starting ASSP (Anti-Spam SMTP Proxy)" "assp"
start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON 2>&1 > /dev/null --chdir $HOME
log_end_msg $?
;;

stop)
log_daemon_msg "Stopping ASSP (Anti-Spam SMTP Proxy)" "assp"
start-stop-daemon --stop --quiet --pidfile $PIDFILE --chdir $HOME
log_end_msg $?
;;

restart)
if [ -f $PIDFILE ]; then
$0 stop
sleep 1
$0 start
else
$0 start
fi
;;

reload)
log_action_begin_msg "Reloading ASSP (Anti-Spam SMTP Proxy) configuration"
if [ -f $PIDFILE ]; then
if kill -1 $(cat $PIDFILE); then
log_action_end_msg 0
else
log_action_end_msg 1
fi
else
log_action_end_msg 1
exit 1
fi
;;

force-reload)
log_action_begin_msg "Reloading ASSP (Anti-Spam SMTP Proxy) configuration"
if [ -f $PIDFILE ]; then
if kill -1 $(cat $PIDFILE); then
log_action_end_msg 0
else
log_action_cont_msg "Could not reload configuration. Restarting"
$0 restart
fi
else
log_action_cont_msg "Could not reload configuration. Restarting"
$0 restart
fi
;;

status)
status_of_proc $DAEMON "ASSP (Anti-Spam SMTP Proxy)"
;;

*)
log_action_msg "Usage: $INITSCRIPT {start|stop|restart|reload|force-reload|status}"
exit 1
;;

esac
exit 0
####################

chmod 755 /etc/init.d/assp
update-rc.d assp defaults

Have fun with all the options and after a week rebuild the bayes database. Check the directories /usr/share/assp/spam and nospam for wrong entries,
if good mail ends up in the spam directory please move it to the nospam directory and vice versa.

Spamassassin and Postifx configuration

http://www.akadia.com/services/postfix_spamassassin.html

aptitude install spamassassin spamc

/etc/default/spamassassin

ENABLED=1
SAHOME="/var/log/spamassassin/"
OPTIONS="--create-prefs --max-children 2 --username debian-spamd -H ${SAHOME} -s ${SAHOME}spamd.log"
PIDFILE="/var/run/spamd.pid"
CRON=1

/etc/postfix/master.cf

smtp inet n - - - - smtpd -o content_filter=spamfilter
spamfilter unix - n n - - pipe
flags=Rq user=debian-spamd argv=/usr/local/bin/spamfilter.sh -oi -f ${sender} ${recipient}

mkdir /var/spamchk
chmod 775 /var/spamchk
chown debian-spamd:debian-spamd /var/spamchk

/usr/local/bin/spamfilter.sh

#!/bin/sh
# -----------------------------------------------------------------
# File: spamchk
#
# Purpose: SPAMASSASIN shell-based filter
#
# Location: /usr/local/bin
#
# Usage: Call this script from master.cf (Postfix)
#
# Certified: Ubuntu Linux, Spamassassin 3.3.x, Postfix 2.7.x
# -----------------------------------------------------------------
# Variables
SENDMAIL="/usr/sbin/sendmail -i"
EGREP=/bin/egrep
TMPFILE=/tmp/spamchk.$$
SIDELINE_DIR=/var/spamchk
# Number of *'s in X-Spam-level header needed to sideline message:
# (Eg. Score of 5.5 = "*****" )
SPAMLIMIT=3
# Clean up when done or when aborting.
trap "rm -f $TMPFILE" 0 1 2 3 15
# Pipe message to spamc and store in $TMPFILE
cat | /usr/bin/spamc -u filter | sed 's/^\.$/../' > $TMPFILE
# Are there more than $SPAMLIMIT stars in X-Spam-Level header?
if $EGREP -q "^X-Spam-Level: \*{$SPAMLIMIT,}" < $TMPFILE
then
# Option 1: Move high scoring messages to sideline dir so
# a human can look at them later:
mv $TMPFILE $SIDELINE_DIR/`date +%Y-%m-%d_%R`-$$
# Option 2: Divert to an alternate e-mail address:
# $SENDMAIL xyz@xxxx.xx < $TMPFILE
# Option 3: Delete the message
# rm -f $TMPFILE
else
$SENDMAIL "$@" < $TMPFILE
fi
# Postfix returns the exit status of the Postfix sendmail command.
exit $?

/etc/spamassassin/local.cf

rewrite_header Subject *****SPAM***** (_SCORE_)
report_safe 0
trusted_networks 192.168.122.
required_score 3.0
use_bayes 1
bayes_auto_learn 1
ifplugin Mail::SpamAssassin::Plugin::Shortcircuit
shortcircuit ALL_TRUSTED on
endif # Mail::SpamAssassin::Plugin::Shortcircuit

service spamassassin start
service postfix restart