Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > บทความจากสมาชิก > สร้าง Exim Spam Filter สร้างตัวดักป้องกัน Spam ใน Mail Server ของ exim



 
Clound SSD Virtual Server

สร้าง Exim Spam Filter สร้างตัวดักป้องกัน Spam ใน Mail Server ของ exim

สร้าง Exim Spam Filter สร้างตัวดักป้องกัน Spam ใน Mail Server ของ Exim บทความนี้ไม่เกี่ยวข้องกับการเขียนโปรแกรมบนภาษา php หรือ .net แต่อย่างใด แต่เป็นปัญหาที่พบเจอกันบ่อย ๆ ของเหล่า admin ผู้ที่มี Server หรือดูแล Server ทั้งหลาย ที่เป็น Linux Server และใช้ Exim เป็น Mail Server ในการรับส่งอีเมล์ เกิดอยู่ดี ๆ มีอีเมล์ส่งออกจากเครื่อง โดยไม่รู้ที่มาหรือที่ไป หรือในกรณีที่ใน Server มีโดเมนหลายตัว ถ้ามีการส่ง Spam โดยใน Content ระบุชื่อโดเมนว่าส่งจาก โดเมนใดก็ไม่ใช่ปัญหาที่จะหาต้นตอเจอแต่อย่างใด แต่ปัญหาที่เจอคือมีอีเมล์เป็นพัน ๆ หรือหมื่น ๆ ฉบับส่งออกจากเครื่อง โดยหาต้นตอไม่เจอว่าส่งจาก user อะไร ยิ่งอีเมล์ถูกส่งออกมากเท่าไหร่ก็จะถูกส่งไปค้างไว้อยู่ที่ Queue ยิ่งค้างมาก Server ก็ทำงานหนัก สุดท้ายถึงกับ Server โหลดและล่มกันไปได้แบบง่าย ๆ ซึ่งปัญหานี้คนที่ดูแล Server หรือทำ Host คงจะพบเจอกันแทบทุกราย

Exim Spam Filter

ตัวอย่างอีเมล์ที่ค้างอยู่ใน Queue ของ Direct Admin ซึ่งเข้าใจว่าน่าจะถูกตีกลับมาแล้วค้างอยู่ใน Queue

ตัวอย่างรายละเอียดของอีเมล์ที่ค้างใน Queue

Return-path: <[email protected]>
Received: from ppp-61-90-30-226.revip.asianet.co.th ([61.90.30.226] helo=w3.org)
by ns1.thaicreate.com with esmtp (Exim 4.71)
(envelope-from <[email protected]>)
id 1SUpsE-0006WC-0h
for [email protected]; Thu, 17 May 2012 08:51:26 +0700
From: "[email protected]
To: [email protected]
Subject: Delivery reports about your e-mail
Date: Thu, 17 May 2012 08:50:10 +0700
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_0012_F46CFD47.9B88CB08"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

This is a multi-part message in MIME format.

------=_NextPart_000_0012_F46CFD47.9B88CB08
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit

Dear user [email protected], administration of w3.org would like to let you know that:

We have received reports that your e-mail account was used to send a large amount of junk email during the last week.
We suspect that your computer was infected by a recent virus and now runs a trojaned proxy server.

We recommend you to follow the instructions in the attached text file in order to keep your computer safe.

Have a nice day,
w3.org support team.


จากข้อความในอีเมล์จะเห็นว่ามีการใช้ Server ของ thaicreate ซึ่งผมตั้ง NS ว่า ns1.thaicreate.com ส่งอีเมล์จาก [email protected] ไปยัง [email protected] ซึ่งเข้าใจได้ทันทีว่าน่าจะมี script หรือไวรัสฝั่งไว้ใน Server หรือมีการแอบใช้ SMTP ของ Server ในการแอบส่งอีเมล์ Spam ออกจาก Server

สำหรับการแก้ไขปัญหาที่ถูกต้องคือจะต้องหาตนตอของสาเหตุให้ถูกต้อง ซึ่งเข้าใจว่าน่าจะมีการเรียกใช้งานโดยส่งผ่าน Microsoft Outlook Express 6.00.2600.0000 วิธีแก้ไขคืออาจจะต้องไปตามแก้ไขพวกรหัสผ่านของ Account ทั้งหมด ตรวจสอบไฟล์บน Server รวมทั้งเครื่องของ Client ที่ทำการเชื่อมต่อกับ Account ก็จะต้องทำการตรวจสอบไวรัส Scan ไวรัส

แต่ในกรณีที่ยังหาต้นตอไม่เจอจริง ๆ ซึ่งตอนนี้ผมก็เจอปัญหาเช่นเดียวกัน มีวิธีแก้ไขที่ปลายเหตุแบบง่าย ๆ ก็คือการเขียน Spam Filter กำจัดอีเมล์ที่ไม่พึงประสงค์ ด้วยการกรองถ้าอีเมล์ฉบับไหน มีข้อคามหรือเนื้อหาตามที่เขียนเงื่อนไขไว้ ก็ให้ลบออกจาก Queue โดยไม่ส่งออกจาก Server ซึ่งวิธีนี้จะต้องอาศัยความชำนาญและประสบการณ์ เพราะถ้าเกิดเขียนผิดขึ้นมา อาจจะถึงขั้น ไม่สามารถ Start ตัว Exim ขึ้นมา หรือไม่ก็อีเมล์ไม่สามารถส่งออกไปได้ ถ้าเป็นอีเมล์สำคัญ ๆ ก็เสียหายค่อนข้างเยอะเหมือนกัน แต่แนะนำว่าก่อนการ Config หรือแก้ไขไฟล์ของ exim ต่าง ๆ ควรทำการ backup ไว้ทุกครั้ง








ขั้นที่ 1 ตรวจสอบไฟล์ exim.conf

ถ้าไม่รู้ว่าถูกติดตั้ง path ไว้ที่ไหนสามารถใช้คำสั่ง

# find / -name exim.conf


เปิดไฟล์ exim.conf เพื่อเปิดการใช้งาน system filter

exim.conf
# General Exim Filter

#system_filter = /etc/exim/exim.filter


ให้เปิดการใช้งานด้วยการ Remove เครื่องหมาย # ออก

exim.conf
# General Exim Filter

system_filter = /etc/exim/exim.filter


และจะเห็นว่าไฟล์ที่เก็บพวก filter ถูกจัดเก็บไว้ใน /etc/exim/exim.filter

ขั้นที่ 2 เขียน spam filter ลงในไฟล์ exim.filter

โดยเพิ่มหลังแถว ๆ ตัวอย่างของ exim filter ซึ่งตะมีตัวอย่างให้ดู 2-3 ตัวอย่าง เช่น

/etc/exim/exim.filter
# Fudge to catch Klez virus (mal formed mime details, unquoted filename with spaces)
if $message_body matches "Content-Type:(?>\\\\s*)[\\\\w-]+/[\\\\w-]+;\\\\s*(?:name)=([^\" ]+ [^\"]*\\\\.(?:ad[ep]|ba[st]|chm|cmd|com|cpl|crt|eml|exe|hlp|hta|in[fs]|isp|jse?|lnk|md[be]|ms[cipt]|pcd|pif|reg|sc[mrt]|shs|url|vb[se]?|ws[fhc]))[\\\\s;]"
then
seen finish
endif


// เพิ่มแถว ๆ ตรงนี้


Exim Spam Filter

ดูรูปประกอบ


เพิ่มคำสั่ง

logfile /var/log/filter.log 0644

if(
	$header_From: contains "@w3.org"
)
then

logwrite "Block $header_from "
	seen finish
endif


อธิบาย
logfile /var/log/filter.log 0644 (สร้าง Log ไฟล์จัดเก็บไว้ที่นี่)
$header_from: contains "@w3.org" (ถ้า $header_from มีคำว่า @w3.org )
logwrite "Block $header_from " (เขียน Log ลงในไฟล์)
seen finish (สิ้นสุดการทำงานโดยลบมันออกจาก Queue ไปเลยโดยไม่ต้องส่ง)


อธิบายค่าตัวแปรคร่าว ๆ สำหรับการเขียนดัก Filter อ้างถึงจากอีเมล์จากข้างบน


$Return-path
Return-path: <[email protected]>


$header_Received
Received: from ppp-61-90-30-226.revip.asianet.co.th ([61.90.30.226] helo=w3.org)
by ns1.thaicreate.com with esmtp (Exim 4.71)
(envelope-from <[email protected]>)
id 1SUpsE-0006WC-0h
for [email protected]; Thu, 17 May 2012 08:51:26 +0700


$header_From หรือ $sender_address


$header_To


$header_Subject
Subject: Delivery reports about your e-mail


$header_Date
Date: Thu, 17 May 2012 08:50:10 +0700


$header_MIME-Version
MIME-Version: 1.0


$header_Content-Type
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_0012_F46CFD47.9B88CB08"


$header_X-Priority
X-Priority: 3


$header_X-MSMail-Priority
X-MSMail-Priority: Normal


$header_X-Mailer
X-Mailer: Microsoft Outlook Express 6.00.2600.0000


$header_X-MIMEOLE
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000


$message_body
This is a multi-part message in MIME format.

------=_NextPart_000_0012_F46CFD47.9B88CB08
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit

Dear user [email protected], administration of w3.org would like to let you know that:

We have received reports that your e-mail account was used to send a large amount of junk email during the last week.
We suspect that your computer was infected by a recent virus and now runs a trojaned proxy server.

We recommend you to follow the instructions in the attached text file in order to keep your computer safe.

Have a nice day,
w3.org support team.



จากตัวอย่างเป็นการเรียกค่าตัวแปรในแต่ล่ะส่วน ซึ่งเราสามารถนำค่าตัวแปรเหล่านี้เพื่อไปเขียน filter ได้

ตัวอย่างการเขียนหลาย ๆ เงื่อนไข

logfile /var/log/filter.log 0644

if $header_from: contains "MAILER-DAEMON"
	or $header_from: contains "postmaster@"
	or $header_from: contains "noreply@"
	or $header_Received: contains "amazon.com"
	or $message_body: contains "Viagra"
	or $sender_address: contains "MAILER-DAEMON@"
	or $sender_address: contains "noreply@"
	or $sender_address: contains "postmaster@"
then

logwrite "$tod_log $message_id sender_address=$sender_address header_from=$header_from header_Received=$header_Received contained spam keywords"
	seen finish
endif


ตัวอย่างการเขียน spam filter ดักเงื่อนไขต่าง ๆ ด้วยการใช้ or โดยจากคำสั่งในตัวอย่าง เมื่อตกเงื่อนไขใดเงื่อนไขหนึ่ง ก็จะถูกลบออกจาก Queue พร้อมกับการเขียน Log ลงในไฟล์ /var/log/filter.log ซึ่งเราสามารถดู Log ได้จากไฟล์ /var/log/filter.log

หลังจากแก้ไขทุกอย่างเรียบร้อยแล้ว อย่าลืม restart exim ด้วยครับ (ก่อนการแก้ไขทุกอย่างควร backup ไฟล์ต้นฉบับด้วยทุกครั้ง)








สุดท้าย
ขอให้โชคดีมีสุข นอนหลับสบายใจ server ไม่ล้มไร้ spam ครับ หุหุ อย่าลืมน่ะครับว่าวิธีนี้แก้ไขปัญหาที่ปลายเหตุ เพราะอย่างไร spam ก็ยังมีการทำงานและ server ก็ยังทำงานหนักอยู่ แต่ถือว่าช่วยได้เยอะ เพราะถ้าส่งออกไปไม่ได้ ซะพักพวก spam ก็ท้อใจ ไม่หันมามอง server ของเรา


   
Share
Bookmark.   

  By : TC Admin
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2012-05-17
  Download : No files
Sponsored Links
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่