|
การติดตั้ง PortSentry
ให้เราเริ่มด้วยการเอา portsentry-1.1.tar.gz ไปไว้ที่ /home/util เผื่อมีการลงซ้ำในอนาคต
[root@one util]# cp portsentry-1.1.tar.gz /var/tmp/ [root@one util]# cd /var/tmp/ [root@one tmp]# tar xzpf portsentry-1.1.tar.gz [root@one tmp]# cd portsentry-1.1 [root@one portsentry-1.1]#
เราเริ่มด้วยการ copy ไปไว้ที่ /var/tmp จากนั้นก็เปลี่ยนไปทำงานที่ /var/tmp ทำการแตก tar.gz ออกมา แล้วก็เข้าไปยัง Directory ของ portsentry-1.1/ มีแฟ้มต่างๆ ที่สำคัญต้องทำการแก้ไขอยู่ 5 แฟ้มคือ
Makefile portsentry_config.h
ซึ่งการแก้ไขแฟ้มทั้ง 2 แฟ้ม มีดังนี้
1. Makefile
เริ่มด้วยการ vi +29 Makefile
แก้บรรทัด CFLAGS = -O -Wall
แก้เป็น
CFLAGS = -O2 -march=i686 -funroll-loops -Wall
ต่อไป vi +40 Makefile แก้บรรทัด
INSTALLDIR = /usr/local/psionic CHILDDIR=/portsentry
แก้เป็น
INSTALLDIR = /usr/sbin CONFIGDIR = /etc/portsentry
ต่อไป vi +71 Makefile แก้บรรทัด
@if [ ! -d $(INSTALLDIR) ]; then /bin/mkdir $(INSTALLDIR); fi
แก้เป็น
@if [ ! -d $(INSTALLDIR) ]; then /bin/mkdir -p $(INSTALLDIR); fi
ต่อไป vi +73 Makefile แก้บรรทัด
@if [ "$(INSTALLDIR)" = "/usr/local/psionic" ]; then /bin/chmod 700 $(INSTALLDIR) ; fi @echo "Creating portsentry directory $(INSTALLDIR)$(CHILDDIR)" @if [ ! -d $(INSTALLDIR)$(CHILDDIR) ]; then /bin/mkdir $(INSTALLDIR)$(CHILDDIR); fi
แก้เป็น
@if [ "$(INSTALLDIR)" = "/usr/sbin" ]; then /bin/chmod 700 $(INSTALLDIR) ; fi @echo "Creating portsentry directory $(CONFIGDIR)" @if [ ! -d $(CONFIGDIR) ]; then /bin/mkdir -p $(CONFIGDIR); fi
ต่อไป vi +77 Makefile แก้บรรทัด
chmod 700 $(INSTALLDIR)$(CHILDDIR)
แก้เป็น
chmod 700 $(CONFIGDIR) ต่อไป vi +79 Makefile แก้บรรทัด
cp ./portsentry.conf $(INSTALLDIR)$(CHILDDIR) cp ./portsentry.ignore $(INSTALLDIR)$(CHILDDIR) cp ./portsentry $(INSTALLDIR)$(CHILDDIR)
แก้เป็น
cp ./portsentry.conf $(CONFIGDIR) cp ./portsentry.ignore $(CONFIGDIR) cp ./portsentry $(INSTALLDIR)
ต่อไป vi +83 Makefile แก้บรรทัด
chmod 600 $(INSTALLDIR)$(CHILDDIR)/portsentry.ignore chmod 600 $(INSTALLDIR)$(CHILDDIR)/portsentry.conf chmod 700 $(INSTALLDIR)$(CHILDDIR)/portsentry
แก้เป็น
chmod 600 $(CONFIGDIR)/portsentry.ignore chmod 600 $(CONFIGDIR)/portsentry.conf chmod 500 $(INSTALLDIR)/portsentry
ต่อไป vi +88 Makefile แก้บรรทัด
@echo "Edit $(INSTALLDIR)$(CHILDDIR)/portsentry.conf and change"
แก้เป็น
@echo "Edit $(CONFIGDIR)/portsentry.conf and change"
ต่อไป vi +94 Makefile แก้บรรทัด
@echo "and config files ($(INSTALLDIR)$(CHILDDIR))."
แก้เป็น
@echo "and config files $(CONFIGDIR)." 2. portsentry_config.h
เริ่มด้วยการ vi +32 portsentry_config.h
แก้บรรทัด #define CONFIG_FILE "/usr/local/psionic/portsentry/portsentry.conf"
แก้เป็น
#define CONFIG_FILE "/etc/portsentry/portsentry.conf"
เมื่อได้แก้ไขแฟ้มทั้งหมดแล้ว การติดตั้งทำโดย
จากนั้นทำการบันทึกการเปลี่ยนแปลงก่อนและหลังลง porttsentry ดังนี้
[root@one portsentry-1.1]# cd [root@one root]# find /* > PortSentry1 [root@one root]# cd /var/tmp/portsentry-1.1/ [root@one portsentry-1.1]# make linux [root@one portsentry-1.1]# make install [root@one portsentry-1.1]# strip /usr/sbin/portsentry [root@one portsentry-1.1]# mkdir -m0700 /var/portsentry [root@one portsentry-1.1]# cd [root@one root]# find /* > PortSentry2 [root@one root]# diff PortSentry1 PortSentry2 > PortSentry-Installed
จากนั้นก็ delete แฟ้มออก
[root@one /]# cd /var/tmp/ [root@one tmp]# rm -rf portsentry-1.1/ [root@one tmp]# rm -f portsentry-1.1.tar.gz
ถ้าการติดตั้งเรียบร้อยสมบูรณ์ จะเกิดแฟ้มต่างๆ ขึ้นมาดังนี้
/etc/portsentry/portsentry.conf: (The PortSentry Configuration File)
/etc/portsentry/portsentry.ignore: (The PortSentry Ignore File)
/etc/portsentry/portsentry.modes: (The PortSentry Modes File)
/etc/init.d/portsentry: (The PortSentry Initialization File)
ในแฟ้ม //etc/portsentry/portsentry.conf ควรจะมีเนื้อหาดังข้างล่างนี้คือ
TCP_PORTS="1,11,81,82,83,1080,1720,1863,5190,8080" UDP_PORTS="1,7,9,81,82,83,1080,1720,1863,5190,8080" ADVANCED_PORTS_TCP="1024" ADVANCED_PORTS_UDP="1024" ADVANCED_EXCLUDE_TCP="113,139" ADVANCED_EXCLUDE_UDP="520,138,137,67" IGNORE_FILE="/etc/portsentry/portsentry.ignore" HISTORY_FILE="/var/portsentry/portsentry.history" BLOCKED_FILE="/var/portsentry/portsentry.blocked" RESOLVE_HOST="0" BLOCK_UDP="0" BLOCK_TCP="1" KILL_ROUTE="/sbin/route add -host $TARGET$ reject" SCAN_TRIGGER="0" PORT_BANNER="** UNAUTHORIZED ACCESS PROHIBITED **"
ลำดับต่อไปแก้ไขแฟ้ม vi /etc/portsentry/portsentry.ignore ให้มีเนื้อหาดังนี้
# Put hosts in here you never want blocked. This includes the IP addresses # of all local interfaces on the protected host (i.e virtual host, mult-home) # Keep 127.0.0.1 and 0.0.0.0 to keep people from playing games. # # PortSentry can support full netmasks for networks as well. Format is: # # <IP Address>/<Netmask> # # Example: # # 192.168.2.0/24 # 192.168.0.0/16 # 192.168.2.1/32 # Etc. # # If you don't supply a netmask it is assumed to be 32 bits. # #
127.0.0.1/32 0.0.0.0
ลำดับต่อไปแก้ไขแฟ้ม vi /etc/portsentry/portsentry.modes ให้มีเนื้อหาดังนี้
# These are the available startup modes for PortSentry. Uncomment the # modes you want PortSentry to run in. For information about each # available mode, please see the PortSentry documentation. # # Normal TCP/UDP scanning: #tcp #udp # # Steal TCP/UDP scanning: #stcp #sudp # # Advanced Stealth TCP/UDP scanning: atcp audp
จากนั้นทำการ chmod และ chown ดังนี้
[root@one /]# chmod 600 /etc/portsentry/portsentry.modes [root@one /]# chown 0.0 /etc/portsentry/portsentry.modes
ส่วนแฟ้ม /etc/init.d/portsentry มีเนื้อหาดังนี้
#!/bin/bash # This shell script takes care of starting and stopping the Port Scan Detector. # # chkconfig: 345 98 05 # description: PortSentry Port Scan Detector is part of the Abacus Project \ # suite of tools. The Abacus Project is an initiative to release \ # low-maintenance, generic, and reliable host based intrusion \ # detection software to the Internet community. # # processname: portsentry # config: /etc/portsentry/portsentry.conf # pidfile: /var/run/portsentry.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 RETVAL=0 prog="PortSentry" start() { SENTRYDIR=/etc/portsentry if [ -s $SENTRYDIR/portsentry.modes ] ; then modes=`cut -d "#" -f 1 $SENTRYDIR/portsentry.modes` else modes="tcp udp" fi for i in $modes ; do action "Starting $prog -$i: " /usr/sbin/portsentry -$i RETVAL=$? done echo [ $RETVAL = 0 ] && touch /var/lock/subsys/portsentry return $RETVAL } stop() { echo -n "Shutting down $prog: " killproc portsentry RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/portsentry return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart|reload) stop start RETVAL=$? ;; condrestart) [ -f /var/lock/subsys/portsentry ] && restart || : ;; status) status portsentry ;; *) echo "Usage: portsentry {start|stop|restart|reload|condrestart|status}" exit 1 esac
จากนั้นให้ทำงานทุกครั้งที่เปิดเครื่อง ( ntsysv นั่นเอง)
[root@one /]# chmod 700 /etc/init.d/portsentry [root@one /]# chown 0.0 /etc/init.d/portsentry [root@one /]# chkconfig --add portsentry [root@one /]# chkconfig --level 345 portsentry on
[root@deep /]# /etc/init.d/portsentry start
แฟ้มต่างๆที่ใช้ในการทำ hostsentry นี้มีให้ Download ประกอบด้วยแฟ้มต่างๆดังนี้
portsentry.sh portsentry-1.1.tar.gz makeFilePort คือแฟ้ม MakeFile ในที่นี้นั่นเอง portsentry_config.h
|