วันอาทิตย์ที่ 6 พฤษภาคม พ.ศ. 2555

block virus

#!/bin/sh #--- check ip wan ---# ppp0=`ifconfig | grep -A1 ppp0 | tail -1 | cut -d : -f 2 | cut -f 1 -d " "` ppp1=`ifconfig | grep -A1 ppp1 | tail -1 | cut -d : -f 2 | cut -f 1 -d " "` ppp2=`ifconfig | grep -A1 ppp2 | tail -1 | cut -d : -f 2 | cut -f 1 -d " "` #--- check gw wan ---# ppp0_gw=`ip route | grep ppp0 | head -1 | cut -f 1 -d " "` ppp1_gw=`ip route | grep ppp1 | head -1 | cut -f 1 -d " "` ppp2_gw=`ip route | grep ppp2 | head -1 | cut -f 1 -d " "` #--- add new SNAT ---# iptables -t nat -A POSTROUTING -o ppp0 -j SNAT --to-source $ppp0 iptables -t nat -A POSTROUTING -o ppp1 -j SNAT --to-source $ppp1 iptables -t nat -A POSTROUTING -o ppp2 -j SNAT --to-source $ppp2 #iptables -I INPUT -j ACCEPT iptables -I FORWARD -j ACCEPT iptables -I OUTPUT -j ACCEPT iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp -d 10.0.1.1/20 --dport 3128 -j DROP iptables -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.1.1/20 --dport 3128 -j DROP #--- gmember ---# iptables -t nat -I PREROUTING -i eth1 -p tcp -d youtube.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d hi5.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d facebook.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d gmember.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 203.151.207.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d song.gmember.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 174.36.4.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 174.36.56.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 208.43.218.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d rcw.ms --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d forums.overclockzone.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d overclockzone.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 202.170.126.119/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 216.239.61.100/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 203.144.244.116/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 164.115.2.135/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 174.36.56.184/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 203.146.140.137/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 208.43.218.80/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 38.117.107.188/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 174.36.242.26/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 69.65.59.240/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 209.17.69.4/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i eth1 -p tcp -d 61.19.12.17/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d youtube.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d hi5.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d facebook.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d gmember.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d 203.151.207.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d song.gmember.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d 174.36.4.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d 174.36.56.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d 208.43.218.0/24 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d rcw.ms --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d forums.overclockzone.com --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d overclockzone.com --dport 80 -j ACCEPT #--- HTTP Proxy service ---# if [ -f /var/run/squid.pid ]; then iptables -t nat -D PREROUTING -s 0/0 -i eth1 -p tcp --dport 80 -j REDIRECT --to-ports 3128 iptables -t nat -D PREROUTING -s 0/0 -i tun0 -p tcp --dport 80 -j REDIRECT --to-ports 3128 iptables -t nat -D PREROUTING -i eth1 -p tcp -d 10.0.1.1 --dport 80 -j ACCEPT iptables -t nat -D PREROUTING -i tun0 -p tcp -d 10.0.1.1 --dport 80 -j ACCEPT iptables -t nat -A PREROUTING -s 0/0 -i eth1 -p tcp --dport 80 -j REDIRECT --to-ports 3128 iptables -t nat -A PREROUTING -s 0/0 -i tun0 -p tcp --dport 80 -j REDIRECT --to-ports 3128 iptables -t nat -I PREROUTING -i eth1 -p tcp -d 10.0.1.1 --dport 80 -j ACCEPT iptables -t nat -I PREROUTING -i tun0 -p tcp -d 10.0.1.1 --dport 80 -j ACCEPT fi iptables -t mangle -A PREROUTING -i tun0 -m state --state NEW -j MULTIWAN_MARK iptables -t mangle -A PREROUTING -i tun0 -m state --state RELATED,ESTABLISHED -j MULTIWAN_RESTORE iptables -t mangle -A PREROUTING -m state --state NEW -j MULTIWAN_MARK iptables -t mangle -A PREROUTING -m state --state RELATED,ESTABLISHED -j MULTIWAN_RESTORE iptables -t mangle -I PREROUTING -j ACCEPT # Algo string iptables -A FORWARD -m string --algo bm --string "BitTorrent" -j DROP iptables -A FORWARD -m string --algo bm --string "BitTorrent protocol" -j DROP iptables -A FORWARD -m string --algo bm --string "peer_id=" -j DROP iptables -A FORWARD -m string --algo bm --string ".torrent" -j DROP iptables -A FORWARD -m string --algo bm --string "announce.php?passkey=" -j DROP iptables -A FORWARD -m string --algo bm --string "torrent"" -j DROP iptables -A FORWARD -m string --algo bm --string "announce"" -j DROP iptables -A FORWARD -m string --algo bm --string "info_hash" -j DROP #codered virus iptables -A FORWARD -m string --algo bm --string "/default.ida?" -j DROP #nimda virus iptables -A FORWARD -m string --algo bm --string ".exe?/c+dir" -j DROP iptables -A FORWARD -m string --algo bm --string ".exe?/c_tftp" -j DROP # Block Bit 100% iptables -t filter -I FORWARD -i eth+ -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j DROP iptables -t filter -I FORWARD -i tun0 -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j DROP iptables -t filter -I FORWARD -i ppp+ -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j DROP iptables -t filter -I FORWARD -m ipp2p --kazaa --gnu --edk --dc --bit --apple --soul --winmx --ares -j DROP # bittorrent key iptables -A FORWARD -m string --string "peer_id" --algo kmp --to 65535 -j DROP iptables -A FORWARD -m string --string "BitTorrent" --algo kmp --to 65535 -j DROP iptables -A FORWARD -m string --string "BitTorrent protocol" --algo kmp --to 65535 -j DROP iptables -A FORWARD -m string --string "bittorrent-announce" --algo kmp --to 65535 -j DROP iptables -A FORWARD -m string --string "announce.php?passkey=" --algo kmp --to 65535 -j DROP # ----- Block Bit iptables -A FORWARD -m ipp2p --ipp2p -j DROP iptables -I INPUT -s 0.0.0.0/0 -m string --string "info_hash" --algo bm -j DROP iptables -I INPUT -s 0.0.0.0/0 -m string --string "torrent" --algo bm -j DROP iptables -I INPUT -s 0.0.0.0/0 -m string --string "announce" --algo bm -j DROP # DHT keyword iptables -A FORWARD -m string --string "info_hash" --algo kmp --to 65535 -j DROP iptables -A FORWARD -m string --string "get_peers" --algo kmp --to 65535 -j DROP iptables -A FORWARD -m string --string "announce" --algo kmp --to 65535 -j DROP iptables -A FORWARD -m string --string "announce_peers" --algo kmp --to 65535 -j DROP #--- Block Bit layer7 ---# iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu iptables -I OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu iptables -I FORWARD -m ipp2p --bit -j DROP iptables -I INPUT -m ipp2p --bit -j DROP iptables -I OUTPUT -m ipp2p --bit -j DROP # Drop package wrom Virus Input iptables -I INPUT -p tcp --dport 135 -j DROP iptables -I INPUT -p udp --dport 135 -j DROP iptables -I INPUT -p tcp --dport 4444 -j DROP iptables -I INPUT -p udp --dport 4444 -j DROP iptables -I INPUT -p tcp --dport 5554 -j DROP iptables -I INPUT -p udp --dport 5554 -j DROP iptables -I INPUT -p tcp --dport 9996 -j DROP iptables -I INPUT -p udp --dport 9996 -j DROP iptables -I INPUT -p tcp --dport 137 -j DROP iptables -I INPUT -p udp --dport 137 -j DROP iptables -I INPUT -p tcp --dport 138 -j DROP iptables -I INPUT -p udp --dport 138 -j DROP iptables -I INPUT -p tcp --dport 139 -j DROP iptables -I INPUT -p udp --dport 139 -j DROP # Drop package wrom Virus Output iptables -I OUTPUT -p tcp --dport 135 -j DROP iptables -I OUTPUT -p udp --dport 135 -j DROP iptables -I OUTPUT -p tcp --dport 4444 -j DROP iptables -I OUTPUT -p udp --dport 4444 -j DROP iptables -I OUTPUT -p tcp --dport 5554 -j DROP iptables -I OUTPUT -p udp --dport 5554 -j DROP iptables -I OUTPUT -p tcp --dport 9996 -j DROP iptables -I OUTPUT -p udp --dport 9996 -j DROP iptables -I OUTPUT -p tcp --dport 137 -j DROP iptables -I OUTPUT -p udp --dport 137 -j DROP iptables -I OUTPUT -p tcp --dport 138 -j DROP iptables -I OUTPUT -p udp --dport 138 -j DROP iptables -I OUTPUT -p tcp --dport 139 -j DROP

มาปรับจูน DNS Server

มาปรับจูน DNS Server กันเถอะ(Clear os) Posted on 2011/09/05 DNS เป็นระบบจัดการในการแปลงจากชื่อไปเป็นหมายเลข IP Address (name-to-IP Address mapping) หรือในทางกลับกันมันก็สามารถแปลงจาก IP Address ไปเป็นชื่อที่มีการตั้งไว้ DNS ถือเป็นฐานข้อมูลแบบ กระจายชนิดหนึ่งที่มีการถูกเรียกใช้งานมากที่สุดและมีการเปลี่ยนแปลงมากที่สุดบนโลกใบนี้ ในระบบ DNS จะมี การเก็บชื่อและ IP Address ของเครื่องที่เกี่ยวข้องอย่างเป็นระบบลักษณะการทำงานจะเป็นแบบ Client/Server โดยที่ตัว Server จะเป็นตัวเก็บข้อมูลต่าง ๆ ที่เรียกว่าเป็น DNS Server (ที่มา : http://www.asiamediasoft.net/content/newboard/HowDNS) Dnsmasq เป็น DNS Server ชนิด forwarder+Caching แบบง่ายๆ ตัวเล็ก ประสิทธิภาพสูง (ถึงไม่เท่า Bind ก็เถอะ) และยังสามารถแจก DHCP ได้อีกด้วย ทุกอย่างที่ว่านี้มีอยู่ใน Clark Connect อยู่แล้วครับ ถ้าตอนติดตั้งไม่ลืมเลือกหัว DHCP and Caching DNS Servers มาด้วย จะเกิดอะไรขึ้นถ้า DNS Server หลักล้ม หรือไม่อัพเดทฐานข้อมูล หรืออัพเดทช้า หรือบางเว็บไซต์ที่นิยมๆถูกบล็อกจาก DNS บาง Server ลองนึกสภาพที่ไม่มี DNS Server อยู่ในร้านดูสิครับ จะเกิดอะไรขึ้น!!! เริ่มแรกกันเลย Copy สคิปที่อยู่ด้านล่างไปแทนที่อันเก่าที่ /etc/dnsmasq.conf # The “interface” parameter is set by the network policy (LAN/DMZ interfaces) bogus-priv # maybe make larger cache-size=512 # dhcp-authoritative dhcp-lease-max=1000 # block silly requests domain-needed filterwin2k # domain=system.lan expand-hosts # no-negcache strict-order user=nobody # Can make specific servers here and not use resolv.conf server=203.146.237.237 # csloxinfo 39 server=203.121.130.40 # Pacific 39.9 server=203.144.255.72 # asianet 40.9 server=202.69.137.137 # Triple T Global Net 41 server=202.44.144.33 # KSC 41.5 server=203.146.102.231 # truefaster 42.5 server=203.144.255.71 # asianet 42.8 server=202.129.27.134 # cattelecom 43.6 server=202.69.137.138 # Triple T Global Net 45 server=203.146.237.222 # csloxinfo 48.5 server=202.57.160.129 # Issp 48.9 server=202.6.100.1 # ABAC 50 server=203.121.130.39 # Pacific 51.5 server=203.155.33.1 # KSC 51.9 server=202.44.68.3 # Sripatum 52.7 server=203.144.207.49 # asianet (True) 54.5 server=203.144.207.29 # asianet (True) 58.1 server=202.57.128.71 # SGA 62 server=203.147.0.3 # Jasmine Internet 62.4 server=61.19.245.246 # cattelecom * server=61.19.254.134 # cattelecom * server=202.47.249.4 # cattelecom * server=203.148.255.70 # A-Net * server=203.148.255.78 # A-Net * server=203.149.0.2 # Samart * server=203.149.0.3 # Samart * server=203.146.222.3 # buddybb * server=203.158.144.1 # Rmutp * server=203.146.64.33 # Tnet * server=202.182.0.1 # FarEast * server=202.182.0.2 # FarEast * server=192.150.249.11 # Thammasat * server=208.67.222.222 # OpenDNS 277.8 server=208.67.220.220 # OpenDNS 285.1 # include another configuration conf-file=/etc/dnsmasq/dhcp.conf แก้ไข /etc/resolv.conf ตามสคิปด้านล่าง โค๊ด: nameserver 127.0.0.1 nameserver 192.168.1.1 สั่ง service dnsmasq restart ถ้าใครมีอะไีรเพิ่มเติมหรือชี้แนะ ก็เชิญได้เต็มที่เลยครับ เพราะผมก็ศึกษามาแบบงูๆปลาๆเหมือนกัน ส่วน list รายชื่อ dns server ที่ผมใส่มานั้น ผมได้ใช้เวลาหามาเกือบ 1 วันเต็ม จัดเรียงตามเร็ว (ping x+y+z/n) และคัดอันที่ใช้ไม่ได้หรือมีปัญหาิทิ้งแล้ว และทุกรายชื่อใช้ข้ามค่ายกันได้ครับ ใครมีรายชื่อเพิ่มเติมนอกจากนี้ก็โพทบอกได้เลยครับ (ควรเอา DNS ที่ตรง ISP ไปไว้แรกๆ) หรือถ้าใครอยากศึกษาคำสั่งเพิ่มเติม ก็ไปศึกษาได้ที่นี้เลยครับ http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html