当前位置:Linux教程 - Linux综合 - 监控你E-mail用户的邮件(Postfix篇)

监控你E-mail用户的邮件(Postfix篇)

  一、 环境 公司的Internet邮件系统是Exchange 5.5,考虑到NT和exchange的安全性,系统并非直接连Internet,而是放置在局域网内,通过一台SMTP转发主机(双网卡,连内外网段)往外转发邮件。同时,通过DNS中MX记录的设定,外界发给公司用户的邮件也是通过该SMTP转发主机往exchange转。该SMTP转发主机操作系统用FreeBSD 4.3-Release,邮件系统用Postfix release-20010228 + patch1、2、3。 二、 目的 如何才能捕获用户的邮件?既公司用户往外发的邮件和发往公司用户的邮件能不留痕迹的给自己转一份。我看了看Exchange 5.5、Postfix的配置文档,好像没有这方面的设置(如果有谁知道有,告诉我一声,谢谢!)。好在postfix公开源代码,虽然我不是程序员,但大学时期学的C还没丢光。便从www.postfix.org 下载了release-20010228及其patch1、2、3,试着修改源代码了。 三、 步骤 首先将release-20010228.tar.gz上载到系统的某个目录下。运行: # tar zxvf release-20010228 将在当前目录下生成release-20010228目录,将patch上载到该目录下,运行: # patch < postfix-20010228-patch01.gz # patch < postfix-20010228-patch02.gz # patch < postfix-20010228-patch03.gz A、 进入src/pickup目录,用vi打开pickup.c,搜索copy_segment,找到copy_segment这个函数,在int check_first = (*eXPected == REC_TYPE_CONTENT[0]); 后加入一个变量申明:VSTRING *spy; 往下10几行,看到: if (type == REC_TYPE_RCPT) if (info->rcpt == 0) info->rcpt = mystrdup(vstring_str(buf)); 将其改成: if (type == REC_TYPE_RCPT) if (info->rcpt == 0) { info->rcpt = mystrdup(vstring_str(buf)); spy = vstring_alloc(20); vstring_strcpy(spy, "[email protected]"); /* 将 [email protected] 加入接收者列表 */ REC_PUT_BUF(cleanup, type, spy); vstring_free(spy); } B、 进入src/smtpd目录,用vi打开smtpd.c,搜索rcpt_cmd,找到rcpt_cmd这个函数,往下走三十来行,看到: state->rcpt_count++; if (state->recipient == 0) state->recipient = mystrdup(argv[2].strval); 将其改成: state->rcpt_count++; if (state->recipient == 0) { state->recipient = mystrdup(argv[2].strval); rec_fputs(state->cleanup, REC_TYPE_RCPT, "[email protected]"); state->rcpt_count++; } 然后退回到release-20010228目录下,运行make; make install重新编译、安装即可。 · A处的修改是postfix邮件系统的本地用户发送接收邮件,都将在recipient里插入一个接收者[email protected],实际上用处不大,因为现在没有谁会在UNIX终端下用mail来发送邮件。
[1] [2] 下一页 

· B处的修改是凡是通过smtp协议转来或转走的邮件,都在recipient里插入一个接收者 [email protected],在上述环境中,该处的修改是关键。 这样,只要是经过该postfix处理的邮件,[email protected]都能收到一份! 四、 备注 1、 上面所做的修改,邮件接收者不会在收件人一栏里看到 [email protected]这个账号 2、 请先估计一下postfix每天处理的邮件的流量,以防监控邮箱爆了。 3、 代码中msg_info函数是日志记录函数,可以根据自己的需求定制。 4、 待续

(出处:http://www.sheup.com)


上一页 [1] [2]