iptables-firewallã¯IPãã¯ã¤ããªã¹ããå½å¥å¶éãFirewallãIDS/IPSãªã©ã®å種èªåçæããããã£ã«ã¿ãç¨éãã¨ã«èªç±ã«çµã¿åããã¦ã«ã¼ã«ã»ãããä½æããä»»æã®ãã¼ã«ã¨ãã¦è¨å®ã»éç¨ãããã¨ã§å³æ ¼ãã¤æè»ãªã¢ã¯ã»ã¹å¶å¾¡æ©æ§ãå®è£ ããã¹ã¯ãªããã§ãã
å°å ¥
GitHub - falsandtru/iptables-firewall: iptables rule generating and management script.
======================= PACKET FLOW EXAMPLE ======================= == config == ROLES=(SSH) SSH=(BLOCK_COUNTRY "file{1,2}|TRACK_PROWLER|DROP" LOCAL_COUNTRY FIERWALL IPF "IPS|LOG...|DROP") ... MAP=("${MAP[@]}" "INPUT -p tcp --dport 60022 -j SSH") MAP=("${MAP[@]}" "INPUT -j TRAP_PORTSCAN") MAP=("${MAP[@]}" "FORWARD -j TRAP_PORTSCAN") == apply == INTERNET ______ V ______________________________________________________ _______ INPUT | | TCP UDP ICMP | | | | TCP 60022 | TRAP_PORTSCAN ( --> TRACK_PROWLER ) --->| POLICY| | | | | | |====== | ======|===============================================| |_______| |====== V ======|===============================================| _______ Layer1 | | | | | BLOCK_COUNTRY --->| | |______________________________ V ______________________________| | | Layer2 | Rule1 | Rule101 | Rule201 | Rule202 | | | | file1 --> file2 -->TRACK_PROWLER--> DROP --->| | |______ V ______|______ V ______|______ V ______|_______________| | BLOCK | Layer3 | | | | | LOCAL_COUNTRY --->| | |______________________________ V ______________________________| | | Layer4 | | | | | FIERWALL ( --> TRACK_ATTACKER ) --->| | |______________________________ V ______________________________| | | Layer5 | | | | | IPF ( ANTI_PROWLER/ATTACKER ) --->| | |______________ V ______________________________________________| | | Layer6 | | | | | | | IDS/IPS --> LOG --> DROP --->| | | | | | | | |============== | ==============================================| |_______| |============== V ==============================================| SERVICE| | | === SSH SERVICE === | |_______________________________________________________________|
ç¹å¾´
ãã¼ã«ãã¼ã¹ã³ã³ããã¼ã«
ãã¼ã«ã«ããé©ç¨ããã«ã¼ã«ãã¾ã¨ãããããããç¨éã«ãããã¦ã«ã¼ã«ãè¨å®ããç¾å®ã®å®åã¢ãã«ã«åããéç¨ãæ軽ã«å®æ½ã§ãã¾ãã
åæè¨å®ã§ã¯GLOBAL/LOCAL/CONNECTION/SYSTEM/NETWORK/AUTH/PRIVATE/CUSTOMER/PUBLICãã¼ã«ãå®ç¾©ããã¦ãã¾ãã
# TESTãã¼ã«ãä½æ ROLES=(TEST) ... ...... # TESTãã¼ã«ãé©ç¨ MAP=("${MAP[@]}" "INPUT -p tcp --dport 8080 -j TEST")
ãã«ãã¬ã¤ã¤ãã£ã«ã¿ãªã³ã°
ãã¼ã«ã«è¨å®ããã«ã¼ã«ã»ããã¯ããã¯ã¤ããªã¹ããå½å¥å¶éãFirewallãIDS/IPSãªã©ããé¸æããå種ãã£ã«ã¿ãçµã¿åãããé ã«é©ç¨ãã¦ãããã«ãã¬ã¤ã¤ãã£ã«ã¿ã¨ãã¦åä½ãã¾ãã
# TESTãã¼ã«ã«ã«ã¼ã«ãè¨å® TEST=(whitelist/private LOCAL_COUNTRY FIREWALL IPF IPS ACCEPT) # 1. whitelist/private # ãã¡ã¤ã«ã«è¨è¿°ãããIPã®ã¿ééãããã»ãã¯é®æããã # # 2. LOCAL_COUNTRY # 許å¯ããå½ã®IPã®ã¿ééãããã»ãã¯é®æããã # # 3. FIREWALL # Firewallãé©ç¨ãæ¥ç¶ãæ¤ç«ããã # # 4. IPF # æ»æè¡çºã¾ãã¯ä¸å¯©è¡çºã®ãã£ãIPãé®æããã # # 5. IPS # æå®ã®ãã±ãããIPSã¸æ¸¡ãå¦çãçµããã # # 6. ACCEPT # 渡ãããªãã£ãæ®ãã®ãã±ããããã¹ã¦è¨±å¯ãå¦çãçµããã #
æ©è½
ãã¯ã¤ããªã¹ã
IPãè¨è¼ãããã¡ã¤ã«ããè¨è¼ããã¦ããIPã®ã¿ãééããããã£ã«ã¿ãçæãããã¯ã¤ããªã¹ãã«ããå³æ ¼ãªã¢ã¯ã»ã¹å¶éãè¡ãã¾ãã
# 1. whitelist/private # ãã¡ã¤ã«ã«è¨è¼ãããIPã®ã¿ééãããã»ãã¯é®æããã #
å½å¥ãã£ã«ã¿(ç¹å®å½ç¦æ¢/æ¥æ¬å½å éå®çå¶é)
ã¢ã¯ã»ã¹å¯è½ãªå½ãæ¥æ¬å½å ã®ã¿çç¹å®ã®å½ã®ã¿ã«å¶éãããã³ç¹å®ã®å½ããã®å ¨ã¢ã¯ã»ã¹ãç¦æ¢é®æãã¾ããIPã¨å½ã¨ã®å¯¾å¿ã¯å²ãå½ã¦ã®å®æ½çµç¹ã§ããå°åã¬ã¸ã¹ããªããèªåçã«åå¾ãé©ç¨ããã¾ãã
# è¨±å¯ æ¥æ¬ LOCAL_COUNTRY_CODE="JP" # æå¦ ä¸å½|é¦æ¸¯|ãã«ãª|éå½|åæé®® BLOCK_COUNTRY_CODE="CN|HK|MO|KR|KP"
# 2. LOCAL_COUNTRY # 許å¯ããå½ã®IPã®ã¿ééãããã»ãã¯é®æãããã #
Firewall
å種Firewallæ©è½ãå©ç¨ã§ãã¾ãã
# 3. FIREWALL # Firewallãé©ç¨ãæ¥ç¶ãæ¤ç«ããã #
PortscanTrap
å ¬éãã¦ããªããã¼ãã«ã¢ã¯ã»ã¹ã試ã¿ãIPãIPFã«ããé®æããIPã¨ãã¦è¿½è·¡ãã¾ãã
# 4. IPF # æ»æè¡çºã¾ãã¯ä¸å¯©è¡çºã®ãã£ãIPãé®æããã #
IDS/IPS
IDSã¾ãã¯IPSãå°å ¥ãã¦ããå ´åãããã«å¦çãå¼ã渡ãã¾ãã
# 5. IPS # æå®ã®ãã±ãããIPSã¸æ¸¡ãå¦çãçµããã # # 6. ACCEPT # 渡ãããªãã£ãæ®ãã®ãã±ããããã¹ã¦è¨±å¯ãå¦çãçµããã #
éç¨ä¾
iptables-firewallã¯ãµã¼ãã¼ãå©ç¨ããéã«è¦æ±ãããã»ãã¥ãªãã£æ©è½ã®ç¢ºä¿ã«å¯ä¸ãã¾ãã
ãã¼ãã¹ãã£ã³ã®è¿½è·¡
iptables-firewallã¯ãããã®VPSã§ãã¹ãéç¨ããã¦ãã¾ããããã®ãµã¼ãã¼ã¯ç®¡çè èªèº«ããå©ç¨ãã¦ããªãã«ãããããããã¦ããã£ã¹ãã«ãããã¼ãã¹ãã£ã³ãç´10åã«1åã1æ¥ã«100å以ä¸åãã¦ãã¾ãã
Nov 17 19:59:37 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=178.33.x.x DST=133.242.x.x LEN=44 TOS=0x00 PREC=0x00 TTL=48 ID=38796 PROTO=TCP SPT=80 DPT=28612 WINDOW=16384 RES=0x00 ACK SYN URGP=0 Nov 17 20:00:01 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=104.192.x.x DST=133.242.x.x LEN=28 TOS=0x08 PREC=0x00 TTL=234 ID=16288 PROTO=UDP SPT=40790 DPT=53413 LEN=8 Nov 17 20:07:08 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=114.38.x.x DST=133.242.x.x LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=23942 DF PROTO=TCP SPT=59270 DPT=23 WINDOW=5808 RES=0x00 SYN URGP=0 Nov 17 20:07:11 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=114.38.x.x DST=133.242.x.x LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=23943 DF PROTO=TCP SPT=59270 DPT=23 WINDOW=5808 RES=0x00 SYN URGP=0 Nov 17 20:07:17 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=114.38.x.x DST=133.242.x.x LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=23944 DF PROTO=TCP SPT=59270 DPT=23 WINDOW=5808 RES=0x00 SYN URGP=0 Nov 17 20:08:33 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=31.148.x.x DST=133.242.x.x LEN=40 TOS=0x10 PREC=0x00 TTL=245 ID=54321 PROTO=TCP SPT=46530 DPT=9064 WINDOW=65535 RES=0x00 SYN URGP=0 Nov 17 20:18:34 www kernel: [IPTABLES INVALID] : IN=eth0 OUT= MAC=xx SRC=66.150.x.x DST=133.242.x.x LEN=76 TOS=0x00 PREC=0x00 TTL=50 ID=12979 PROTO=ICMP TYPE=3 CODE=3 [SRC=133.242.x.x DST=66.150.x.x LEN=48 TOS=0x00 PREC=0x00 TTL=125 ID=27360 PROTO=UDP SPT=27005 DPT=27015 LEN=28 ] Nov 17 20:33:11 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=66.114.x.x DST=133.242.x.x LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=9599 DF PROTO=TCP SPT=3618 DPT=23 WINDOW=5840 RES=0x00 SYN URGP=0 Nov 17 20:33:17 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=66.114.x.x DST=133.242.x.x LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=9600 DF PROTO=TCP SPT=3618 DPT=23 WINDOW=5840 RES=0x00 SYN URGP=0 Nov 17 20:35:12 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=178.33.x.x DST=133.242.x.x LEN=44 TOS=0x00 PREC=0x00 TTL=48 ID=50103 PROTO=TCP SPT=80 DPT=25596 WINDOW=16384 RES=0x00 ACK SYN URGP=0 Nov 17 20:41:09 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=5.196.x.x DST=133.242.x.x LEN=44 TOS=0x00 PREC=0x00 TTL=46 ID=30348 PROTO=TCP SPT=443 DPT=55323 WINDOW=16384 RES=0x00 ACK SYN URGP=0 Nov 17 20:43:19 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=111.249.x.x DST=133.242.x.x LEN=40 TOS=0x00 PREC=0x00 TTL=111 ID=256 DF PROTO=TCP SPT=12200 DPT=21320 WINDOW=8192 RES=0x00 SYN URGP=0 Nov 17 20:43:41 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=8.8.x.x DST=133.242.x.x LEN=44 TOS=0x00 PREC=0x00 TTL=39 ID=48886 PROTO=TCP SPT=53 DPT=51501 WINDOW=42900 RES=0x00 ACK SYN URGP=0
ãã¼ãã¹ãã£ã³ããã¯ã©ããã³ã°ã¸
ãã®ãããªä¸è¦ç©ããã«è¦ãããã¼ãã¹ãã£ã³ã§ãã£ã¦ãããã¼ããçºè¦ããã¨é端ã«ç§éæ°åããæ°ååã®ç·å½ããæ»æãè¾æ¸æ»æãè¡ããµã¼ãã¼ã¸ä¾µå ¥ãããã¨ãã¦ããããæ¾ç½®ããã¨é常ã«å±éºã§ããéå»ã«8080çªãã¼ãã§ãµã¼ãã¼ç£è¦ãã¼ã«ã使ç¨ãã¦ããéã«æ»æãåãã¾ããã
ãã¯ã¤ããªã¹ãã®ä½æãå°é£ãªè¦ä»¶ã§ã®ã»ãã¥ãªãã£å¯¾å¿
ãµã¼ãã¹ãå°ãªãè³æ¬ã§éå¶ãã¦ããå ´åãããããæ»æãé¿ãããã¨SSHãã¼ããªã©ã®éè¦æ©è½ã¸æ¥ç¶å¯è½ãªIPãå¶éãããã¨ãã¦ããããã¤ãã¬ãã«ã¾ã§ã§ããIPã®ç¯å²ãçµãè¾¼ããã社å¡ã®å¤åºå ãèªå® ããã®æ¥ç¶ã許å¯ãããå ´åã¯ãããããå°é£ã¨ãªãã¾ãã
æ»æã®é®æããã³ãã¼ãã¹ãã£ã³ããã®ãã¼ãé è½
ãã®ãããªè¦ä»¶ã«ããã¦ããå½å¥ãã£ã«ã¿ã§æ¥ç¶ãæ¥æ¬å½å ã«éå®ããã¨ã¨ãã«ããã¼ãã¹ãã£ã³ãæ»æãè¡ã£ãIPãé®æãããã¡ã¤ã¢ã¦ã©ã¼ã«ã®ãªãã·ã§ã³æ©è½ã§ããFW_INTRUDERã«ãããã¼ããé è½ãããã¨ãã§ãã¾ããã¾ããæ»æãåããå ´åã§ãæ»æãæ¤ç¥ãã¦ä»¥éã®æ»æã¨ã¢ã¯ã»ã¹ãé®æãã¾ã(â»ãããã0-1023çªä»¥å¤ã®ãã¼ãã§ããå¿ è¦ããã)ã
# e.g. # å ¬éãã¦ããªããã¼ãã¸ã®ãã¼ãã¹ãã£ã³ã¨ãã£ãä¸å¯©è¡çºãæ»æãæ¤ç¥ãã¦IPã追跡 Nov 17 20:43:19 www kernel: [IPTABLES PORTSCAN] : IN=eth0 OUT= MAC=xx SRC=111.249.x.x DST=133.242.x.x LEN=40 TOS=0x00 PREC=0x00 TTL=111 ID=256 DF PROTO=TCP SPT=12200 DPT=21320 WINDOW=8192 RES=0x00 SYN URGP=0 # 追跡ä¸ã®ä¸å¯©ãªIPããã®éè¦æ©è½ã¸ã®ã¢ã¯ã»ã¹ãé®æãã¦å ¬éãã¼ããä¿è·ã»é è½ Nov 17 20:43:19 www kernel: [IPTABLES INTRUDER] : IN=eth0 OUT= MAC=xx SRC=111.249.x.x DST=133.242.x.x LEN=40 TOS=0x00 PREC=0x00 TTL=111 ID=256 DF PROTO=TCP SPT=12200 DPT=10022 WINDOW=8192 RES=0x00 SYN URGP=0
ãµã¼ãã¼ã®ãããã¯ã¼ã¯ã»ãã¥ãªãã£åä¸ã«
以ä¸ã®ããã«ãiptables-firewallã¯å®ç¨çãªãããã¯ã¼ã¯ã»ãã¥ãªãã£ã®å°å ¥ã容æã«ãã¾ãã