免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3111 | 回复: 0

如何安装配置SpamAssassin、ClamAV与Procmail [复制链接]

论坛徽章:
0
发表于 2010-01-28 01:30 |显示全部楼层
1. 安装SpamAssassin
(请注意,在安装SpamAssassin前,请确认你的系统已经安装了Perl)
cd /tmp
wget
http://www.mirror.ac.uk/sites/spamassassin.taint.org/spamassassin.org/released/Mail-SpamAssassin-2.63.tar.gz
tar xvfz Mail-SpamAssassin-2.63.tar.gz
cd Mail-SpamAssassin-2.63
perl Makefile.PL
make
make install2. 安装ClamAV
cd /tmp
groupadd clamav
useradd -g clamav -s /bin/false -c "Clam AntiVirus" clamav
wget
http://heanet.dl.sourceforge.net/sourceforge/clamav/clamav-0.67.tar.gz
tar xvfz clamav-0.67.tar.gz
cd clamav-0.67
./configure --sysconfdir=/etc(请注意,你可以使用./configure --help来获得更多编译安装选项)
make
su -c "make install"安装完成后,如果你运行:
clamd你会得到一个错误提示:
ERROR: Please edit the example config file /etc/clamav.conf.你需要参照一下内容来编辑/etc/clamav.conf文件:
##
## Example config file for the Clam AV daemon
## Please read the clamav.conf(5) manual before editing this file.
##
# Comment or remove the line below.
#Example
# Uncomment this option to enable logging.
# LogFile must be writable for the user running the daemon.
# Full path is required.
#LogFile /tmp/clamd.log
# By default the log file is locked for writing - the lock protects against
# running clamd multiple times (if want to run another clamd, please
# copy the configuration file, change the LogFile variable, and run
# the daemon with --config-file option). That's why you shouldn't uncomment
# this option.
#LogFileUnlock
# Maximal size of the log file. Default is 1 Mb.
# Value of 0 disables the limit.
# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)
# and 'K' or 'k' for kilobytes (1K = 1k = 1024 bytes). To specify the size
# in bytes just don't use modifiers.
#LogFileMaxSize 2M
# Log time with an each message.
#LogTime
# Use system logger (can work together with LogFile).
#LogSyslog
# Enable verbose logging.
#LogVerbose
# This option allows you to save the process identifier of the listening
# daemon (main thread).
#PidFile /var/run/clamd.pid
# Path to a directory containing .db files.
# Default is the hardcoded directory (mostly /usr/local/share/clamav,
# it depends on installation options).
#DatabaseDirectory /var/lib/clamav
# The daemon works in local or network mode. Currently the local mode is
# recommended for security reasons.
# Path to the local socket. The daemon doesn't change the mode of the
# created file (portability reasons). You may want to create it in a directory
# which is only accessible for a user running daemon.
LocalSocket /tmp/clamd
# Remove stale socket after unclean shutdown.
#FixStaleSocket
# TCP port address.
#TCPSocket 3310
# TCP address.
# By default we bind to INADDR_ANY, probably not wise.
# Enable the following to provide some degree of protection
# from the outside world.
#TCPAddr 127.0.0.1
# Maximum length the queue of pending connections may grow to.
# Default is 15.
#MaxConnectionQueueLength 30
# When activated, input stream (see STREAM command) will be saved to disk before
# scanning - this allows scanning within archives.
#StreamSaveToDisk
# Close the connection if this limit is exceeded.
#StreamMaxLength 10M
# Maximal number of a threads running at the same time.
# Default is 5, and it should be sufficient for a typical workstation.
# You may need to increase threads number for a server machine.
#MaxThreads 10
# Thread (scanner - single task) will be stopped after this time (seconds).
# Default is 180. Value of 0 disables the timeout. SECURITY HINT: Increase the
# timeout instead of disabling it.
#ThreadTimeout 500
# Maximal depth the directories are scanned at.
MaxDirectoryRecursion 15
# Follow a directory symlinks.
# SECURITY HINT: You should have enabled directory recursion limit to
# avoid potential problems.
#FollowDirectorySymlinks
# Follow regular file symlinks.
#FollowFileSymlinks
# Do internal checks (eg. check the integrity of the database structures)
# By default clamd checks itself every 3600 seconds (1 hour).
#SelfCheck 600
# Execute a command when virus is found. In the command string %v and %f will
# be replaced by the virus name and the infected file name respectively.
#
# SECURITY WARNING: Make sure the virus event command cannot be exploited,
#                    eg. by using some special file name when %f is used.
#                    Always use a full path to the command.
#                    Never delete/move files with this directive !
#VirusEvent /usr/local/bin/send_sms 123456789 "VIRUS ALERT: %f: %v"
# Run as selected user (clamd must be started by root).
# By default it doesn't drop privileges.
User clamav
# Initialize the supplementary group access (for all groups in /etc/group
# user is added in. clamd must be started by root).
#AllowSupplementaryGroups
# Don't fork into background. Useful in debugging.
#Foreground
# Enable debug messages in libclamav.
#Debug
##
## Mail support
##
# Uncomment this option if you are planning to scan mail files.
ScanMail
##
## Archive support
##
# Comment this line to disable scanning of the archives.
ScanArchive
# By default the built-in RAR unpacker is disabled by default because the code
# terribly leaks, however it's probably a good idea to enable it.
#ScanRAR
# Options below protect your system against Denial of Service attacks
# with archive bombs.
# Files in archives larger than this limit won't be scanned.
# Value of 0 disables the limit.
# WARNING: Due to the unrarlib implementation, whole files (one by one) in RAR
#           archives are decompressed to the memory. That's why never disable
#           this limit (but you may increase it of course!)
ArchiveMaxFileSize 10M
# Archives are scanned recursively - e.g. if Zip archive contains RAR file,
# the RAR file will be decompressed, too (but only if recursion limit is set
# at least to 1). With this option you may set the recursion level.
# Value of 0 disables the limit.
ArchiveMaxRecursion 5
# Number of files to be scanned within archive.
# Value of 0 disables the limit.
ArchiveMaxFiles 1000
# Use slower decompression algorithm which uses less memory. This option
# affects bzip2 decompressor only.
#ArchiveLimitMemoryUsage
##
## Clamuko settings
## WARNING: This is experimental software. It is very likely it will hang
##            up your system !!!
##
# Enable Clamuko. Dazuko (/dev/dazuko) must be configured and running.
#ClamukoScanOnLine
# Set access mask for Clamuko.
ClamukoScanOnOpen
ClamukoScanOnClose
ClamukoScanOnExec
# Set the include paths (all files in them will be scanned). You can have
# multiple ClamukoIncludePath options, but each directory must be added
# in a seperate option. All subdirectories are scanned, too.
ClamukoIncludePath /home
#ClamukoIncludePath /students
# Set the exclude paths. All subdirectories are also excluded.
#ClamukoExcludePath /home/guru
# Limit the file size to be scanned (probably you don't want to scan your movie
# files ;))
# Value of 0 disables the limit. 1 Mb should be fine.
ClamukoMaxFileSize 1M
# Enable archive support. It uses the limits from clamd section.
# (This option doesn't depend on ScanArchive, you can have archive support
# in clamd disabled).
# ClamukoScanArchive现在我们需要为ClamAV创建一个初始化脚本/etc/init.d/clamd文件:
#!/bin/bash
TMPDIR=/tmp
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin
case "$1" in
start)
echo "Starting ClamAV..."
if [ -S /tmp/clamd ]; then
echo "ClamAV is already running!"
else
/usr/local/bin/freshclam -d -c 10 --datadir=/usr/local/share/clamav
/usr/local/sbin/clamd
fi
echo "ClamAV is now up and running!"
;;
stop)
echo "Shutting down ClamAV..."
array=(`ps ax | grep -iw '/usr/local/bin/freshclam' | grep -iv 'grep' \
| awk '{print $1}' | cut -f1 -d/ | tr '\n' ' '`)
element_count=${#array[@]}
index=0
while [ "$index" -lt "$element_count" ]
do
kill -9 ${array[$index]}
let "index = $index + 1"
done
array=(`ps ax | grep -iw '/usr/local/sbin/clamd' | grep -iv 'grep' \
| awk '{print $1}' | cut -f1 -d/ | tr '\n' ' '`)
element_count=${#array[@]}
index=0
while [ "$index" -lt "$element_count" ]
do
kill -9 ${array[$index]}
let "index = $index + 1"
done
if [ -S /tmp/clamd ]; then
rm -f /tmp/clamd
fi
echo "ClamAV stopped!"
;;
restart)
$0 stop  && sleep 3
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0改变文件权限:
chmod 755 /etc/init.d/clamd启动ClamAV:
/etc/init.d/clamd start现在运行以下命令,你应该看到clamd程序的进程和更新病毒库的freshclam进程:
ps aux以下内容包含在clamd初始化脚本内,使clamd能够每天更新10次病毒库
/usr/local/bin/freshclam -d -c 10 --datadir=/usr/local/share/clamav运行以下命令使ClamAV能够跟随系统启动:
ln -s /etc/init.d/clamd /etc/rc2.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc3.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc4.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc5.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc0.d/K20clamd
ln -s /etc/init.d/clamd /etc/rc1.d/K20clamd
ln -s /etc/init.d/clamd /etc/rc6.d/K20clamd3 Install trashscan3. 安装Trashscan
Trashscan为Procmail和ClamAV建立了连接。(当收到一封电子邮件,Procmail将调用Trashscan,而Trashscan将调用ClamAV来扫描邮件是否感染病毒)
cd /tmp/clamav-0.67/contrib/trashscan
tar xvfz trashscan-0.08.tar.gz
cd trashscan-0.08
cp -pf trashscan /usr/local/sbin/安装完成后,我们需要在文件/usr/local/sbin/trashscan的配置部分中调整一些参数。你可以参阅以下内容:
#!/bin/bash
#
# TrashScan v0.08; Scan email for viruses
# ZapCoded by Trashware; 13.10.2002
# Email:
trashware@gmx.de
# Web:
http://trashware.mirrorz.com
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
# --------------------------------------- Begin Settinx ---------------------------------------- #
SCANDIR=$HOME/tmp                                              # Temp directory for virus scans.
                                                               # Security: Don't define public
                                                               # accessible directories here !!!
                                                               # $HOME/tmp should be fine.
#DECODER=metamail                                              # Decoder: "metamail" or "uudeview"
#DECODPRG=metamail                                             # Absolute path to decoder: metamail
DECODER=uudeview                                               # Decoder: "metamail" or "uudeview"
DECODPRG=/usr/local/bin/uudeview                               # Absolute path to decoder: uudeview
VSCANPRG=/usr/local/bin/clamscan                               # Absolute path to the virus scanner
VSCANOPT="--quiet --tempdir=$HOME/tmp --recursive --max-files=500 \
        --max-space=30M --unzip=/usr/bin/unzip --unrar=/usr/bin/unrar \
        --unarj=/usr/bin/unarj --zoo=/usr/bin/zoo --lha=/usr/bin/lha \
        --jar=/usr/bin/unzip --tar=/bin/tar --tgz=/bin/tar"    # Parameters for the virus scanner.
                                                               # Security: Don't choose public
                                                               # accessible directories for the
                                                               # --tempdir definition !!!
                                                               # --tempdir=$HOME/tmp should be fine.
VSCANVEX=1                                                     # Exitcode of the virus scanner if a
                                                               # virus was found
VSCANSUSP=mail.virus                                           # File to store suspicious mail (see
                                                               # procmail.trashscan)
FORMAIL=formail                                                # Absolute path to formail
PROCMAIL=procmail                                              # Absolute path to procmail
SENDMAIL=sendmail                                              # Absolute path to sendmail
CAT=cat                                                        # Absolute path to cat
GREP=grep                                                      # Absolute path to grep
LOGGER=logger                                                  # Absolute path to logger
LOGPRIO=mail.warn                                              # Log level for logger
MKDIR=mkdir                                                    # Absolute path to mkdir
RM=rm                                                          # Absolute path to rm
SED=sed                                                        # Absolute path to sed
ALERTRCVR=virusadmin@example.com                               # Receiver of virus alert messages
ALERTSNDR=virusadmin@example.com                               # Sender of virus alert messages
ALERTCTCT=virusadmin@example.com                               # Person to contact (appears in the
                                                               # mail body of the virus alert)
# ---------------------------------------- End Settinx ---------------------------------------- #请注意在脚本开头部分的路径定义:
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin这样我们可以不需要指定需要调用Trashscan程序的绝对路径。
VSCANOPT参数指定了当邮件含有压缩文件时所需要的解压缩程序路径,你可能并不需要检查所有的压缩文件,但是在这里建议至少指定常用压缩格式的解压缩程序路径(例如:zip格式),当然你的系统同样需要安装这些解压缩程序。
另外,请指定一个邮件地址来接收病毒警告邮件
4. 安装uudeview
Trashscan需要一个外部程序来解码邮件信息。在上面的Trashscan配置中,我们指定了uudeview,所以,现在我们来安装uudeview。
cd /tmp
wget
http://www.fpx.de/fp/Software/UUDeview/download/uudeview-0.5.19.tar.gz
tar xvfz uudeview-0.5.19.tar.gz
cd uudeview-0.5.19
./configure
make
make install5. 配置Procmail
Procmail是大部分发行版的默认组件,所以在这里略过Procmail的安装过程。
运行以下命令来找出系统中Procmail的位置(一般都会在/usr/bin/procmail):
which procmail现在我们假设为家目录在/home/www/web1/user/testuser的用户testuser来配置Procmail。
确定用户testuser的家目录权限是755,否则Procmail无法正常工作。
首先我们创建文件/home/www/web1/user/testuser/.forward,在testuser收到邮件时,Procmail会被调用。
添加以下内容至/home/www/web1/user/testuser/.forward:
"|/usr/bin/procmail -f-"改变文件所属及权限:
chown testuser /home/www/web1/user/testuser/.forward
chmod 600 /home/www/web1/user/testuser/.forward创建并复制以下内容至/home/www/web1/user/testuser/.procmailrc。这个文件内容帮助Procmail决定运行哪些程序。(这里我们仅添加了简单的主要程序,你可以添加更多自定义程序)
## MAILDIR=$HOME/Maildir/
## DEFAULT=$MAILDIR
INCLUDERC=/home/www/web1/user/testuser/.antivirus.rc
INCLUDERC=/home/www/web1/user/testuser/.html-trap.rc
INCLUDERC=/home/www/web1/user/testuser/.spamassassin.rc请注意,如果使用Maildir功能,可以取消前两行的#。(Maildir功能将会更改邮件存储路径为/home/www/web1/user/testuser/Maildir/来替代原来的/var/spool/mail。)
创建并添加以下内容至/home/www/web1/user/testuser/.antivirus.rc:
#
# procmail configuration for TrashScan: ZapCoded by Trashware; 13.10.2002
#
# [ ... ]
# ------------------------------------------------------------------------------------- #
# Virus scan section ...                                                                #
# ------------------------------------------------------------------------------------- #
# 1. Run TrashScan
:0
* multipart
* !^X-Virus-Scan:
| /usr/local/sbin/trashscan
# 2. Filter tagged virus mails
:0:
* ^X-Virus-Scan: Suspicious
/dev/null创建并添加以下内容至/home/www/web1/user/testuser/.spamassassin.rc:
# SpamAssassin sample procmailrc
#
# Pipe the mail through spamassassin (replace 'spamassassin' with 'spamc'
# if you use the spamc/spamd combination)
# The condition line ensures that only messages smaller than 250 kB
# (250 * 1024 = 256000 bytes) are processed by SpamAssassin. Most spam
# isn't bigger than a few k and working with big messages can bring
# SpamAssassin to its knees.
:0fw
* 以上内容将接收所有邮件(包含垃圾邮件)。通常用于初始阶段测试SpamAssassin工作状态。
如果你想过滤垃圾邮件,可以将以下内容编辑覆盖至.spamassassin.rc文件中。
# SpamAssassin sample procmailrc
#
# Pipe the mail through spamassassin (replace 'spamassassin' with 'spamc'
# if you use the spamc/spamd combination)
# The condition line ensures that only messages smaller than 250 kB
# (250 * 1024 = 256000 bytes) are processed by SpamAssassin. Most spam
# isn't bigger than a few k and working with big messages can bring
# SpamAssassin to its knees.
:0fw
* 接下来,我们创建并添加以下内容至/home/www/web1/user/testuser/.user_prefs,这个文件内容决定了用户的SpamAssassin设置:
# SpamAssassin user preferences file.  See 'perldoc Mail::SpamAssassin::Conf'
# for details of what can be tweaked.
#*
#* Note: this file is not read by SpamAssassin until copied into the user
#* directory. At runtime, if a user has no preferences in their home directory
#* already, it will be copied for them, allowing them to perform personalised
#* customisation.  If you want to make changes to the site-wide defaults,
#* create a file in /etc/spamassassin or /etc/mail/spamassassin instead.
###########################################################################
# How many hits before a mail is considered spam.
required_hits         5.0
rewrite_subject       1
subject_tag           ***SPAM***SpamAssassin在每封电子邮件上运行一些测试来确定它们是否是垃圾邮件并在测试过程中记录与确定每封邮件required_hits值与rewrite_subject值。你可以通过调整参数值来区别是否是垃圾邮件。
6. 配置Email Sanitizer
Email Sanitizer (
http://www.impsec.org/email-tools/procmail-security.html
) 是一个可以被Procmail调用的邮件内容过滤程序。
例如,它可以禁用HTML邮件中的恶意JavaScript代码,并将含有可疑代码的附件重命名。(假设:example.exe含有恶意代码,会被重命名为example.12345DEFANGED-exe,所以文件无法直接被用户在Windows系统执行。)
运行以下命令安装:
cd /tmp
wget
http://www.impsec.org/email-tools/html-trap.procmail.gz
gunzip html-trap.procmail.gz
echo 'PATH="/usr/bin:$PATH:/usr/local/bin"' > /home/www/web1/user/testuser/.html-trap.rc
echo 'SHELL=/bin/sh' >> /home/www/web1/user/testuser/.html-trap.rc
cat html-trap.procmail >> /home/www/web1/user/testuser/.html-trap.rc7.测试你的配置
完成配置后,你可以发送一些包含附件的邮件来进行测试,当然如果你有恶意代码或者病毒文件,也可以使用它们来测试邮件系统是否能够正常工作。
当接收到邮件后,程序如果正常工作的话,邮件应包含以下内容:
X-Security: MIME headers sanitized on server1.example.com See
http://www.impsec.org/email-tools/sanitizer-intro.html
for details. $Revision: 1.140 $Date: 2004-02-11 20:47:43-08
X-Virus-Scan: Scanned by TrashScan v0.08 running on server1.example.com
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server1.example.com
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/7546/showart_2162691.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP