การติดตั้งโปรแกรม snort เพื่อเฝ้าระวังตรวจสอบผู้บุกรุก server
*** แหล่งข้อมูลต้นฉบับ snort คือ http://www.snort.org/
- หากเป็น fedora core 5 ให้ติดตั้งด้วยคำสั่ง
yum install snort
- ติดตั้งโปรแกรม snort โดยดาวน์โหลดโปรแกรมจาก
ftp://ftp.psu.ac.th/pub/snort/snort-2.4.3-1.FC3.i386.rpm
แล้วติดตั้งด้วยคำสั่ง
rpm -Uvh snort-2.4.3-1.FC3.i386.rpm
- ต่อไปต้องติดตั้ง rules ซึ่งเป็น pattern ของผู้บุกรุก
- ต้นฉบับอยู่ที่ http://www.snort.org/rules/
มีหลายรุ่น ทั้งแบบเสียเงิน และแบบไม่ต้องเสียเงิน(community rules)
- ให้ลองตรวจสอบดู directory ชื่อ /etc/snort/rules
จะไม่มีแฟ้มข้อมูลเลย มีแต่ความว่างเปล่า
ให้ติดตั้ง rules โดยดาวน์โหลดแฟ้มจาก
ftp://ftp.psu.ac.th/pub/snort/Community-Rules-2.4.tar.gz
- แล้วแตกแฟ้มไปเก็บไว้ที่ /etc/snort ด้วยคำสั่ง
tar -zxvf Community-Rules-2.4.tar.gz -C /etc/snort
จะได้แฟ้ม rules อยู่ใน /etc/snort/rules
แล้วแก้ไขแฟ้ม /etc/snort/snort.conf ที่บรรทัดข้อความว่า
var RULE_PATH /etc ให้แก้ไขเป็นว่า
var RULE_PATH /etc/snort/rules
***หากถูกต้องอยู่แล้ว ก็ไม่ต้องแก้ไข
- ให้ตรวจสอบดูในแฟ้ม /etc/snort/snort.conf
แก้ไขบรรทัดตัวแปร RULE_PATH จากเดิม /etc
ให้เป็น /etc/snort/rules ดังตัวอย่าง
var RULE_PATH /etc/snort/rules
แก้ไขบรรัทด path ของ dynamicengine เดิมว่ามีข้อความดังนี้
dynamicengine /usr/lib/dynamicengine/libsf_engine.so
ให้แก้ไขเป็นว่า dynamicengine /usr/lib/snort/dynamicengine
ให้ยกเลิกการทำงานของ dcerpc preprocessor
โดยการใส่เครื่องหมาย "#" นำหน้าบรรทัดดังตัวอย่าง
#preprocessor dcerpc: \
# autodetect \
# max_frag_size 3000 \
# memcap 100000
ทั้งหมดนี้เป็น bug ที่ติดมาเจอใน fedora core 5
- ทดสอบการทำงาน
- เริ่มต้นด้วยคำสั่ง service snortd start ได้ผลว่า
Starting snort: [ OK ]
หาก start ไม่ขึ้น ให้ลองตรวจสอบ error ดูในแฟ้ม /var/log/messages
- !!! โปรดอย่าเพิ่งดีใจ ให้ลองตรวจสอบผล
ด้วยคำสั่ง service snortd status ได้ผลว่า
snort dead but subsys locked
แสดงว่ายังปรับแต่ง snort ไม่ถูกต้อง
- ให้ตรวจสอบความผิดพลาดด้วยคำสั่ง
snort -Tc /etc/snort/snort.conf
ได้ผลข้อความดังตัวอย่างว่า
***
*** interface device lookup found: eth0
***
Running in Test mode with config file: /etc/snort/snort.conf
Running in IDS mode .....
ยังมีต่ออีกมาก...ให้สังเกตที่บรรทัดช่วงสุดท้ายคือ
ERROR: Unable to open rules file: /etc/snort/rules/local.rules or /etc/snort//etc/snort/rules/local.rules
Fatal Error, Quitting..
เป็นเพราะว่าระบบพยายามเรียกหา rules ไม่ถูกตำแหน่ง
- ให้ปรับปรุงแก้ไขแฟ้ม /etc/snort/snort.conf ดังนี้
- ไปที่บริเวณด้านท้ายของแฟ้มนี้
- ให้เติมเครื่องหมาย # นำหน้าทุกบรรทัดที่ขึ้นต้นด้วยข้อความ
จากเดิม include $RULE_PATH/
ให้กลายเป็น #include $RULE_PATH/
- แล้วไปเพิ่มบรรทัดข้อความต่อด้านท้ายสุดของแฟ้มนี้ว่า
include $RULE_PATH/community-dos.rules
include $RULE_PATH/community-exploit.rules
include $RULE_PATH/community-ftp.rules
include $RULE_PATH/community-game.rules
include $RULE_PATH/community-icmp.rules
include $RULE_PATH/community-imap.rules
include $RULE_PATH/community-inappropriate.rules
include $RULE_PATH/community-mail-client.rules
include $RULE_PATH/community-misc.rules
include $RULE_PATH/community-nntp.rules
include $RULE_PATH/community-oracle.rules
include $RULE_PATH/community-sip.rules
include $RULE_PATH/community-smtp.rules
include $RULE_PATH/community-sql-injection.rules
include $RULE_PATH/community-virus.rules
include $RULE_PATH/community-web-attacks.rules
include $RULE_PATH/community-web-cgi.rules
include $RULE_PATH/community-web-client.rules
include $RULE_PATH/community-web-dos.rules
include $RULE_PATH/community-web-iis.rules
include $RULE_PATH/community-web-misc.rules
include $RULE_PATH/community-web-php.rules
- ตรวจสอบผลด้วยคำสั่ง
snort -Tc /etc/snort/snort.conf
หาก Fatal Error, Quitting.. หายไป
ได้ Snort exiting กลับมาเป็นอันใช้ได้
- ต้องลบแฟ้ม /var/log/snort/alert ทิ้งด้วย(ถ้ามี)
เพราะหลัง error สิทธิ์ของแฟ้มเป็นของ root ให้ลบด้วยคำสั่ง
rm /var/log/snort/alert
ทดลองเริ่มสั่งทำงาน service snortd start ได้ผลว่า
Starting snort: [ OK ]
ให้ตรวจสอบผลทำงานด้วยคำสั่ง service snortd status
ถ้าได้ผลว่า snort (pid 16105) is running...
เป็นอันใช้งานได้แล้ว
- หากมีปัญหาระบบ logrotate ให้แก้ไขแฟ้ม /etc/logrotate.d/snort ดังนี้
- หากแจ้งเตือนหา log ไม่เจอ
ลบแก้ไขที่บริเวณบรรทัดข้อความจากเดิม
/var/log/snort/alert /var/log/snort/*log /var/log/snort/*/alert /var/log/snort/*/*log {
ให้เหลือเพียงแค่ว่า
/var/log/snort/alert /var/log/snort/*log {
- หากมีการ rotate แฟ้มใน /var/log/snort ถี่เกินไป
เปลี่ยนจากจากทุกวันเป็นทุกเดือน โดยแก้ข้อความดังนี้
จากเดิม daily ให้เปลี่ยนเป็น monthly
และให้กำหนดให้ rotate หากแฟ้มมีขนาดโตเกิน 100K
โดยเพิ่มบรรทัดข้อความว่า size 100k
- หากไม่ต้องการให้ compress แฟ้มใน /var/log/snort
เปลี่ยนจากมีการ compress เป็นไม่มี โดยแก้ข้อความดังนี้
จากเดิม compress ให้เปลี่ยนเป็น nocompress
- ตัวอย่างแฟ้ม /etc/logrotate.d/snort คือ
# /etc/logrotate.d/snort
# $Id: snort.logrotate,v 1.1.2.1.2.2 2005/05/05 15:49:56 jhewlett Exp $
/var/log/snort/alert /var/log/snort/snort.log {
rotate 7
missingok
monthly
size 100k
nocompress
sharedscripts
postrotate
/etc/init.d/snortd restart 1>/dev/null || true
endscript
}
ขอบคุณข้อมูลจาก ศูนย์คอมพิวเตอร์ มหาวิทยาลัยสงขลานครินทร์