發新話題
打印

[轉貼]Mail Server [postfix] 使用者帳號遭受盜用處理

[轉貼]Mail Server [postfix] 使用者帳號遭受盜用處理

http://blog.xuite.net/tolarku/blog/81551578-Mail+Server+%5Bpostfix%5D+%E4%BD%BF%E7%94%A8%E8%80%85%E5%B8%B3%E8%99%9F%E9%81%AD%E5%8F%97%E7%9B%9C%E7%94%A8+-+%E4%BA%8B%E4%BB%B6%E8%A8%98%E9%8C%84

在詐騙信件實在多到攔不完,所以使用者還是偶爾會收到詐騙信,從早期的英文詐騙信一直到現在的中英文都有,發送主機(來源)也從怪怪的國外IP進展為國內的IP(學術單位的IP居多),這算是APT的一種進化嗎?

持續的觀察與封鎖帳號,大部分的使用者都已經學乖了,但還是有些人會上當......底下就針對攻擊方式簡單做個記錄

先來看個 Mail Server 收信的流程吧!!


 

Manual Page 針對各個 Mail program 的簡單描述

  • smtpd:Postfix SMTP server,Postfix daemon. The SMTP server accepts network connection requests and performs zero or more SMTP transactions per connection.  Each received message is piped through the cleanup(8) daemon, and is placed  into  the incoming queue as one single queue file.  For this mode of operation, the program expects to be run  from the master(8) process manager. 利用 port:25 對外提供接收郵件的服務程式
  • pickup:Postfix local mail pickup,The  pickup(8)  daemon  waits for hints that new mail has been dropped into the maildrop directory, and feeds it into the cleanup(8) daemon.接受本地端使用者送過來的信件
  • cleanupcanonicalize and enqueue Postfix message. The  cleanup(8) daemon processes inbound mail, inserts it into the incoming mail queue, and informs the queue manager of its arrival. 依循 main.cf 訂定的規則,來處理、排隊依序進來的信件。
  • trivial-rewritePostfix address rewriting and resolving daemon. Rewrite an address to standard form, according to the address rewriting context. 針對 recipient address 做重寫的格式化輸出。
  • qmgrPostfix queue manager. The  qmgr(8)  daemon  awaits the arrival of incoming mail and arranges for its delivery via Postfix delivery processes.  The actual mail routing strategy is delegated to the  trivial-rewrite(8)  daemon. Postfix 最重要的排隊處理程式。
  •  

--------------------------------------------------------------------

Mail Queues / 郵件暫存的資料夾

  • incoming:Inbound mail from the network, or mail picked up by the  local  pickup(8)  daemon  from  the maildrop directory. 處理 pickup 收進來的信件,會先放到 incoming 這個資料夾 (以 Binary file 格式儲存,可以用 postcat 來觀看信件內容)。或者 Queue Manager 來不及處理的信件也會暫時先放在這個目錄 /var/spool/postfix/incoming 。
  • activeMessages  that  the queue manager has opened for delivery. Only a limited number of messages is allowed to enter the active queue (leaky bucket strategy, for a fixed delivery rate). 正準備寄送的信件會被放在這個目錄。
  • deferredMail that could not be delivered upon the first attempt. The queue manager implements  exponential backoff by doubling the time between delivery attempts. 傳送失敗的信件會被放到這個目錄,每失敗一次都會利用 exponential backoff 算出應該等待的時間,時間倒數完才會進行下一次的嘗試傳送。
    想要清除這麼目錄下的信件可以參考Postfix Mail Queue - 一些簡單的管理指令」 ,但不建議一次刪除這目錄下的檔案,除非你知道那些信件都是不要的。
  • corruptUnreadable or damaged queue files are moved here for inspection. 損毀或是無法讀取的信件。
  • hold:Messages that are kept "on hold" are kept here until someone sets them free. 管理者可以利用「/usr/sbin/postsuper -h queue_id」來將信件 Hold 住不讓他寄送出去,這時該信件就會被暫時放到這個目錄下。
  • bouncePer-recipient status information about why mail is bounced.  These files are  maintained  by the bounce(8) daemon.
  • deferPer-recipient  status  information about why mail is delayed.  These files are maintained by the defer(8) daemon.
  • tracePer-recipient status information as requested with the Postfix "sendmail  -v"  or  "sendmail -bv" command.  These files are maintained by the trace(8) daemon.

 

-----------------------------------------------------------------------------

既然這篇定義是說「事件記錄」怎麼會前面突然跑出一大堆 mail 的 programs / folders 或流程的描述呢?耐心的看下....


狀況一:當使用者誤信了詐騙信件,導致將自己的帳密提供給別人,依我的觀察~~

## 大約不到一天這個帳號就會被利用來散發廣告信,因為我有擋每封信收件者的上線,所以瞬間可能會有幾百封的廣告信從我的 mail server 送出去。


狀況二:若在狀況一發生時,無法及時處理過了一晚大約會有數千到數萬筆信件 queue 住等待散發垃圾信

##這時反應比較快的 mail server 已經將我的 mail server 阻擋,不再接受我的主機送信過去。像這項的情況需要用

mailq | grep "xxx@123.com" | cut -d " " -f1 | cut -d’*’ -f1 | postsuper -d - 

/usr/sbin/postqueue -p | grep "xxx@123.com" | cut -d " " -f1 | cut -d"*" -f1 | /usr/sbin/postsuper -d -

將特定寄件者的信件清除掉,當然你得同時封鎖該使用者的帳號。


狀況三:在狀況二已封鎖使用者帳號情況下,也清除了 mail Queue 裡的信件,卻持續的被對方利用來寄發垃圾信

##這時是因為 smtpd 的 SASL認證 或 webmail 的 session 還沒過期所致,你可以簡單的重新啟動 postfix / sendmail 來解決。


狀況四:某次發現 mail queue 裡怎麼會有 AA@domain, AX@domain ....ZC@domain 的寄件者送出的信件

##這是某位使用者帳號遭受盜用,通過SASL認證後,其竄改寄件者的來源 (以往都是用單一寄件者來發信,這已進化到以程式來偽裝寄件者,而且每個偽裝的 XX@domain 不多不少都只寄50封信,減少被偵測出來的機會。

##這樣的處理就複雜的多,因為某些 XX@domain 是真的有這個帳號的,所以就必須個別的清除不存在寄件者所送出的信件。而這一次 mail queue 就 queue 住了快10萬筆的信件。


狀況五:這次的情況跟狀況二相似,不同的在於很慢才發現,系統的 loading 已經破百 102.x(使用 w 指令觀察,而一般的狀況 loading 連1都不到,只有 0.1x)

##利用「/usr/sbin/postqueue -p | grep "xxx@123.com" | cut -d " " -f1 | cut -d"*" -f1 | /usr/sbin/postsuper -d -」方式清除特定使用者的信件,用這一行程式清除 mail queue 裡的信件跑了快 6個小時

##一則是 CPU loading 已被超爆,再來是信件大量到信並不是卡在 /var/spool/postfix/active ,而是連 /var/spool/postfix/incoming 都被放了上百萬封,所以單獨清 active 是不夠的, 在 incoming 會再進來,在 deferred 的也會再嘗試傳送

##最後我的作法是先清除非當天的 deferred 信件「find /var/spool/postfix/deferred -type f -mtime +1 -exec rm -f \{\} \;」,為了怕誤刪正常的信件就必須過濾,只將某特定使用者的信才刪除。

 

當遇到使用者帳號遭受盜用的情形,第一時間當然是先封鎖帳號、封鎖發信IP或重新啟動郵件服務程式 postfix / sendmail ,再來就清 active 的 mail queue 跟過了幾天送不出去的信件,如果情形很嚴重則需要去觀察 incoming 目錄下  queue 住的信件。


朋友建議「撈出log裡的sasl認證,找出sasl username對應的mail queue ID」然後利用此方式來刪,找時間寫段 shell script 來試試看。

TOP

發新話題