purk
2002-02-09, 05:40 AM
http://weber.tn.edu.tw/chukk/tech/procmail.htm
Procmail 過濾mail病毒
朱國光 [email protected] 2001/11/11
一、安裝procmail
1. 下載最新版 http://www.procmail.org
2. tar zxvf procmail
3. cd procmail-3.15.2
4. make install
(解除安裝make deinstall)
5. make install-suid (增加安全性)
檢查一下/etc/sendmail.cf是否已將procmail替換原來的mail.local
Mlocal, P=/usr/bin/procmail, F=lsDFMAw5:/|@qSPfhn9, S=10/30, R=20/40,
A=procmail -Y -a $h -d $u
二、設定procmail
vi /etc/procmailrc
MAILDIR=/var/mail
VERBOSE=off
PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin
LOGFILE=/var/log/procmail.log
#SirCam Virus
:0 Bh
*I send you this file in order to have your advice
/dev/null
#Nimda Virus
:0 Bh
* ^Content-Type: audio/x-wav;
* name="readme.exe"
/dev/null
:0 Bh
* ^Content-Type:.*audio/x-wav.*
* name="sample.exe"
/dev/null
Procmail範例
將所有收到主旨有test字元的信放入/var/mail/IN.test檔案中。
:0 b
* ^Subject:.*test
IN.test
參考靜態病毒碼
http://alcor.concordia.ca/topics/email/auto/procmail/spam/tag-contents.html
三、觀察系統日誌統計
mailstat -km procmail.log
- m 合併錯誤至同一行(會刪除原記錄,重新計算)
- l 增加統計平均每人郵件大小,(會刪除原記錄,重新計算)
- k 保持原來的log檔
- o 使用舊的統計資料檔
- t 沒有總統計資料
Procmail-Sanitizer的安裝
朱國光 [email protected] 2001/11/11
目的:
在安裝Procmail後,可加裝Sanitizer,它配合html-trap.procmail ruleset這個perl程式,能自動化程式過濾信件內容,判斷是否可能中毒。
程式下載:
The html-trap.procmail ruleset的取得:HTTP Mirror 1 (USA- WA)
Sanitizer的取得:HTTP Mirror 1 (USA- WA)
安裝步驟:
mkdir sanitizer
cd sanitizer
ftp ftp.tn.edu.tw/linux/procmail/procmail-sanitizer.tar.gz
tar zxvf procmail*
mkdir /etc/procmail
cp html-trap.procmail /etc/procmail/
cp poisoned-files /etc/procmail/
vi /etc/procmailrc
範例檔:
MAILDIR=/var/mail
VERBOSE=off
PATH="/usr/bin:$PATH:/usr/local/bin"
#Nimda Virus
:0 Bh
* ^Content-Type: audio/x-wav;
* name="readme.exe"
/dev/null
SHELL=/bin/sh
POISONED_EXECUTABLES=/etc/procmail/poisoned-files
#寄信通知系統管理者,若需更多人請在postmaster後加逗點再輸入email即可
SECURITY_NOTIFY="postmaster"
#系統通知訊息發布人
SECURITY_NOTIFY_VERBOSE="postmaster"
#寄信通知寄件人
SECURITY_NOTIFY_SENDER=YES
#寄信通知寄件人訊息內容
SECURITY_NOTIFY_SENDER="/etc/procmail/policy.txt"
#寄信通知給收件人的訊息內容
SECURITY_NOTIFY_RECIPIENT="/etc/procmail/quarantined.txt"
#可放20字元長度以下亂數值,增加安全性
SECRET="hgsfd9734965q34o2ldgbl"
#檢疫隔離信件檔位置
SECURITY_QUARANTINE=/var/spool/mail/quarantine
#巨集病毒掃描積分門檻,一般而言,中毒信件得分通常都會超過100分
POISONED_SCORE=100
#巨集病毒掃描日誌檔位置
SCORE_HISTORY=/var/log/scores
LOGFILE=/var/log/procmail.log
INCLUDERC=/etc/procmail/html-trap.procmail
touch /var/log/procmail.log
chmod 644 /var/log/procmail.log
touch /var/spool/mail/quarantine
chmod 644 /var/spool/mail/quarantine
touch /var/log/scores
chmod 644 /var/log/scores
vi /etc/procmail/policy.txt
範例:
這封信是系統自動發出的訊息。
您的信件可能含有病毒,系統目前已加以隔離處理,請儘速掃毒後再重新寄出此封信。
vi /etc/procmail/quarantined.txt
有人寄病毒信給您,系統已加以攔截,信件相關訊息如下。
抓主旨為空白,信件大於20000行的執行檔範例:
:0
* > 20000
* !^Subject:
* ^Content-Type:.*multipart/mixed;
{
:0 B hfi
* ^Content-Disposition:.*\.EXE
* ^Content-Type:.*\.EXE
| formail -A "X-Content-Security: [$HOST] NOTIFY" \
-A "X-Content-Security: [$HOST] QUARANTINE" \
-A "X-Content-Security: [$HOST] REPORT: Trapped anonymous .EXE"
}
以Procmail-Gateway過濾寄出信件病毒之安裝
朱國光 [email protected] 2001/11/11
簡介說明
在安裝Procmail及Sanitizer後,系統都祇能處理寄進伺服器內的信件,無法處理利用郵件伺服器來寄出病毒信,因此在安裝Procmail-Gateway修改sendmail.cf後可以在伺服器寄信前攔截掉病毒信,減輕網路的負荷。
確定procmail已安裝
Mlocal, P=/usr/bin/procmail, F=lsDFMAw5:/|@qSPfhn9, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,
T=DNS/RFC822/X-Unix,
A=procmail -t -Y -a $h -d $u
確定毒藥檔路徑及檔案存在
/etc/procmail/poisoned-files
確定陷阱檔路徑及檔案存在
/etc/procmail/html-trap.procmail
編寫系統回信警告通知檔
vi /etc/procmail/policy.txt
內容範例:
這封信是系統自動發出的訊息。
您的信件可能中毒,系統已加以隔離處理,請儘速掃毒後再重新寄此封信。
vi /etc/procmail/quarantined.txt
有人寄病毒信給您,系統已加以攔截,信件相關訊息如下。
確定檔案權限
touch /var/log/procmail.log <--檔案不存在時才touch
chmod 644 /var/log/procmail.log
touch /var/spool/mail/quarantine <--檔案不存在時才touch
chmod 644 /var/spool/mail/quarantine
touch /var/log/scores <--檔案不存在時才touch
chmod 644 /var/log/scores
修改procmailrc
vi /etc/procmailrc
範例檔如下:
MAILDIR=/var/mail
VERBOSE=off
PATH="/usr/bin:$PATH:/usr/local/bin"
#Nimda Virus
:0 Bh
* ^Content-Type: audio/x-wav;
* name="readme.exe"
/dev/null
SHELL=/bin/sh
POISONED_EXECUTABLES=/etc/procmail/poisoned-files
#寄信通知系統管理者,若需更多人請在postmaster後加逗點再輸入email即可
SECURITY_NOTIFY="postmaster"
#系統通知訊息發布人
SECURITY_NOTIFY_VERBOSE="postmaster"
#寄信通知寄件人
SECURITY_NOTIFY_SENDER=YES
#寄信通知寄件人訊息內容
SECURITY_NOTIFY_SENDER="/etc/procmail/policy.txt"
#寄信通知給收件人的訊息內容
SECURITY_NOTIFY_RECIPIENT="/etc/procmail/quarantined.txt"
#可放20字長度以下字元亂數值,增加安全性
SECRET="sfd9734965q34o2ldgbl"
#檢疫隔離信件檔位置
SECURITY_QUARANTINE=/var/spool/mail/quarantine
#巨集病毒掃描積分門檻,一般而言,中毒信件得分通常都會超過100分
POISONED_SCORE=100
#巨集病毒掃描日誌檔位置
SCORE_HISTORY=/var/log/scores
LOGFILE=/var/log/procmail.log
INCLUDERC=/etc/procmail/html-trap.procmail
修改sendmail.cf
vi /etc/sendmail.cf
在檔案最後加上以下的內容:
注意:複製/貼上以下內容有時會因為html tag的問題造成sendmail服務無法重新啟動,此時可下載完整sendmail.cf範例檔 (右鍵/另存目標)至本機再複製/貼上至伺服器或上傳至伺服器。
#在M
##### @(#)procmail.m4 8.11 (Berkeley) 5/19/1998 #####
Mprocmail, P=/usr/bin/procmail, F=DFMSPhnu9, S=11/31, R=21/31, T=DNS/RFC822/X-Unix,
A=procmail -f- -Y -m $h $f $u
# (空此行一定要先空tab)
# 在my name for error messages設定的後面加上下面兩行
# Avoid host map lookups if address has this pseudo-domain on it
CPprocmail
# 在Ruleset 98後面加上下面設定
# Filter all mail through procmail
#
# Strip the pseudo-domain and continue (already gone through the filter)
R$*<@$+.procmail>$* $@ $1<@$2.>$3
R$*<@$+.procmail.>$* $@ $1<@$2.>$3
#
# No pseudo-domain, send to filtering mailer
R$*<@$+.>$* $#procmail $@/etc/procmail/filter.rc $:$1<@$2.procmail>$3
R$*<@$+>$* $#procmail $@/etc/procmail/filter.rc $:$1<@$2.procmail>$3
########################################################################
建立過濾檔filter.rc
vi /etc/procmail/filter.rc
範例檔內容如下:
LOGFILE=/var/log/procmail.log
NL="
"
LOGABSTRACT=no
POISONED_EXECUTABLES=/etc/procmail/poisoned-files
INCLUDERC=/etc/procmail/html-trap.procmail
:0 # re-send the message
! -oi -f "$@"
Procmail 過濾mail病毒
朱國光 [email protected] 2001/11/11
一、安裝procmail
1. 下載最新版 http://www.procmail.org
2. tar zxvf procmail
3. cd procmail-3.15.2
4. make install
(解除安裝make deinstall)
5. make install-suid (增加安全性)
檢查一下/etc/sendmail.cf是否已將procmail替換原來的mail.local
Mlocal, P=/usr/bin/procmail, F=lsDFMAw5:/|@qSPfhn9, S=10/30, R=20/40,
A=procmail -Y -a $h -d $u
二、設定procmail
vi /etc/procmailrc
MAILDIR=/var/mail
VERBOSE=off
PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin
LOGFILE=/var/log/procmail.log
#SirCam Virus
:0 Bh
*I send you this file in order to have your advice
/dev/null
#Nimda Virus
:0 Bh
* ^Content-Type: audio/x-wav;
* name="readme.exe"
/dev/null
:0 Bh
* ^Content-Type:.*audio/x-wav.*
* name="sample.exe"
/dev/null
Procmail範例
將所有收到主旨有test字元的信放入/var/mail/IN.test檔案中。
:0 b
* ^Subject:.*test
IN.test
參考靜態病毒碼
http://alcor.concordia.ca/topics/email/auto/procmail/spam/tag-contents.html
三、觀察系統日誌統計
mailstat -km procmail.log
- m 合併錯誤至同一行(會刪除原記錄,重新計算)
- l 增加統計平均每人郵件大小,(會刪除原記錄,重新計算)
- k 保持原來的log檔
- o 使用舊的統計資料檔
- t 沒有總統計資料
Procmail-Sanitizer的安裝
朱國光 [email protected] 2001/11/11
目的:
在安裝Procmail後,可加裝Sanitizer,它配合html-trap.procmail ruleset這個perl程式,能自動化程式過濾信件內容,判斷是否可能中毒。
程式下載:
The html-trap.procmail ruleset的取得:HTTP Mirror 1 (USA- WA)
Sanitizer的取得:HTTP Mirror 1 (USA- WA)
安裝步驟:
mkdir sanitizer
cd sanitizer
ftp ftp.tn.edu.tw/linux/procmail/procmail-sanitizer.tar.gz
tar zxvf procmail*
mkdir /etc/procmail
cp html-trap.procmail /etc/procmail/
cp poisoned-files /etc/procmail/
vi /etc/procmailrc
範例檔:
MAILDIR=/var/mail
VERBOSE=off
PATH="/usr/bin:$PATH:/usr/local/bin"
#Nimda Virus
:0 Bh
* ^Content-Type: audio/x-wav;
* name="readme.exe"
/dev/null
SHELL=/bin/sh
POISONED_EXECUTABLES=/etc/procmail/poisoned-files
#寄信通知系統管理者,若需更多人請在postmaster後加逗點再輸入email即可
SECURITY_NOTIFY="postmaster"
#系統通知訊息發布人
SECURITY_NOTIFY_VERBOSE="postmaster"
#寄信通知寄件人
SECURITY_NOTIFY_SENDER=YES
#寄信通知寄件人訊息內容
SECURITY_NOTIFY_SENDER="/etc/procmail/policy.txt"
#寄信通知給收件人的訊息內容
SECURITY_NOTIFY_RECIPIENT="/etc/procmail/quarantined.txt"
#可放20字元長度以下亂數值,增加安全性
SECRET="hgsfd9734965q34o2ldgbl"
#檢疫隔離信件檔位置
SECURITY_QUARANTINE=/var/spool/mail/quarantine
#巨集病毒掃描積分門檻,一般而言,中毒信件得分通常都會超過100分
POISONED_SCORE=100
#巨集病毒掃描日誌檔位置
SCORE_HISTORY=/var/log/scores
LOGFILE=/var/log/procmail.log
INCLUDERC=/etc/procmail/html-trap.procmail
touch /var/log/procmail.log
chmod 644 /var/log/procmail.log
touch /var/spool/mail/quarantine
chmod 644 /var/spool/mail/quarantine
touch /var/log/scores
chmod 644 /var/log/scores
vi /etc/procmail/policy.txt
範例:
這封信是系統自動發出的訊息。
您的信件可能含有病毒,系統目前已加以隔離處理,請儘速掃毒後再重新寄出此封信。
vi /etc/procmail/quarantined.txt
有人寄病毒信給您,系統已加以攔截,信件相關訊息如下。
抓主旨為空白,信件大於20000行的執行檔範例:
:0
* > 20000
* !^Subject:
* ^Content-Type:.*multipart/mixed;
{
:0 B hfi
* ^Content-Disposition:.*\.EXE
* ^Content-Type:.*\.EXE
| formail -A "X-Content-Security: [$HOST] NOTIFY" \
-A "X-Content-Security: [$HOST] QUARANTINE" \
-A "X-Content-Security: [$HOST] REPORT: Trapped anonymous .EXE"
}
以Procmail-Gateway過濾寄出信件病毒之安裝
朱國光 [email protected] 2001/11/11
簡介說明
在安裝Procmail及Sanitizer後,系統都祇能處理寄進伺服器內的信件,無法處理利用郵件伺服器來寄出病毒信,因此在安裝Procmail-Gateway修改sendmail.cf後可以在伺服器寄信前攔截掉病毒信,減輕網路的負荷。
確定procmail已安裝
Mlocal, P=/usr/bin/procmail, F=lsDFMAw5:/|@qSPfhn9, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,
T=DNS/RFC822/X-Unix,
A=procmail -t -Y -a $h -d $u
確定毒藥檔路徑及檔案存在
/etc/procmail/poisoned-files
確定陷阱檔路徑及檔案存在
/etc/procmail/html-trap.procmail
編寫系統回信警告通知檔
vi /etc/procmail/policy.txt
內容範例:
這封信是系統自動發出的訊息。
您的信件可能中毒,系統已加以隔離處理,請儘速掃毒後再重新寄此封信。
vi /etc/procmail/quarantined.txt
有人寄病毒信給您,系統已加以攔截,信件相關訊息如下。
確定檔案權限
touch /var/log/procmail.log <--檔案不存在時才touch
chmod 644 /var/log/procmail.log
touch /var/spool/mail/quarantine <--檔案不存在時才touch
chmod 644 /var/spool/mail/quarantine
touch /var/log/scores <--檔案不存在時才touch
chmod 644 /var/log/scores
修改procmailrc
vi /etc/procmailrc
範例檔如下:
MAILDIR=/var/mail
VERBOSE=off
PATH="/usr/bin:$PATH:/usr/local/bin"
#Nimda Virus
:0 Bh
* ^Content-Type: audio/x-wav;
* name="readme.exe"
/dev/null
SHELL=/bin/sh
POISONED_EXECUTABLES=/etc/procmail/poisoned-files
#寄信通知系統管理者,若需更多人請在postmaster後加逗點再輸入email即可
SECURITY_NOTIFY="postmaster"
#系統通知訊息發布人
SECURITY_NOTIFY_VERBOSE="postmaster"
#寄信通知寄件人
SECURITY_NOTIFY_SENDER=YES
#寄信通知寄件人訊息內容
SECURITY_NOTIFY_SENDER="/etc/procmail/policy.txt"
#寄信通知給收件人的訊息內容
SECURITY_NOTIFY_RECIPIENT="/etc/procmail/quarantined.txt"
#可放20字長度以下字元亂數值,增加安全性
SECRET="sfd9734965q34o2ldgbl"
#檢疫隔離信件檔位置
SECURITY_QUARANTINE=/var/spool/mail/quarantine
#巨集病毒掃描積分門檻,一般而言,中毒信件得分通常都會超過100分
POISONED_SCORE=100
#巨集病毒掃描日誌檔位置
SCORE_HISTORY=/var/log/scores
LOGFILE=/var/log/procmail.log
INCLUDERC=/etc/procmail/html-trap.procmail
修改sendmail.cf
vi /etc/sendmail.cf
在檔案最後加上以下的內容:
注意:複製/貼上以下內容有時會因為html tag的問題造成sendmail服務無法重新啟動,此時可下載完整sendmail.cf範例檔 (右鍵/另存目標)至本機再複製/貼上至伺服器或上傳至伺服器。
#在M
##### @(#)procmail.m4 8.11 (Berkeley) 5/19/1998 #####
Mprocmail, P=/usr/bin/procmail, F=DFMSPhnu9, S=11/31, R=21/31, T=DNS/RFC822/X-Unix,
A=procmail -f- -Y -m $h $f $u
# (空此行一定要先空tab)
# 在my name for error messages設定的後面加上下面兩行
# Avoid host map lookups if address has this pseudo-domain on it
CPprocmail
# 在Ruleset 98後面加上下面設定
# Filter all mail through procmail
#
# Strip the pseudo-domain and continue (already gone through the filter)
R$*<@$+.procmail>$* $@ $1<@$2.>$3
R$*<@$+.procmail.>$* $@ $1<@$2.>$3
#
# No pseudo-domain, send to filtering mailer
R$*<@$+.>$* $#procmail $@/etc/procmail/filter.rc $:$1<@$2.procmail>$3
R$*<@$+>$* $#procmail $@/etc/procmail/filter.rc $:$1<@$2.procmail>$3
########################################################################
建立過濾檔filter.rc
vi /etc/procmail/filter.rc
範例檔內容如下:
LOGFILE=/var/log/procmail.log
NL="
"
LOGABSTRACT=no
POISONED_EXECUTABLES=/etc/procmail/poisoned-files
INCLUDERC=/etc/procmail/html-trap.procmail
:0 # re-send the message
! -oi -f "$@"