Block Bittorrent

################################################

ขออนุญาต คุณสุชาตินะครับ ขอเอามาแปะไว้ก่อน  จาก http://suchart.wordpress.com

################################################

คราวนี้ ผมไม่ใช้ ipp2p-0.8.1_rc1 จาก patch-o-matic แล้ว จะใช้ ipp2p-0.8.2 จาก ipp2p.org แทน บวกกับ patch ที่แอบขโมยมาจาก gentoo :-)

1.

apt-get update
apt-get install build-essential
apt-get install kernel-package
apt-get install libncurses5-dev

2.

cd /usr/src/
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.24.tar.bz2
tar xvjf linux-2.6.24.tar.bz2
ln -s linux-2.6.24 linux

wget http://nchc.dl.sourceforge.net/sourceforge/l7-filter/netfilter-layer7-v2.17.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/l7-filter/l7-protocols-2008-01-16.tar.gz

wget http://iptables.org/projects/iptables/files/iptables-1.4.0.tar.bz2

tar xvzf l7-protocols-2008-01-16.tar.gz
tar xvzf netfilter-layer7-v2.17.tar.gz
tar xvjf iptables-1.4.0.tar.bz2
ln -s iptables-1.4.0 iptables

3. patch linux kernel & iptables with l7-filter

cd /usr/src/linux
patch -p1 < ../netfilter-layer7-v2.17/kernel-2.6.22-2.6.24-layer7-2.17.patch
cd ../iptables
patch -p1 < ../netfilter-layer7-v2.17/iptables-1.4-for-kernel-2.6.20forward-layer7-2.17.patch
chmod +x extensions/.layer7-test

4. config and compile kernel

cd /usr/src/linux
cp /boot/config-2.6.18-5-686 ./.config
make menuconfig

เลือกไปที่

Networking –> Networking options –> Network packet filtering framework (Netfilter) –> Core netfilter configuration
เลือกเพิ่ม
<M> Netfilter connection tracking support
<M> “layer7″ match support
[*] Layer 7 debugging output

ส่วนอันอื่นที่ยังไม่ได้เลือก ก็สามารถเลือกได้ ตามต้องการ สำหรับผม ในการติดตั้งครั้งนี้ จะเลือกทุกอันเลย โดยจะเลือกเป็นโมดูล [M] ไว้ก่อน
แล้ว exit ออกมา โดยกด Esc 2 ครั้งติดๆกัน แล้วไปที่ IP: Netfilter Configuration เลือกเพิ่ม

<M> IPv4 connection tracking support (required for NAT)
<M> Full NAT

อยู่ด้านล่างสุดเลย แล้ว exit ออกมา โดยกด Esc 2 ครั้ง ไปเรื่อยๆ จนกระทั่งปรากฏหน้าจอ

Do you wish to save your new kernel configuration?

ให้กด Enter เพื่อบันทึกค่าคอนฟิก

5. คอมไพล์และสร้าง kernel image ใหม่ ขั้นตอนนี้ต้องรอนานหน่อยนะครับ

make-kpkg clean
make-kpkg --initrd --append-to-version=-l7 kernel_image kernel_headers

6. หลังจากรอคอยมานาน ต่อไปก็ติดตั้ง kernel ใหม่

cd /usr/src
dpkg -i linux-image-2.6.24-l7_2.6.24-l7-10.00.Custom_i386.deb
dpkg -i linux-headers-2.6.24-l7_2.6.24-l7-10.00.Custom_i386.deb

ตรวจสอบไฟล์ /boot/grub/menu.lst ว่าค่า default เป็นเคอร์เนลที่ติดตั้งใหม่

shutdown -r now

8. คอมไพล์และติดตั้ง iptables

cd /usr/src/iptables
make KERNEL_DIR=/usr/src/linux
make install
mv /usr/src/l7-protocols-2008-01-16 /etc/l7-protocols

9. คอมไพล์และติดตั้ง ipp2p

cd /usr/src
wget http://ipp2p.org/downloads/ipp2p-0.8.2.tar.gz
wget http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/net-firewall/ipp2p/files/ipp2p-0.8.2-kernel-2.6.22.patch
wget http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/net-firewall/ipp2p/files/ipp2p-0.8.2-iptables-1.4.0.patch
tar xvzf ipp2p-0.8.2.tar.gz

cp -a ipp2p-0.8.2 ipp2p-0.8.2.orig
cd ipp2p-0.8.2
patch -p1 <../ipp2p-0.8.2-kernel-2.6.22.patch
patch -p1 <../ipp2p-0.8.2-iptables-1.4.0.patch

# ถ้าใช้ ld จะมีปัญหาในการโหลดโมดูล แก้ให้ใช้ gcc ที่บรรทัดท้ายๆของไฟล์ Makefile

vi Makefile

libipt_ipp2p.so: libipt_ipp2p.c ipt_ipp2p.h
$(CC) $(CFLAGS) $(IPTABLES_OPTION) $(IPTABLES_INCLUDE) -fPIC -c libipt_ipp2p.c
@# ld -shared -o libipt_ipp2p.so libipt_ipp2p.o
$(CC) -shared -o libipt_ipp2p.so libipt_ipp2p.o

clean:
-rm -f *.o *.so *.ko .*.cmd *.mod.c
endif

make
cp libipt_ipp2p.so /usr/local/lib/iptables/
cp ipt_ipp2p.ko /lib/modules/2.6.24-l7/kernel/net/netfilter/
depmod -a

11. Test

iptables -A FORWARD -m ipp2p --ipp2p -j DROP
iptables -A FORWARD -m layer7 --l7proto bittorrent -j DROP

mydebian:/usr/src/ipp2p-0.8.2# iptables -nvL
Chain INPUT (policy ACCEPT 1116 packets, 82622 bytes)
pkts bytes target prot opt in out source destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DROP all — * * 0.0.0.0/0 0.0.0.0/0 ipp2p v0.8.2 –ipp2p
0 0 DROP all — * * 0.0.0.0/0 0.0.0.0/0 LAYER7 l7proto bittorrent

Chain OUTPUT (policy ACCEPT 664 packets, 91251 bytes)
pkts bytes target prot opt in out source destination

mydebian:/usr/src/ipp2p-0.8.2# lsmod | egrep 'ipp2p|layer7'
xt_layer7 11236 1
nf_conntrack 62720 2 nf_conntrack_ipv4,xt_layer7
ipt_ipp2p 6848 1
x_tables 14372 3 xt_layer7,ipt_ipp2p,ip_tables

แต่ผมเพิ่มจากคุณสุชาติอีกนิดครับ เอาแค่ l7-Filter กับ ipp2p เอาไม่อยู่หรอกครับ ต้องเขียนเพิ่มอีกหน่อยใน Protocal ของ l7-Filter ครับ ดังนี้

สร้างไฟล์ชื่อ announce ขึ้นมาก่อนครับ ที่ห้อง protocol นะครับ
# Block announce bittorrent
announce
^get.+announce.+info_hash=

จากนั้นก็บันทึก
แล้วเพิ่มกฎเข้าไปอีกบรรทัดหนึ่ง
iptables -A FORWARD -m layer7 –l7proto announce -j DROP

ก็เป็นเกร็ดเล็ก ๆ น้อย ๆ ครับ หวังว่าคงใช้ได้นะครับ แต่ก็ไม่เป็นการถาวรหรอก ผมมองว่า Bittorrent นั้น ก็เหมือนกับ Virus แล้ว l7-Filter ก็เหมือนกับ Antivirus  ซึ่งอีกฝ่ายก็พยายามหนี อีกฝ่ายก็พยายามไล่  ถ้าฝ่ายไหนหยุด ก็ต้องตกเป็นฝ่ายพ่ายแพ้ในที่สุดครับ

VN:F [1.9.9_1125]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.9_1125]
Rating: 0 (from 0 votes)
Block Bittorrent, 10.0 out of 10 based on 1 rating

Comments are closed.