zen cart的漏洞和它一樣流行.但是因特網上還是有N多的站沒有升級,即使有補丁發佈,那些漏洞依然大門敞開,再好的系統管理員也無用,因爲後門總是開着啊.
今天碰到這樣的一個問題
在新產生新訂單時,magento後臺沒有發確認信。我直接的反應是不可能啊,因爲一直都很正常啊,而且沒有修改過代碼?仔細一想,還有一個可以肯定就是昨天有收到一封郵件,一個客戶說收到了新訂單確認郵件,但是沒有進入付款頁面。所以這就有茅盾。進一步確認是magento網站的contact us可以發出郵件。
查看mailog發現服務器在發大量的郵件。懷疑服務器讓人利用發垃圾郵件,首先想到的是zen cart網站。查看apache的日誌,確認發現有對zen cart的tell-a-friend頁面的大量訪問量。
關閉sendmail
清空
/var/spool/mqueue
/var/spool/clientqueue
將發垃圾郵件的IP從apache的access log中提取,暫時用iptable規則drop掉所來息這幾個IP的的請求
啓動sendmail
最重要的是如何完全的zen cart的給朋友發郵件推薦產品的功能徹底關閉掉
首先,關閉掉所有產品頁面的"tell a friend”按鈕
菜單Catalog 子菜單 Product Types 點擊 Edit Layout 按鈕 在頁面中選擇 Show Product Tell A Friend Button 這個選項編輯,修改爲 false然後單擊 update 保存
其次,關閉掉所有的"tell a friend”的sidebox
選項菜單Tools 子菜單 Layout Box Controller,在頁面中找到 "sideboxes/tell_a_friend.php",選中所有的off,保存
這其實還不夠,知道地址的人還是可以進入到發郵件的頁面。所以,要在代碼中禁用發郵件的功能。這不可能,因爲發郵件的功能還是要用的。那什麼辦?有兩個選項:
1,利用zen cart自帶的配置機制,但是在後臺是無法做到的,我是在查看代碼之後看註釋看到的
我用grep -r 'mail(' includes搜索php的mail函數,找到文件 includes/functions/functions_email.php,看到這段代碼
...
...
/**
* Send email (text/html) using MIME. This is the central mail function.
* If using "PHP" transport method, the SMTP Server or other mail application should be configured correctly in server's php.ini
*
* @param string $to_name The name of the recipient, e.g. "Jim Johanssen"
* @param string $to_email_address The email address of the recipient, e.g. [email protected]
* @param string $email_subject The subject of the eMail
* @param string $email_text The text of the email, may contain HTML entities
* @param string $from_email_name The name of the sender, e.g. Shop Administration
* @param string $from_email_adrdess The email address of the sender, e.g. [email protected]
* @param array $block Array containing values to be inserted into HTML-based email template
* @param string $module The module name of the routine calling zen_mail. Used for HTML template selection and email archiving.
* This is passed to the archive function denoting what module initiated the sending of the email
* @param array $attachments_list Array of attachment names/mime-types to be included (this portion still in testing, and not fully reliable)
**/
function zen_mail($to_name, $to_address, $email_subject, $email_text, $from_email_name, $from_email_address, $block=array(), $module='default', $attachments_list='' )
...
...
// ignore sending emails for any of the following pages
// (The EMAIL_MODULES_TO_SKIP constant can be defined in a new file in the "extra_configures" folder)
if (defined('EMAIL_MODULES_TO_SKIP') && in_array($module,explode(",",constant('EMAIL_MODULES_TO_SKIP')))) return false;
// check for injection attempts. If new-line characters found in header fields, simply fail to send the message
foreach(array($from_email_address, $to_address, $from_email_name, $to_name, $email_subject) as $key=>$value) {
if (eregi("/r",$value) || eregi("/n",$value)) return false;
}
...
...
我先是看到$module參數,雖然註釋說是爲了調用模板之用,但是我想即使zen cart沒做,我們自己要修改也應該是要利用這個參數來實現。但是從 (The EMAIL_MODULES_TO_SKIP constant can be defined in a new file in the "extra_configures" folder) 表明,我們只要在extra_configures目錄下定義一個EMAIL_MODULES_TO_SKIP這個常量就OK了,我是這樣做的:
define('EMAIL_MODULES_TO_SKIP', 'tell_a_friend,tell_a_friend_extra');
不過,在我測試的這個版本中,1.3.8中即使這樣設置後,也會提示發送成功,但是其實是沒有發送的。
另外一種方法就是禁止對tell_a_friend頁面的請求,或者通過mod_rewrite將對這個頁面的請求重定向到產品頁或首頁。