Latest Updates: Debian RSS

  • bass

    IPSET Installation With Compile For iptables

    bass 12:45 on 01/01/2010 | 0 Permalink | Reply
    Tags: , , Debian, ipset,

    The installation requires the following steps

    it is assumed that you have got the kernel source tree, configured and at least the modules compiled
    donwload and unpack the source
    run KERNEL_DIR= make to compile the userspace tool and the kernel modules
    run KERNEL_DIR= make install to install the ipset userspace tool and the kernel modules
    In order to use to the set match and SET target
    you need iptables 1.4.4 (or above), or
    due to the ipset protocol change, you have to recompile iptables before 1.4.4 to get ipset 3.0 (or above) supported:
    Copy the file kernel/include/linux/netfilter_ipv4/ip_set.h from the source tree of ipset-3.9 to include/linux/netfilter_ipv4 in the source of iptables
    Recompile iptables
    and ready!

    Refer : http://ipset.netfilter.org/install.html

     
  • bass

    ArpON: ARP Poisoning Protection -- Note ไว้ กันลืม

    bass 18:50 on 12/24/2009 | 0 Permalink | Reply
    Tags: arp, Debian, netcut

    ArpON: ARP Poisoning Protection
    Submitted by neutron on 13 August, 2009 – 02:18. ARP ArpON networking Poisoning Protection
    ฝันร้ายของ admin ในระบบเครือข่าย อย่างหนึ่งที่เจอกันบ่อย ๆ คือ ARP poisoning หรือที่คนทั่วไปรู้จักกันในชื่อ NetCut ซึ่งปัญหานี้ เป็นช่องโหว่ของระบบเครือข่าย ซึ่งรู้โดยทั่วกันว่า หาทางแก้ได้แบบเด็ดขาดลำบากมาก เนื่องจากทางแก้ที่สมบูรณ์นั้น ต้องได้รับความร่วมมือจากผู้ใช้ด้วย

    ARP poisoning หรือ ARP spoofing คือวิธีการโจมตีลักษณะหนึ่งในระบบเครือข่ายแบบ ethernet ไม่ว่าจะเป็นแบบ มีสายหรือไร้สาย โดยอาศัยช่องโหว่ของ ARP (Address Resolution Protocol) ซึ่งมีระบบความปลอดภัยต่ำมาก เนื่องจาก ARP เป็นโพรโทคอลที่คุยกัน และให้ความเชื่อถือข้อมูลที่ถูกส่งออกมาโดยไม่มีเงื่อนไขในการตรวจสอบที่มา และความน่าเชื่อถือของข้อมูลใด ๆ ทั้งสิ้น ซึ่งช่องโหว่นี้ เป็นที่มาของการปลอมข้อมูล (spoofing) เพื่อหลอกให้ชาวบ้านหลงเชื่อตามที่โกหก

    ในการโจมตี เป้าหมายหลัก ๆ ที่พบบ่อย มีอยู่ 2 สาเหตุ คือ

    การทำ Man-In-The-Middle (MITM) คือ การที่ผู้ก่อการร้าย หลอกให้ชาวบ้านหลงเชื่อว่า ตัวเองนั้น เป็นเครื่องเกตเวย์ของเครือข่าย เพื่อให้ส่งข้อมูลต่าง ๆ มาที่เครื่องของผู้ก่อการร้าย และหลังจากนั้น ผู้ก่อการร้ายจะส่งข้อมูลต่อไปยังเกตเวย์ที่แท้จริงต่อไป ในกรณีนี้ ผู้ใช้จะยังใช้งานได้เหมือนไม่มีอะไรเกิดขึ้น ยกเว้นว่า ผู้ใช้อยู่ในระบบที่มีการตรวจสอบที่มา IP + MAC address ซึ่งกรณีนี้ ระบบอาจจะตรวจพบว่า ผู้ใช้มีการส่งข้อมูลมาจากแหล่งที่ไม่ได้รับอนุญาต แต่หากว่า เครื่องที่ผู้ก่อการร้ายใช้นั้น ได้รับอนุญาตเช่นกัน ก็จะไม่เห็นความผิดปกติใด ๆ เกิดขึ้น
    การทำ Denial-of-Service (DoS) หรือบางครั้งเรียกการทำ blackhole คือ การที่ผู้ก่อการร้าย หลอกให้ชาวบ้านหลงเชื่อว่า เครื่อง เกตเวย์อยู่ในที่ที่ไม่มีตัวตนจริงในระบบ หรือพูดง่าย ๆ คือ ส่ง MAC address ที่ไม่มีเครื่องใดเลยในระบบใช้อยู่ ผลที่ตามมาคือ ผู้ใช้ที่โดนหลอกด้วยการทำ blackhole จะไม่สามารถเชื่อมต่อกับเกตเวย์ของระบบได้ ทำให้ใช้งานเครือข่ายอินเทอร์เน็ตไม่ได้ หรือที่รู้จักกันในนาม NetCut
    โปรแกรมสำหรับทำ ARP spoofing หาได้โดยทั่วไปในอินเทอร์เน็ต และถูกใช้โดยผู้ที่รู้เท่าไม่ถึงการณ์ (และผู้ที่รู้เท่า และถึงการณ์) อย่างแพร่หลาย จึงมีความพยายามที่จะป้องกันการโจมตีในลักษณะดังกล่าวในหลาย ๆ รูปแบบ ทั้งทางฮาร์ดแวร์และซอฟต์แวร์ ซึ่งรู้โดยทั่วกันว่า ฮาร์ดแวร์ที่มีความสามารถในการจัดการเรื่องนี้ มีราคาที่ค่อนข้างสูง ถึงสูงมาก สำหรับระบบเครือข่ายที่มีทุนทรัพย์จำกัด (ทั่วไปในประเทศไทย) นั้น ทางออกที่น่าสนใจ คงตกอยู่ที่ซอฟต์แวร์

    ArpON “Arp handler inspectiON” – http://arpon.sourceforge.net เป็นซอฟต์แวร์ที่ถูกพัฒนาขึ้น เพื่อคอยตรวจสอบ และจัดการ ARP cache เพื่อให้เครื่องที่ใช้งาน ArpON ปลอดภัยขึ้นอีกระดับหนึ่ง ซึ่งเป็นการดี ที่จะติดตั้ง ArpON ไว้ที่เครื่องเกตเวย์ เพื่อที่จะป้องกันการถูกหลอกจากผู้ก่อการร้าย ซึ่งวิธีการติดตั้งเป็นดังนี้

    สำหรับ Lenny (ArpON เป็นแพกเกจใหม่ ซึ่งเข้ามาใน repository หลังจากที่ Lenny release ออกไปแล้ว)

    # cd /var/cache/apt/archives
    # wget ftp://ftp.debianclub.org/debian/pool/main/a/arpon/arpon_1.90-1_amd64|i386].deb
    ติดตั้ง ArpON

    # dpkg -i arpon_1.90-1_[amd64|i386].deb ; apt-get -f install
    สำหรับ Squeeze และ Sid

    # apt-get install arpon
    หลังจากติดตั้งเสร็จ จะต้องมีการตั้งค่า ที่ /etc/default/arpon ซึ่งในแฟ้มดังกล่าวจะมีตัวอย่างการตั้งค่าไว้ทั้งแบบ SARPI (Static ARP Inspection) และ DARPI (Dynamic ARP Inspection) ซึ่ง SARPI จะใช้กับระบบมีการ fix ค่า IP ส่วน DARPI จะใช้กับระบบที่ใช้ DHCP ซึ่งรายละเอียดสามารถอ่านเพิ่มเติมได้ที่เว็บไซต์ของ ArpON

    การกำหนดค่าใน /etc/default/arpon

    SARPI

    DAEMON_OPTS=”-d -f /var/log/arpon/arpon.log -g -i eth0 -s”
    DARPI

    DAEMON_OPTS=”-d -f /var/log/arpon/arpon.log -g -i eth0 -y”
    กำหนดค่าให้ ArpON ทำงาน

    RUN=”yes”
    สั่งให้ ArpON ทำงาน

    # /etc/init.d/arpon start
    ArpON “Arp handler inspection” version 1.90 (http://arpon.sourceforge.net)

    [07/13/2009 - 01:35:22 ICT] Task is forking to background, using /var/run/arpon.pid pid file…

    .
    ซึ่งค่าตั้งที่กำหนดไว้ข้างบน เป็นการกำหนดว่า ให้ ArpON ตรวจสอบ ARP สำหรับอินเทอร์เฟซ eth0 หากต้องการตรวจสอบมากกว่า 1 อินเทอร์เฟซ สามารถกำหนดเพิ่มเติมได้ดังนี้

    DAEMON_OPTS=”-d -f /var/log/arpon/eth0.log -g -i eth0 -s -f /var/log/arpon/eth1.log -g -i eth1 -y”
    ซึ่งจะกำหนดให้

    (-i) eth0 : (-s) SARPI ทำการ log ไปที่แฟ้ม (-f) /var/log/arpon/eth0.log
    (-i) eth1 : (-y) DARPI ทำการ log ไปที่แฟ้ม (-f) /var/log/arpon/eth1.log
    หลังจากที่ ArpON ทำงาน ก็จะตรวจสอบ ARP request/reply ให้ และคอยตรวจสอบความถูกต้องให้อยู่เสมอ ทำให้เครื่องที่เป็นเกตเวย์ปลอดภัยจาก ARP poisoning ในระดับหนึ่ง อย่างน้อยก็ป้องกันได้ “ครึ่งทาง”

    ตรวจ ARP cache table จะพบ

    # arp -n
    Address HWtype HWaddress Flags Mask Iface
    192.168.1.1 ether 00:22:57:62:xx:xx CM eth0
    Flags: CM แสดงให้เห็นว่า ArpON ทำการเพิ่ม 192.168.1.1:00:22:57:62:xx:xx เข้าไปใน ARP cache table แบบ manual ซึ่งหมายความว่า ระบบจะไม่เปลี่ยนแปลงค่านี้เองไม่ว่าจะมีการส่งค่าใด ๆ มาหลอกก็ตาม

    แต่ทว่า การป้องกันเพียงข้างเดียว (ที่เกตเวย์) ไม่เพียงพอสำหรับการแก้ปัญหา ARP poisoning ต้องมีการแก้ที่ผู้ใช้ด้วย ซึ่งหากฝั่งผู้ใช้เป็น Linux, FreeBSD, NetBSD, OpenBSD and Mac OS X สามารถใช้ ArpON เพื่อป้องกันในลักษณะเดียวกับตัวอย่างนี้ได้ แต่หากผู้ใช้เป็น MS Windows แล้ว ต้องหาซอฟต์แวร์ที่ทำงานบน Windows เพื่อมาช่วยจัดการในลักษณะเดียวกัน ซึ่งโดยประสบการณ์ของผู้เขียน ยังให้ข้อสรุปไม่ได้ว่าซอฟต์แวร์ชุดไหนที่ทำงานบน Windows ได้ดี เนื่องจากไม่ค่อยได้ใช้ Windows ถ้า ArpON มีการพอร์ตให้ใช้กับ Windows ได้ก็คงจะดี :P

    ข้อแนะนำเพิ่มเติมสำหรับ admin ที่ดูแลระบบภายในโรงเรียน หรือสถานที่ ที่เครื่องคอมพิวเตอร์ไม่ได้มีการเคลื่อนย้าย สามารถทำ Static ARP ได้เองโดยอาจจะเขียน batch file ให้ระบบทำการเพิ่ม static ARP เข้าไปในระหว่างที่เครื่องเริ่มเปิดใช้งาน หรือใช้โปรแกรมชื่อ ARPFreeze (http://www.irongeek.com/i.php?page=security/arpfreeze-static-arp-poisoni…) ซึ่งช่วยอำนวยความสะดวกในการตั้งค่าเหล่านี้ให้เรา ก็จะช่วยปิดทางการทำ ARP poisoning ได้อย่างสมบูรณ์

    โดย neutron
    Refer : http://debianclub.org/node/492

     
  • bass

    Red5 Install

    bass 20:52 on 12/20/2009 | 0 Permalink | Reply
    Tags: Debian, red5

    Installing Red5 on Debian
    This howto was provided by Nathan P. Johansen.

    The following are steps used to get Red5 running on a Debian machine. This is the development version of Red5.

    Before beginning this make sure you are running these commands as root.

    Install Subversion:
    apt-get install subversion
    Install tools to build your own Debian packages:
    apt-get install dpkg-dev debhelper dh-make devscripts fakeroot
    Install Java (see this tutorial for more info):
    apt-get install java-package
    Install Apache Ant 1.7:
    wget http://apache.mirror.transip.nl/ant/binaries/apache-ant-1.7.1-bin.tar.gz
    tar zxvf apache-ant-1.7.1-bin.tar.gz
    mv apache-ant-1.7.1 /usr/local/ant
    export ANT_HOME=/usr/local/ant
    Once Java and Ant are all set up you simply download the latest development version of Red5 to your box.
    svn co http://red5.googlecode.com/svn/java/server/trunk red5-trunk
    That will create a folder in your current directory called red5-trunk.

    Navigate to the red5-trunk directory and run ant
    cd red5-trunk
    /usr/local/ant/bin/ant
    That will build the project on your machine.

    At this point you will need to create a red5 directory in the /usr/local/red5 directory.
    mkdir /usr/local/red5
    Then you will want to copy the contents of the dist(distribution) folder to /usr/local/red5 like so
    cp -R red5-trunk/dist/* /usr/local/red5/
    We need need to fix the permissions on the red5.sh file:
    cd /usr/local/red5
    chmod 755 red5.sh
    To run the server you have a few options using the red5.sh file. Run the server by either running
    sh red5.sh &
    or

    ./red5.sh &
    This will start the Red5 service manually.

    Verify the correct ports are being bound to:
    netstat -ant
    You may need to edit the red5.properties file in the /usr/local/red5/conf directory if you can’t connect to your server from an external location. Try to connect to the server before you modify the properties file because you may be able to connect to it with no problems.

    Refer : http://osflash.org/red5/debian

     
  • bass

    bass 10:48 on 11/22/2009 | 0 Permalink | Reply
    Tags: , , Debian, firwall, ,

    เฮ้อ ทำระบบ Search Log กับ Top Domain System เสร็จละครับพี่น้อง สบายตัวแล้ว วุ้ย

    สรุป ฟังก์ชั่น นะครับ
    รองรับ การทำ Authentication สมบูรณ์ 100%
    มีระบบจัดเก็บ Squid Log
    มีระบบ จัดเก็บ IM Message
    มีระบบ จัดเก็บ Radius
    มีระบบ รายงานการใช้ในผู้ใช้แต่ละคน
    มีระบบ แสดงข้อมูลการใช้งานในแต่ละ User แบบ Realtime (Bandwidth Monitor Realtime per User)
    มีระบบ ค้นหา Log History Search
    และที่สำคัญ ใช้ Chillispot ที่โม โดยตาเบส ครับ อิอิอิ(ตูเอง)

    ครบเครื่องแล้วครับ

     
  • bass

    สรุปวันจัดการ Deb camp Thailand

    bass 12:49 on 11/16/2009 | 0 Permalink | Reply
    Tags: debcamp, Debian

    วันนี้ เข้า DebianClub.org
    เลยไปเห็น เรื่องการจัดการ DebianCam

    http://www.debianclub.org/node/509

    วันงาน สรุป
    ตกลงเป็นวันที่ 13-19 มี.ค. 2553

     
  • bass

    HowTo DNS Bind9 Master Slave Server

    bass 10:27 on 11/16/2009 | 0 Permalink | Reply
    Tags: , Debian,

    DNS Bind9 Master Slave Server HowTo

    http://www.howtoforge.com/debian_bind9_master_slave_system

    กำลังลองทำอยู่ ถ้าเสร็จแล้ว จะมาเรียบเรียงใหม่ ในรูปแบบของ นายเบส

     
  • bass

    Monitor Traffic On Debian

    bass 10:25 on 11/10/2009 | 0 Permalink | Reply
    Tags: bandwidth, , Debian, , jnettop, , , tcptrack, traffic

    jNettop – View hosts/ports taking up the most network traffic

    jNettop captures traffic comming across the host it is running on and displays streams sorted by bandwidth they use. Result is a nice listing of communication on network by host and port, how many bytes went through this transport and the bandwidth it is consuming.

    Install jnettop in debian

    #apt-get install jnettop

    This will complete the installation now you need to run this program with the following command

    #jnettop

    This will display a GUI with all the network traffic comming across the host

    ตัวอย่าง

    jnettop -i eth0 –display text -t 5 –format ‘$src$,$srcport$,$srcbps$,$dst$,$dstport$,$dstbps
    สำหรับ Track Traffice

    ตัวโปรแกรมนี้ สามารถกำหนดการ  Export Data ได้ ตอนนี้ทำเสร็จแล้ว สามารถแสดงผลในหน้่า WebGUI ได้ สามารถที่จะรู้ได้ว่า
    ใครใช้อะไรไปเท่าไหร่ เป็นต้น ตอนนี้เอาใส่เข้าไปใน BHotspot แล้วครับ

     
  • bass

    ปรับแต่งภาพ Grub Loader

    bass 02:01 on 11/03/2009 | 0 Permalink | Reply
    Tags: Debian, gimp, grub, image, splash

    Customizing the splash image in GRUB (ปรับแต่งภาพใน Grub Loader)

    The splash image is the image shown in the background when GRUB (the GRand Unified Bootloader) is displaying the list of operating systems you can boot. Typically, this is the corporate logo of your Linux distribution. But its very simple to customize it to an image of your choice. All you need is the GIMP and gzip. My GIMP version is 1.2. Even older versions may do the job.

    Here’s how:(You need to have root access)
    1)Start the GIMP.
    2)Click on File->New or type Ctrl+N
    3)In the new image dialog, change Width to 640 pixels and Height to 480 pixels. (The image should be of size 640×480 pixels.) Now click OK.
    4)Create the image which you would like to be the splash image. It’s quite fun to experiment with the various tools of the GIMP!
    5)After you have finished creating the image, hit Alt+i or right click on the image and click on Image->Mode->Indexed…
    6)In the Indexed Color Conversion dialog that appears, click on the radio button “Generate optimal Palette” and in “# of colors” enter 14. Click OK.(The image should be of only 14 colors)
    7)Now right-click on the image and click on File->Save As…Save the file as splash.xpm in a directory of your choice.
    8)Now open a terminal window and navigate to the directory where you have saved splash.xpm
    9)Now key in gzip splash.xpm
    10)You will find that a file named splash.xpm.gz is created in the directory where splash.xpm used to exist.
    11)Copy this splash.xpm.gz to the /boot/grub directory. You may want to back up the pre-existing splash.xpm.gz file in the /boot/grub directory first.

    That’s it! When you reboot, you will find your image in the background, with the menu of operating systems etc. in the foreground.

    Of course, this is not the only way to change the image, but it is a very simple one.

     
  • bass

    Compile Debian + L7

    bass 01:40 on 11/03/2009 | 0 Permalink | Reply
    Tags: , , Debian, , kernel, layer7,

    Debian Lenny Compile Kernel

    apt-get install gzip unzip bzip2 patch
    apt-get install debhelper screen fakeroot zlib1g-dev build-essential libncurses5-dev kernel-package

    apt-get install linux-source-2.6

    cd /usr/src/

    wget http://downloads.sourceforge.net/project/l7-filter/l7-filter%20kernel%20version/2.22/netfilter-layer7-v2.22.tar.gz
    wget http://downloads.sourceforge.net/project/l7-filter/Protocol%20definitions/2009-05-28/l7-protocols-2009-05-28.tar.gz

    wget http://www.ssi.bg/~ja/routes-2.6.26-15.diff

    wget http://www.linuximq.net/patchs/linux-2.6.26.8-imq-test2.diff
    wget http://www.linuximq.net/patchs/iptables-1.4.3.2-imq_xt.diff

    wget http://www.netfilter.org/projects/iptables/files/iptables-1.4.3.2.tar.bz2

    tar jxf linux-source-2.6.26.tar.bz2
    tar zxf netfilter-layer7-v2.22.tar.gz
    tar zxf l7-protocols-2009-05-28.tar.gz
    tar jxf iptables-1.4.3.2.tar.bz2

    ln -sd linux-source-2.6.26 ./linux

    cd linux

    patch -p1 < /usr/src/netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patch
    patch -p1 < /usr/src/routes-2.6.26-15.diff
    patch -p1 < /usr/src/linux-2.6.26.8-imq-test2.diff

    Networking options > Network packet filtering framework (Netfilter) > Core Netfilter Configuration.
    [ ] layer7 match support

    [*] select all
    [M] select all

    "IMQ" target support
    "layer7" match support
    [ ] "Layer7" debugging output

    ติดตั้งแบบ ด่วน
    make && make modules && make modules_install && make install
    cd /boot
    mkinitramfs -o initrd.img-2.6.26.19 2.6.26.19
    update-grub
    reboot

    สำหรับสร้างเพื่อไป Install ที่อื่น (.deb)

    make clean && make mrproper
    make menuconfig

    make-kpkg clean
    fakeroot make-kpkg –initrd –append-to-version=-l7imq kernel_image kernel_headers
    cd /usr/src
    dpkg -i linux-image-*
    dpkg -i linux-headers-*

    reboot

    iptables v1.4.3.2 เพื่อให้รองรับกับ layer7
    cd /usr/src/iptables-1.4.3.2
    patch -p1 < /usr/src/iptables-1.4.3.2-imq_xt.diff
    cp /usr/src/netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/* /usr/src/iptables-1.4.3.2/extensions/
    ./configure –with-kernel=/usr/src/linux
    make
    make install
    cd /usr/src/l7-protocols-2009-05-28
    make install

    modprobe xt_layer7

    Files rc.local

    modprobe xt_rateest
    modprobe xt_helper
    modprobe xt_dccp
    modprobe xt_TPROXY
    modprobe xt_NFLOG
    modprobe xt_limit
    modprobe xt_tcpmss
    modprobe xt_connbytes
    modprobe xt_owner
    modprobe xt_sctp
    modprobe xt_DSCP
    modprobe xt_MARK
    modprobe xt_IMQ
    modprobe xt_statistic
    modprobe xt_quota
    modprobe xt_layer7
    modprobe xt_TCPOPTSTRIP
    modprobe xt_recent
    modprobe xt_NOTRACK
    modprobe xt_iprange
    modprobe xt_CONNSECMARK
    modprobe xt_multiport
    modprobe xt_CONNMARK
    modprobe xt_RATEEST
    modprobe xt_policy
    modprobe xt_dscp
    modprobe xt_pkttype
    modprobe xt_length
    modprobe xt_CLASSIFY
    modprobe xt_physdev
    modprobe xt_SECMARK
    modprobe xt_connlimit
    modprobe xt_tcpudp
    modprobe xt_TRACE
    modprobe xt_realm
    modprobe xt_conntrack
    modprobe xt_string
    modprobe xt_hashlimit
    modprobe xt_mac
    modprobe xt_time
    modprobe xt_mark
    modprobe xt_comment
    modprobe xt_u32
    modprobe xt_NFQUEUE
    modprobe xt_TCPMSS
    modprobe xt_socket
    modprobe xt_esp
    modprobe xt_state
    modprobe xt_connmark
    modprobe nf_conntrack_ftp
    modprobe nf_conntrack
    modprobe nf_nat_ftp
    modprobe nf_nat

    ทดสอบ Layer7
    iptables -m layer7 -h

    Block Bit
    iptables -A FORWARD -m layer7 –l7proto bittorrent -j DROP

    iptables -nvL | grep LAYER

    ทดสอบ IMQ
    http://www.linuximq.net/usage.html

     
  • bass

    เก็บ IP Traffic Log ด้วย ulogd สำหรับ Debian

    bass 11:35 on 11/02/2009 | 0 Permalink | Reply
    Tags: Debian, , ulogd

    เก็บ IP Traffic Log ด้วย ulogd (Debian Admin Style)

    อันนี้ ผมไป ค้นหาใน Google ไว้นานละครับ (ขอตัดข้อความจากต้นฉบับบ้างส่วนนะครับ)

    เริ่มเลยละกันครับ

    1. ติดตั้ง packages ที่จำเป็น

    # aptitude install ulogd ulogd-pcap tshark

    2. เขียน script มาจัดการเกี่ยวกับ log

    # vi /usr/local/bin/traffic-ulogd.sh

    #!/bin/sh

    ULOGD_CONF_TPL=/etc/ulogd.conf.tpl
    ULOGD_CONF=/etc/ulogd.conf
    LOG_DIR=/home/log/ip-traffic

    PARENT_DIR=`date +%Y-%m`
    PARENT_DIR=”$LOG_DIR/$PARENT_DIR”

    DAILY_LOG=`date +%Y-%m-%d`
    DAILY_LOG=”$PARENT_DIR/$DAILY_LOG.pcap”

    # Copy original debian ulogd.conf file to be
    # the future config template.
    if [ ! -f $ULOGD_CONF_TPL ]; then
    echo “Copying default $ULOGD_CONF to $ULOGD_CONF_TPL”
    cp $ULOGD_CONF $ULOGD_CONF_TPL
    fi

    # Create the directory structure for logging
    if [ ! -d $PARENT_DIR ]; then
    echo “Make directory $PARENT_DIR”
    mkdir -p $PARENT_DIR
    fi

    # Edit template config file
    cat $ULOGD_CONF_TPL | \
    sed -e ’s:^#\(plugin=”/usr/lib/ulogd/ulogd_PCAP.so”\):\1:g’ | \
    sed -e “s:/var/log/ulog/pcap.log:$DAILY_LOG:g” > /tmp/ulogd.conf

    mv /tmp/ulogd.conf $ULOGD_CONF

    # Restarting to reload config file
    /etc/init.d/ulogd restart

    เป็น script ที่จะคอยจัดการเกี่ยวกับ directory สำหรับจัดเก็บ ในรูปแบบ 2008-08, 2008-09 และจัดเก็บ log file ในรูปแบบ 2008-08-26.pcap,…

    # chmod u+x /usr/local/bin/traffic-ulogd.sh
    # /usr/local/bin/traffic-ulogd.sh

    สั่งให้ script จัด config ให้ และเริ่มรอการ log
    3. กำหนด iptables rule ให้ทำการ log

    # iptables -I FORWARD -j ULOG –ulog-cprange 100 –ulog-qthreshold 50

    4. ลองดูคร่าว ๆ ว่ามี packet ผ่านเข้า log ไหม

    # iptables -nvL FORWARD
    Chain FORWARD (policy ACCEPT 211M packets, 106G bytes)
    pkts bytes target prot opt in out source destination
    14M 7502M ULOG all — * * 0.0.0.0/0 0.0.0.0/0 ULOG copy_range 100 nlgroup 1 queue_threshold 50

    จะเห็นว่ามี Packet วิ่งเข้า rule นี้ด้วย
    5. ดูแฟ้มที่จัดเก็บ log (ผมเก็บไว้ที่ /home เพราะแบ่งพื้นที่ไว้เยอะที่นี่)

    # cd /home/log/ip-traffic/2008-08
    # ls
    2008-08-26.pcap
    # file 2008-08-26.pcap
    2008-08-26.pcap: tcpdump capture file (little-endian) – version 2.4 (raw IP, capture length 65535)

    อ้า… ใช่แล้วครับ เป็น ลักษณะ tcpdump capture file (binary ด้วย … เห็นเขาบอกให้เก็บในรูปแบบที่น่าเชื่อถือได้ ไม่รู้ตัวนี้น่าเชื่อถือพอหรือเปล่า
    6. ลองดู log ข้างในแฟ้มนี้ดู

    # tshark -r 2008-08-26.pcap -tad -c 5
    Running as user “root” and group “root”. This could be dangerous.
    1 2008-08-26 03:31:34.464265 172.30.10.18 -> 80.252.110.146 TCP acter > kar2ouche [SYN] Seq=0 Win=16384 Len=0 MSS=1452
    2 2008-08-26 03:31:34.537428 172.30.10.102 -> 64.71.134.246 TCP ft-role > https [SYN] Seq=0 Win=16384 Len=0 MSS=1452
    3 2008-08-26 03:31:34.565095 172.30.10.18 -> 66.199.250.170 TCP appiq-mgmt > manyone-xml [SYN] Seq=0 Win=16384 Len=0 MSS=1452
    4 2008-08-26 03:31:34.568396 172.30.10.18 -> 219.239.90.172 TCP rfa > 28221 [SYN] Seq=0 Win=16384 Len=0 MSS=1452
    5 2008-08-26 03:31:34.571477 172.30.10.18 -> 72.51.37.237 TCP cxws > ospf-lite [SYN] Seq=0 Win=16384 Len=0 MSS=145

    ขอดูแค่ 5 packets ก่อนละกัน

    -r 2008-08-26.pcap (read from file)
    -tad (Absolute date)
    -c 5 (5 packets count and exit)

    7. เป็นอันว่า เก็บได้ ก็น่าจะเรียบร้อย ตอนนี้ก็เหลือให้ script เราทำงานเป็นช่วง ๆ เพื่อจัดการเรื่องชื่อไฟล์ให้ถูกต้อง

    # vi /etc/cron.d/traffic-log

    0 */1 * * * root /usr/local/bin/traffic-ulogd.sh >/dev/null 2>&1

    # /etc/init.d/cron restart

    เป็นการกำหนดให้ระบบ run script นี้ ทุก ๆ ชั่วโมง (กันพลาด เดี๋ยว log ในแฟ้ม จะไม่ตรงกับวันเวลาจริง แต่ถ้าเครื่องเปิดตลอดเวลาไม่น่ามีปัญหา) เท่านี้ก็น่าจะเรียบร้อยแล้วครับผม ตอนนี้ก็เหลือดูผลว่าไฟล์ใหญ่แค่ไหน อาจจะต้องมีการมาทำ archive อีกที เดี๋ยวค่อยมาว่ากันต่อคราวหน้าละกันครับ

    Refer : http://wittaya8.blogspot.com/2008/09/ip-traffic-log-ulogd-debian-admin-style.html

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
esc
cancel