qmail+vpopmail郵件過濾(練習篇)
發表于:2007-07-02來源:作者:點擊數:
標簽:
最近正在研究qmail+vpopmail的郵件過濾,找了很多相關的軟件,都覺得不好,主要是討厭他們的依附關系太復雜,有的甚至還要對qmail進行改動,嫌太麻煩。 然后在inter7.com發現了eps,目前是0.5。研究了一下,搞了一個相當暴力的過濾方法出來,有興趣的就看看吧
最近正在研究qmail+vpopmail的郵件過濾,找了很多相關的軟件,都覺得不好,主要是討厭他們的依附關系太復雜,有的甚至還要對qmail進行改動,嫌太麻煩。
然后在inter7.com發現了eps,目前是0.5。研究了一下,搞了一個相當暴力的過濾方法出來,有興趣的就看看吧。
練習的前提是qmail+vpopmail已經裝好,而且正常運作。
首先當然是
下載eps了,在Inter7.com下載。展
開源代碼包后
make
make install
就可以了。
然后寫了這個小程序mime.c
#include <s
tdio.h>
#include <eps.h>
char *exts[]={
".
vbs",
".scr",
".exe",
".com",
NULL
};
int efilter_check_mime(struct mime_t *m)
{
int i = 0;
int p = 0;
if (!(m->2003104134820.htm))
return 0;
for (i = 0; exts[i]; i++) {
if (m->2003104134820.htm) {
p = strstr(m->2003104134820.htm, exts[i]);
if (p) {
return 1;
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
int ret = 0;
char *l = NULL;
struct mime_t *m = NULL;
struct header_t *h = NULL;
struct eps_t *eps = NULL;
if (argc < 2)
eps = eps_begin(INTERFACE_S
TDIN, NULL);
else
eps = eps_begin(INTERFACE_FILENAME, argv[1]);
if (!eps)
return 1;
/*
Examine headers for Content/
MIME information
Pass information off to EPS@# internals
*/
for (h = eps_next_header(eps); h; h = eps_next_header(eps)) {
if ((h->name) && (h->data))
eps_header_internal(eps, h);
}
/*
..skip the message body since we@#re not interested in
it.
*/
for (l = eps_next_line(eps, BREAK_STOP); l; l = eps_next_line(eps, BREAK_STOP));
eps_init_mime(eps);
for (m = eps_next_mime(eps); m; m = eps_next_mime(eps)) {
if (efilter_check_mime(m))
printf("rejected");
}
eps_end(eps);
return 0;
}
功能挺簡單的,就是檢查電子郵件的附件,但凡發現.vbs .scr .exe .com的附件,都提示rejected。編譯,安裝。
gcc -g -I/usr/include/eps -L/usr/lib -DVERSION="1.2" -o mime mime.c -leps
復制到~vpopmail/bin并chown vpopmail.vchkpw mime
然后建立一個filter.sh文件,也是在~vpopmail/bin目錄,屬主和mime一樣了。
#!/bin/sh
ISVIRUS=`/var/vpopmail/bin/mime`
if [ X"${ISVIRUS}" != X"rejected" ]; then
/var/vpopmail/bin/vdelivermail @#@# bounce-no-mailbox
fi
最后修該~vpopmail/domains/yourdomain/里面的.qmail-default文件
把原本為
| /var/vpopmail/bin/vdelivermail @#@# bounce-no-mailbox
改成
| /var/vpopmail/bin/filter.sh
就可以了。
實現的手段很暴力,凡是附件中含有.vbs .exe .com .scr的都整個郵件drop掉了。沒有辦法啦,我還沒有全面的研究清楚eps的功能,而且它還沒有發展完全。不過先玩玩啦。
原文轉自:http://www.kjueaiud.com