b. 编译并安装四个Perl模块
直接进入每个目录运行 perl Makefile.PL;make;make test;make install 即可。
cd /root
for i in ./*;do tar xvfz $i;done
cd 每个相应的模块目录
perl Makefile.PL
make
make test (确保你测试成功)
make install
c. 编译Sendmail加入MILTER支持
放下面的行在 devtools/Site/site.config.m4 (用VI创建该文件)
APPENDDEF(`conf_sendmail_ENVDEF,`-DMILTER)
确保编译过程中看到Sendmail带参数 -DMILTER 进行编译。
新的Sendmail版本加强了安全性,不再运行以suid,需要设置用户名和组名smmsp, 在/etc/passwd中加入下面的行:
smmsp:x:25:25:Sendmail:/:
在/etc/group中加入下面的行:
smmsp:x:25:
cd /root/sendmail-8.12.1
cd sendmail
sh Build
cd ../cf/cf
cp generic-linux.mc sendmail.mc
vi sendmail.mc (且放下面的行到该文件中)
define(`confPRIVACY_FLAGS, `authwarnings,needmailhelo,novrfy,noexpn,restrictqrun)dnl
INPUT_MAIL_FILTER(`mimedefang, `S=unix:/var/run/mimedefang.sock, F=T, T=S:60s;R:60s;E:5m)
FEATURE(`smrsh,`/usr/sbin/smrsh)dnl
FEATURE(`mailertable,`hash -o /etc/mail/mailertable.db)dnl
FEATURE(`virtusertable,`hash -o /etc/mail/virtusertable.db)dnl
FEATURE(`access_db)dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail,`,`procmail -t -Y -a $h -d $u)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
Cwlocalhost.localdomain
基于Sendmail和Perl的邮件附件过滤系统(3)
其中 INPUT_MAIL_FILTER行是MIMEDefang所必需的。
sh Build sendmail.cf
sh Build install-cf
cd ../..
cd sendmail
sh Build install
cd ../libmilter
sh Build install (创建libmilter库文件供MIMEDefang使用)
对其它的各种应用程序目录,同样用sh Build install安装。
d. 编译MIMEDefang
cd sendmail-8.12.1
mkdir -p /usr/local/include/sendmail
cp -R include/* /usr/local/include/sendmail
cp -R sendmail/*.h /usr/local/include/sendmail
mkdir -p /usr/local/lib
cp obj.Linux.2.4.9-7smp.i686/*/*.a /usr/local/lib
注:用你的obj.Linux.xxxxx平台的文件代替上面的obj.Linux.2.4.9-7smp.i686
cd mimedefang-2.1
./configure
make
make install
e. 设置过滤器规则
在mimedefang-2.1/example下面有各种预定义的规则,你需要拷贝一个到 /etc/mimedefang-filter,下面是我用的规则
基于Sendmail和Perl的邮件附件过滤系统(4)
我拷贝了suggested-minimum-filter-for-windows-clients到/etc/mail下且改成下面的:
$Administrator = itsecurity@yourdomain.com;
$DaemonAddress = itsecurity@yourdomain.com;
$Stupidity{"flatten"} = 0;
$Stupidity{"NoMultipleInlines"} = 0;
sub filter_begin {
}
sub filter {
my($entity, $fname, $ext, $type) = @_;
if (re_match_ext($entity, ^\.(exe|com|bat|vbs|scr|shs|dll|vxd|pif|reg|ocx)$)) {
action_discard();
action_notify_sender("Your message with attachment $fname had been deleted by our mail server because of security issue\n");
return action_quarantine($entity, "The message with attchment $fname was deleted by mail server.");
}
return action_accept();
}
1;
上面的过滤规则表示删除带上面所列出的扩展名的邮件且通知发送者邮件被删除,接收其它所有的邮件。我也更改/usr/local/bin/mimedefang.pl文件以致不要保留邮件附件在/var/spool/MIMEDefang目录中,该文件有详细的自我解释,请编辑该文件去掉保留一份被删除邮件附件在硬盘上的部分。
f. 启动系统并测试
简单地拷贝example目录下的为redhat而写的redhat-sendmail-init-script到 /etc/rc.d/init.d/sendmail并且更改Sendmail启动部分为
/usr/sbin/sendmail -L sm-mta -bd -q30m
/usr/sbin/sendmail -L sm-msp-queue -Ac -q30m
如果你的邮件服务器每天需要处理成千上万的邮件,则考虑拷贝另一个脚本redhat-sendmail-init-script-with-multiplexor到/etc/rc.d/init.d/sendmail,加快处理速度。
最后用/etc/rc.d/init.d/sendmail start启动sendmail,发送带.exe的附件进行测试。