{"id":94,"date":"2021-02-27T15:14:32","date_gmt":"2021-02-27T06:14:32","guid":{"rendered":"http:\/\/www.feelkind.com\/blog\/?p=94"},"modified":"2021-02-27T15:15:17","modified_gmt":"2021-02-27T06:15:17","slug":"centos7%e3%80%81firewalld%e3%82%92%e6%ad%a2%e3%82%81%e3%81%a6iptables%e3%81%ab%e3%81%99%e3%82%8b%e9%9a%9b%e3%81%ae%e3%83%89%e3%83%8f%e3%83%9e%e3%82%8a%e8%a7%a3%e6%b1%ba","status":"publish","type":"post","link":"http:\/\/www.feelkind.com\/blog\/?p=94","title":{"rendered":"CentOS7\u3001firewalld\u3092\u6b62\u3081\u3066iptables\u306b\u3059\u308b\u969b\u306e\u30c9\u30cf\u30de\u308a\u89e3\u6c7a"},"content":{"rendered":"\n<p>CentOS7\u3067\u306f\u3044\u308f\u3086\u308b\u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb\u3068\u3057\u3066firewalld\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3088\u304f\u89e3\u3089\u306a\u3044\u306e\u3067\u3001\u6614\u304b\u3089\u4f7f\u3044\u6163\u308c\u305fiptables\u3092\u4f7f\u3046\u3068\u3044\u3063\u305f\u65b9\u304c\u6570\u591a\u304f\u898b\u53d7\u3051\u3089\u308c\u307e\u3059\u3002<br>\u300c\u306a\u3093\u3061\u3083\u3063\u3066\u7ba1\u7406\u8005\u300d\u306e\u79c1\u3082\u305d\u306e\u4e00\u4eba\u3001\u305d\u3082\u305d\u3082iptables\u306f\u5168\u304f\u7406\u89e3\u51fa\u6765\u3066\u306a\u3044\u77e5\u898b\u30fb\u529b\u91cf\u30ec\u30d9\u30eb\u3067\u3059\u304c\u3001\u4ed6\u4eba\u69d8\u304c\u4f5c\u3089\u308c\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u306a\u3069\u3092\u8ee2\u7528\u3057\u3066\u4f7f\u308f\u305b\u3066\u3044\u305f\u3060\u3044\u3066\u307e\u3059\u3002<br>\u3057\u304b\u3057\u3001\u4e38\u30b3\u30d4\u30fc\u3067\u306f\u52d5\u304b\u306a\u3044\uff08\u3053\u308c\u306f\u5f53\u7136\uff09\u3060\u3051\u3067\u306a\u304f\u3001\u30b5\u30fc\u30d0\u3068\u5916\u90e8\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u901a\u4fe1\u304c\u906e\u65ad\u3055\u308c\u308b\uff08\u5168\u304f\u3067\u304d\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\uff09\u3068\u3044\u3063\u305f\u30c9\u30cf\u30de\u308a\u30dd\u30a4\u30f3\u30c8\u3082\u3042\u308a\u30011w\u307b\u3069\u60a9\u3093\u3067\u307e\u3057\u305f\u3002<br><br>\u7d50\u679c\u3068\u3057\u3066\u3001\u5c11\u3057\u305a\u3064\u30c8\u30e9\u30a4\u30a2\u30f3\u30c9\u30a8\u30e9\u30fc\u3067\u8a66\u3057\u3066\u3044\u304f\u4e8b\u3067\u30cf\u30de\u30ea\u30dd\u30a4\u30f3\u30c8\u304b\u3089\u306f\u8131\u51fa\u3067\u304d\u305f\u3088\u3046\u306a\u306e\u3067\u3001\u305d\u306e\u5185\u5bb9\u3092\u5099\u5fd8\u9332\u3068\u3057\u3066\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br>\u4ed6\u306e\u65b9\u3005\u306e\u74b0\u5883\u3067\u6b63\u3057\u304f\u52d5\u304f\u304b\u3001\u307e\u305f\u3001\u3053\u306e\u5185\u5bb9\u304c\u59a5\u5f53\u304b\u3069\u3046\u304b\u306f\u4e0d\u660e\u30fb\u7121\u4fdd\u8a3c\u306a\u306e\u3067\u3054\u6ce8\u610f\u4e0b\u3055\u3044\u3002<br><br>\u53c2\u8003\u306b\u3057\u305f\u30eb\u30fc\u30c8\u30b3\u30f3\u30c6\u30f3\u30c4\u306f\u3053\u3061\u3089<br>\u300c\u4ffa\u53f2\u4e0a\u6700\u5f37\u306eiptables\u3092\u3055\u3089\u3059\u300d<br>https:\/\/qiita.com\/suin\/items\/5c4e21fa284497782f71<br>\uff082021\u5e74\u6642\u70b9\u3067\u306f\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u3055\u308c\u3066\u3044\u306a\u3044\u6a21\u69d8\uff09<br><br>\uff0d\uff0d\uff0d\uff0d\u4ee5\u4e0b\u3001\u5f53\u5bb6\u81ea\u9bd6\u7528\u306b\u30a2\u30ec\u30f3\u30b8\u3057\u305f\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3002<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>#!bin\/bash\n\n\n# \u30d1\u30b9\nPATH=\/sbin:\/usr\/sbin:\/bin:\/usr\/bin\n\n###########################################################\n# IP\u306e\u5b9a\u7fa9\n# \u5fc5\u8981\u306b\u5fdc\u3058\u3066\u5b9a\u7fa9\u3059\u308b\u3002\u5b9a\u7fa9\u3057\u306a\u304f\u3066\u3082\u52d5\u4f5c\u3059\u308b\u3002\n###########################################################\n\n# \u5185\u90e8\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3068\u3057\u3066\u8a31\u53ef\u3059\u308b\u7bc4\u56f2\n# LOCAL_NET=\"xxx.xxx.xxx.xxx\/xx\"\nLOCAL_NET=\"192.168.0.0\/24\"\n\n# \u5185\u90e8\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3068\u3057\u3066\u4e00\u90e8\u5236\u9650\u4ed8\u304d\u3067\u8a31\u53ef\u3059\u308b\u7bc4\u56f2\n# LIMITED_LOCAL_NET=\"xxx.xxx.xxx.xxx\/xx\"\n\n# Zabbix\u30b5\u30fc\u30d0\u30fcIP\n# ZABBIX_IP=\"xxx.xxx.xxx.xxx\"\nZABBIX_IP=\"192.168.0.5\"\n\n# \u5168\u3066\u306eIP\u3092\u8868\u3059\u8a2d\u5b9a\u3092\u5b9a\u7fa9\nANY=\"0.0.0.0\/0\"\n\n# \u4fe1\u983c\u53ef\u80fd\u30db\u30b9\u30c8(\u914d\u5217)\n# ALLOW_HOSTS=(\n# \t\"xxx.xxx.xxx.xxx\"\n# \t\"xxx.xxx.xxx.xxx\"\n# \t\"xxx.xxx.xxx.xxx\"\n# )\n\n#2nd DNS\nALLOW_HOSTS=(\n#SELF\n        \"127.0.0.1\"\n        \"192.168.0.5\"\n#       win10pc\n        \"192.168.0.51\"\n#       \/* 2nd name server 1\/3 *\/\n        \"(2nd name server 1\/3\u306eip)\"\n\n#       \/* 2nd name server 2\/3 *\/\n        \"(2nd name server 2\/3\u306eip)\"\n\n#       \/* 2nd name server 3\/3 *\/\n        \"(2nd name server 3\/3\u306eip)\"\n)\n\n\n# \u7121\u6761\u4ef6\u7834\u68c4\u3059\u308b\u30ea\u30b9\u30c8(\u914d\u5217)\n# DENY_HOSTS=(\n# \t\"xxx.xxx.xxx.xxx\"\n# \t\"xxx.xxx.xxx.xxx\"\n# \t\"xxx.xxx.xxx.xxx\"\n# )\n\n###########################################################\n# \u30dd\u30fc\u30c8\u5b9a\u7fa9\n###########################################################\n\nSSH=20022\nFTP=20,21\nDNS=53\nSMTP=25,465,587\nPOP3=110,995\nIMAP=143,993\n\n#http2812\u306fmonit\u300110000\u306fwebmin\u300110024,10026\u306famavis\u7528\nHTTP=80,443,2812,10000,10024,10026\nIDENT=113\nNTP=123\nMYSQL=3306\nNET_BIOS=135,137,138,139,445\nDHCP=67,68\n\n###########################################################\n# \u95a2\u6570\n###########################################################\n\n# iptables\u306e\u521d\u671f\u5316, \u3059\u3079\u3066\u306e\u30eb\u30fc\u30eb\u3092\u524a\u9664\ninitialize() \n{\n\n##Assertion failed on job for iptables.service.\u30a8\u30e9\u30fc\u5bfe\u7b56\niptables -S\nservice iptables save\n##\n\n# \u30c6\u30fc\u30d6\u30eb\u521d\u671f\u5316\n\tiptables -F\n\n# \u30c1\u30a7\u30fc\u30f3\u3092\u524a\u9664\n\tiptables -X\n\n# \u30d1\u30b1\u30c3\u30c8\u30ab\u30a6\u30f3\u30bf\u30fb\u30d0\u30a4\u30c8\u30ab\u30a6\u30f3\u30bf\u3092\u30af\u30ea\u30a2\n\tiptables -Z\n\n\tiptables -P INPUT   ACCEPT\n\tiptables -P OUTPUT  ACCEPT\n\tiptables -P FORWARD ACCEPT\n}\n\n# \u30eb\u30fc\u30eb\u9069\u7528\u5f8c\u306e\u51e6\u7406\nfinailize()\n{\n# \u8a2d\u5b9a\u306e\u4fdd\u5b58\n# \u4fdd\u5b58\u3057\u305f\u3082\u306e\u3067\u518d\u8d77\u52d5\u3057\u3066\u307f\u308b\n\treturn 0\n\t\/usr\/libexec\/iptables\/iptables.init save&amp;&amp;\n#\tiptables-save &amp;&amp;\n\tsystemctl restart iptables &amp;&amp;\n\treturn 1\n}\n\n# \u958b\u767a\u7528\nif &#91; \"$1\" == \"dev\" ]\nthen\n\tiptables() { echo \"iptables $@\"; }\n\tfinailize() { echo \"finailize\"; }\nfi\n\n###########################################################\n# iptables\u306e\u521d\u671f\u5316\n###########################################################\ninitialize\n\n\n###########################################################\n# \u30dd\u30ea\u30b7\u30fc\u306e\u6c7a\u5b9a\n###########################################################\n\n# \u3059\u3079\u3066DROP\u3002\u3059\u3079\u3066\u306e\u7a74\u3092\u3075\u3055\u3044\u3067\u304b\u3089\u5fc5\u8981\u306a\u30dd\u30fc\u30c8\u3092\u7a7a\u3051\u3066\u3044\u304f\u306e\u304c\u826f\u3044\u3002\niptables -P INPUT   DROP\n\niptables -P OUTPUT  ACCEPT\niptables -P FORWARD DROP\n\n###########################################################\n# \u4fe1\u983c\u53ef\u80fd\u306a\u30db\u30b9\u30c8\u306f\u8a31\u53ef\n###########################################################\n\n# \u30ed\u30fc\u30ab\u30eb\u30db\u30b9\u30c8\n# lo \u306f\u30ed\u30fc\u30ab\u30eb\u30eb\u30fc\u30d7\u30d0\u30c3\u30af\u306e\u3053\u3068\u3067\u81ea\u5206\u81ea\u8eab\u306e\u30db\u30b9\u30c8\u3092\u6307\u3059\n\n# SELF -&gt; SELF\niptables -A INPUT -i lo -j ACCEPT\n\n# \u30ed\u30fc\u30ab\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\n# $LOCAL_NET \u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308c\u3070 LAN\u4e0a\u306e\u4ed6\u306e\u30b5\u30fc\u30d0\u3068\u306e\u3084\u308a\u53d6\u308a\u3092\u8a31\u53ef\u3059\u308b\nif &#91; \"$LOCAL_NET\" ]\nthen\n\n# LOCAL_NET -&gt; SELF\n\tiptables -A INPUT -p tcp -s $LOCAL_NET -j ACCEPT\n\nfi\n\n# \u4fe1\u983c\u53ef\u80fd\u30db\u30b9\u30c8\n# $ALLOW_HOSTS \u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308c\u3070 \u305d\u306e\u30db\u30b9\u30c8\u3068\u306e\u3084\u308a\u53d6\u308a\u3092\u8a31\u53ef\u3059\u308b\nif &#91; \"${ALLOW_HOSTS}\" ]\nthen\n\tfor allow_host in ${ALLOW_HOSTS&#91;@]}\n\tdo\n\n# allow_host -&gt; SELF\n\t\tiptables -A INPUT -p tcp -s $allow_host -j ACCEPT\n\tdone\nfi\n\n###########################################################\n# $DENY_HOSTS\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u306f\u7834\u68c4\n###########################################################\nif &#91; \"${DENY_HOSTS}\" ]\nthen\n\tfor deny_host in ${DENY_HOSTS&#91;@]}\n\tdo\n\t\tiptables -A INPUT -s $deny_host -m limit --limit 1\/s -j LOG --log-prefix \"deny_host: \"\n\t\tiptables -A INPUT -s $deny_host -j DROP\n\tdone\nfi\n\n###########################################################\n# \u30bb\u30c3\u30b7\u30e7\u30f3\u78ba\u7acb\u5f8c\u306e\u30d1\u30b1\u30c3\u30c8\u758e\u901a\u306f\u8a31\u53ef\n###########################################################\niptables -A INPUT  -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: Stealth Scan\n###########################################################\n\n# \"STEALTH_SCAN\" \u3068\u3044\u3046\u540d\u524d\u3067\u30c1\u30a7\u30fc\u30f3\u3092\u4f5c\u308b\niptables -N STEALTH_SCAN\niptables -A STEALTH_SCAN -j LOG --log-prefix \"stealth_scan_attack: \"\niptables -A STEALTH_SCAN -j DROP\n\n# \u30b9\u30c6\u30eb\u30b9\u30b9\u30ad\u30e3\u30f3\u3089\u3057\u304d\u30d1\u30b1\u30c3\u30c8\u306f \"STEALTH_SCAN\" \u30c1\u30a7\u30fc\u30f3\u3078\u30b8\u30e3\u30f3\u30d7\u3059\u308b\niptables -A INPUT -p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW -j STEALTH_SCAN\niptables -A INPUT -p tcp --tcp-flags ALL NONE -j STEALTH_SCAN\n\niptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN         -j STEALTH_SCAN\niptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST         -j STEALTH_SCAN\niptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j STEALTH_SCAN\n\niptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j STEALTH_SCAN\niptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN     -j STEALTH_SCAN\niptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH     -j STEALTH_SCAN\niptables -A INPUT -p tcp --tcp-flags ACK,URG URG     -j STEALTH_SCAN\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: \u30d5\u30e9\u30b0\u30e1\u30f3\u30c8\u30d1\u30b1\u30c3\u30c8\u306b\u3088\u308b\u30dd\u30fc\u30c8\u30b9\u30ad\u30e3\u30f3,DOS\u653b\u6483\n# namap -v -sF \u306a\u3069\u306e\u5bfe\u7b56\n###########################################################\niptables -A INPUT -f -j LOG --log-prefix 'fragment_packet:'\niptables -A INPUT -f -j DROP\n \n\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: Ping of Death\n###########################################################\n# \u6bce\u79d21\u56de\u3092\u8d85\u3048\u308bping\u304c10\u56de\u7d9a\u3044\u305f\u3089\u7834\u68c4\n\n# \"PING_OF_DEATH\" \u3068\u3044\u3046\u540d\u524d\u3067\u30c1\u30a7\u30fc\u30f3\u3092\u4f5c\u308b\niptables -N PING_OF_DEATH\niptables -A PING_OF_DEATH -p icmp --icmp-type echo-request \\\n         -m hashlimit \\\n         --hashlimit 1\/s \\\n         --hashlimit-burst 10 \\\n         --hashlimit-htable-expire 300000 \\\n         --hashlimit-mode srcip \\\n         --hashlimit-name t_PING_OF_DEATH \\\n         -j RETURN\n\n# \u5236\u9650\u3092\u8d85\u3048\u305fICMP\u3092\u7834\u68c4\niptables -A PING_OF_DEATH -j LOG --log-prefix \"ping_of_death_attack: \"\niptables -A PING_OF_DEATH -j DROP\n\n# ICMP \u306f \"PING_OF_DEATH\" \u30c1\u30a7\u30fc\u30f3\u3078\u30b8\u30e3\u30f3\u30d7\niptables -A INPUT -p icmp --icmp-type echo-request -j PING_OF_DEATH\n\n\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: SYN Flood Attack\n# \u3053\u306e\u5bfe\u7b56\u306b\u52a0\u3048\u3066 Syn Cookie \u3092\u6709\u52b9\u306b\u3059\u3079\u3057\u3002\n###########################################################\n\n# \"SYN_FLOOD\" \u3068\u3044\u3046\u540d\u524d\u3067\u30c1\u30a7\u30fc\u30f3\u3092\u4f5c\u308b\niptables -N SYN_FLOOD\niptables -A SYN_FLOOD -p tcp --syn \\\n         -m hashlimit \\\n         --hashlimit 200\/s \\\n         --hashlimit-burst 3 \\\n         --hashlimit-htable-expire 300000 \\\n         --hashlimit-mode srcip \\\n         --hashlimit-name t_SYN_FLOOD \\\n         -j RETURN\n\n# \u89e3\u8aac\n# -m hashlimit                       \u30db\u30b9\u30c8\u3054\u3068\u306b\u5236\u9650\u3059\u308b\u305f\u3081 limit \u3067\u306f\u306a\u304f hashlimit \u3092\u5229\u7528\u3059\u308b\n# --hashlimit 200\/s                  \u79d2\u9593\u306b200\u63a5\u7d9a\u3092\u4e0a\u9650\u306b\u3059\u308b\n# --hashlimit-burst 3                \u4e0a\u8a18\u306e\u4e0a\u9650\u3092\u8d85\u3048\u305f\u63a5\u7d9a\u304c3\u56de\u9023\u7d9a\u3067\u3042\u308c\u3070\u5236\u9650\u304c\u304b\u304b\u308b\n# --hashlimit-htable-expire 300000   \u7ba1\u7406\u30c6\u30fc\u30d6\u30eb\u4e2d\u306e\u30ec\u30b3\u30fc\u30c9\u306e\u6709\u52b9\u671f\u9593\uff08\u5358\u4f4d\uff1ams\n# --hashlimit-mode srcip             \u9001\u4fe1\u5143\u30a2\u30c9\u30ec\u30b9\u3067\u30ea\u30af\u30a8\u30b9\u30c8\u6570\u3092\u7ba1\u7406\u3059\u308b\n# --hashlimit-name t_SYN_FLOOD       \/proc\/net\/ipt_hashlimit \u306b\u4fdd\u5b58\u3055\u308c\u308b\u30cf\u30c3\u30b7\u30e5\u30c6\u30fc\u30d6\u30eb\u540d\n# -j RETURN                          \u5236\u9650\u4ee5\u5185\u3067\u3042\u308c\u3070\u3001\u89aa\u30c1\u30a7\u30fc\u30f3\u306b\u623b\u308b\n\n# \u5236\u9650\u3092\u8d85\u3048\u305fSYN\u30d1\u30b1\u30c3\u30c8\u3092\u7834\u68c4\niptables -A SYN_FLOOD -j LOG --log-prefix \"syn_flood_attack: \"\niptables -A SYN_FLOOD -j DROP\n\n# SYN\u30d1\u30b1\u30c3\u30c8\u306f \"SYN_FLOOD\" \u30c1\u30a7\u30fc\u30f3\u3078\u30b8\u30e3\u30f3\u30d7\niptables -A INPUT -p tcp --syn -j SYN_FLOOD\n\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: HTTP DoS\/DDoS Attack\n###########################################################\n\n# \"HTTP_DOS\" \u3068\u3044\u3046\u540d\u524d\u3067\u30c1\u30a7\u30fc\u30f3\u3092\u4f5c\u308b\niptables -N HTTP_DOS\niptables -A HTTP_DOS -p tcp -m multiport --dports $HTTP \\\n         -m hashlimit \\\n         --hashlimit 1\/s \\\n         --hashlimit-burst 100 \\\n         --hashlimit-htable-expire 300000 \\\n         --hashlimit-mode srcip \\\n         --hashlimit-name t_HTTP_DOS \\\n         -j RETURN\n\n# \u89e3\u8aac\n# -m hashlimit                       \u30db\u30b9\u30c8\u3054\u3068\u306b\u5236\u9650\u3059\u308b\u305f\u3081 limit \u3067\u306f\u306a\u304f hashlimit \u3092\u5229\u7528\u3059\u308b\n# --hashlimit 1\/s                    \u79d2\u95931\u63a5\u7d9a\u3092\u4e0a\u9650\u3068\u3059\u308b\n# --hashlimit-burst 100              \u4e0a\u8a18\u306e\u4e0a\u9650\u3092100\u56de\u9023\u7d9a\u3067\u8d85\u3048\u308b\u3068\u5236\u9650\u304c\u304b\u304b\u308b\n# --hashlimit-htable-expire 300000   \u7ba1\u7406\u30c6\u30fc\u30d6\u30eb\u4e2d\u306e\u30ec\u30b3\u30fc\u30c9\u306e\u6709\u52b9\u671f\u9593\uff08\u5358\u4f4d\uff1ams\n# --hashlimit-mode srcip             \u9001\u4fe1\u5143\u30a2\u30c9\u30ec\u30b9\u3067\u30ea\u30af\u30a8\u30b9\u30c8\u6570\u3092\u7ba1\u7406\u3059\u308b\n# --hashlimit-name t_HTTP_DOS        \/proc\/net\/ipt_hashlimit \u306b\u4fdd\u5b58\u3055\u308c\u308b\u30cf\u30c3\u30b7\u30e5\u30c6\u30fc\u30d6\u30eb\u540d\n# -j RETURN                          \u5236\u9650\u4ee5\u5185\u3067\u3042\u308c\u3070\u3001\u89aa\u30c1\u30a7\u30fc\u30f3\u306b\u623b\u308b\n\n# \u5236\u9650\u3092\u8d85\u3048\u305f\u63a5\u7d9a\u3092\u7834\u68c4\niptables -A HTTP_DOS -j LOG --log-prefix \"http_dos_attack: \"\niptables -A HTTP_DOS -j DROP\n\n# HTTP\u3078\u306e\u30d1\u30b1\u30c3\u30c8\u306f \"HTTP_DOS\" \u30c1\u30a7\u30fc\u30f3\u3078\u30b8\u30e3\u30f3\u30d7\niptables -A INPUT -p tcp -m multiport --dports $HTTP -j HTTP_DOS\n\n\n\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: IDENT port probe\n# ident\u3092\u5229\u7528\u3057\u653b\u6483\u8005\u304c\u5c06\u6765\u306e\u653b\u6483\u306b\u5099\u3048\u308b\u305f\u3081\u3001\u3042\u308b\u3044\u306f\u30e6\u30fc\u30b6\u30fc\u306e\n# \u30b7\u30b9\u30c6\u30e0\u304c\u653b\u6483\u3057\u3084\u3059\u3044\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u30dd\u30fc\u30c8\u8abf\u67fb\u3092\u5b9f\u884c\n# \u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\n# DROP \u3067\u306f\u30e1\u30fc\u30eb\u30b5\u30fc\u30d0\u7b49\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u4f4e\u4e0b\u306b\u306a\u308b\u305f\u3081 REJECT\u3059\u308b\n###########################################################\niptables -A INPUT -p tcp -m multiport --dports $IDENT -j REJECT --reject-with tcp-reset\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: SSH Brute Force\n# SSH\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u8a8d\u8a3c\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u30b5\u30fc\u30d0\u306e\u5834\u5408\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u7dcf\u5f53\u308a\u653b\u6483\u306b\u5099\u3048\u308b\u3002\n# 1\u5206\u9593\u306b5\u56de\u3057\u304b\u63a5\u7d9a\u30c8\u30e9\u30a4\u3092\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3002\n# SSH\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u304c\u518d\u63a5\u7d9a\u3092\u7e70\u308a\u8fd4\u3059\u306e\u3092\u9632\u3050\u305f\u3081DROP\u3067\u306f\u306a\u304fREJECT\u306b\u3059\u308b\u3002\n# SSH\u30b5\u30fc\u30d0\u304c\u30d1\u30b9\u30ef\u30fc\u30c9\u8a8d\u8a3cON\u306e\u5834\u5408\u3001\u4ee5\u4e0b\u3092\u30a2\u30f3\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3059\u308b\n###########################################################\niptables -A INPUT -p tcp --syn -m multiport --dports $SSH -m recent --name ssh_attack --set\niptables -A INPUT -p tcp --syn -m multiport --dports $SSH -m recent --name ssh_attack --rcheck --seconds 60 --hitcount 5 -j LOG --log-prefix \"ssh_brute_force: \"\niptables -A INPUT -p tcp --syn -m multiport --dports $SSH -m recent --name ssh_attack --rcheck --seconds 60 --hitcount 5 -j REJECT --reject-with tcp-reset\n\n\n###########################################################\n# \u653b\u6483\u5bfe\u7b56: FTP Brute Force\n# FTP\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u8a8d\u8a3c\u306e\u305f\u3081\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u7dcf\u5f53\u308a\u653b\u6483\u306b\u5099\u3048\u308b\u3002\n# 1\u5206\u9593\u306b5\u56de\u3057\u304b\u63a5\u7d9a\u30c8\u30e9\u30a4\u3092\u3067\u304d\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3002\n# FTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u304c\u518d\u63a5\u7d9a\u3092\u7e70\u308a\u8fd4\u3059\u306e\u3092\u9632\u3050\u305f\u3081DROP\u3067\u306f\u306a\u304fREJECT\u306b\u3059\u308b\u3002\n# FTP\u30b5\u30fc\u30d0\u3092\u7acb\u3061\u4e0a\u3052\u3066\u3044\u308b\u5834\u5408\u3001\u4ee5\u4e0b\u3092\u30a2\u30f3\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3059\u308b\n###########################################################\niptables -A INPUT -p tcp --syn -m multiport --dports $FTP -m recent --name ftp_attack --set\niptables -A INPUT -p tcp --syn -m multiport --dports $FTP -m recent --name ftp_attack --rcheck --seconds 60 --hitcount 5 -j LOG --log-prefix \"ftp_brute_force: \"\niptables -A INPUT -p tcp --syn -m multiport --dports $FTP -m recent --name ftp_attack --rcheck --seconds 60 --hitcount 5 -j REJECT --reject-with tcp-reset\n\n###########################################################\n# \u5168\u30db\u30b9\u30c8(\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c8\u30a2\u30c9\u30ec\u30b9\u3001\u30de\u30eb\u30c1\u30ad\u30e3\u30b9\u30c8\u30a2\u30c9\u30ec\u30b9)\u5b9b\u30d1\u30b1\u30c3\u30c8\u306f\u7834\u68c4\n###########################################################\niptables -A INPUT -d 192.168.0.255   -j LOG --log-prefix \"drop_broadcast: \"\niptables -A INPUT -d 192.168.0.255   -j DROP\niptables -A INPUT -d 255.255.255.255 -j LOG --log-prefix \"drop_broadcast: \"\niptables -A INPUT -d 255.255.255.255 -j DROP\niptables -A INPUT -d 224.0.0.1       -j LOG --log-prefix \"drop_broadcast: \"\niptables -A INPUT -d 224.0.0.1       -j DROP\n\n\n\n###########################################################\n# \u5168\u30db\u30b9\u30c8(ANY)\u304b\u3089\u306e\u5165\u529b\u8a31\u53ef\n###########################################################\n\n# ICMP: ping \u306b\u5fdc\u7b54\u3059\u308b\u8a2d\u5b9a\n\n# ANY -&gt; SELF\niptables -A INPUT -p icmp -j ACCEPT\n\n# HTTP, HTTPS\n# ANY -&gt; SELF\niptables -A INPUT -p tcp -m multiport --dports $HTTP -j ACCEPT\n\n# SSH: \u30db\u30b9\u30c8\u3092\u5236\u9650\u3059\u308b\u5834\u5408\u306f TRUST_HOSTS \u306b\u4fe1\u983c\u30db\u30b9\u30c8\u3092\u66f8\u304d\u4e0b\u8a18\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3059\u308b\n# ANY -&gt; SELF\niptables -A INPUT -p tcp -m multiport --dports $SSH -j ACCEPT\n\n# FTP\n# ANY -&gt; SELF\niptables -A INPUT -p tcp -m multiport --dports $FTP -j ACCEPT\n\n# DNS\n# ANY -&gt; SELF\niptables -A INPUT -p tcp -m multiport --sports $DNS -j ACCEPT\n\n# SMTP\n# ANY -&gt; SELF\niptables -A INPUT -p tcp -m multiport --sports $SMTP -j ACCEPT\n\n# POP3\n# ANY -&gt; SELF\niptables -A INPUT -p tcp -m multiport --sports $POP3 -j ACCEPT\n\n# IMAP\n# ANY -&gt; SELF\niptables -A INPUT -p tcp -m multiport --sports $IMAP -j ACCEPT\n\n\n###########################################################\n# \u30ed\u30fc\u30ab\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af(\u5236\u9650\u4ed8\u304d)\u304b\u3089\u306e\u5165\u529b\u8a31\u53ef\n###########################################################\n\nif &#91; \"$LIMITED_LOCAL_NET\" ]\nthen\n\t# SSH\n\n# LIMITED_LOCAL_NET -&gt; SELF\n\tiptables -A INPUT -p tcp -s $LIMITED_LOCAL_NET -m multiport --dports $SSH -j ACCEPT\n\t\n\t# FTP\n# LIMITED_LOCAL_NET -&gt; SELF\n\tiptables -A INPUT -p tcp -s $LIMITED_LOCAL_NET -m multiport --dports $FTP -j ACCEPT\n\n\t# MySQL\n# LIMITED_LOCAL_NET -&gt; SELF\n\tiptables -A INPUT -p tcp -s $LIMITED_LOCAL_NET -m multiport --dports $MYSQL -j ACCEPT\nfi\n\n###########################################################\n# \u7279\u5b9a\u30db\u30b9\u30c8\u304b\u3089\u306e\u5165\u529b\u8a31\u53ef\n###########################################################\n\nif &#91; \"$ZABBIX_IP\" ]\nthen\n\t# Zabbix\u95a2\u9023\u3092\u8a31\u53ef\n# Zabbix -&gt; SELF\n\tiptables -A INPUT -p tcp -s $ZABBIX_IP --dport 10050 -j ACCEPT\nfi\n\n\n\n\n\n#iptables -A INPUT -p tcp --dport 20 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 21 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 53 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 25 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 465 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 587 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 110 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 995 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 80 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 443 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 2812 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 10000 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 10024 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 10026 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 123 -j ACCEPT\n#iptables -A INPUT -p tcp --dport 3306 -j ACCEPT\n#iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 20022 -j ACCEPT\n\n# \u307b\u304bACCEPT\u3084DROP\u306a\u3069\u30e6\u30fc\u30b6\u306b\u3088\u308b\u8a2d\u5b9a\n \n#\u30ed\u30fc\u30ab\u30eb\u30eb\u30fc\u30d7\u30d0\u30c3\u30af\u306e\u63a5\u7d9a\u3092\u8a31\u53ef\u3059\u308b\u3002\n#iptables -A INPUT -i lo -j ACCEPT\n\n#\u4ee5\u4e0b\u3001\u3053\u3061\u3089\u304b\u3089\u6c42\u3081\u305f\u30d1\u30b1\u30c3\u30c8\u306f\u8a31\u53ef\u3059\u308b\u3002\u2190\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u975e\u5e38\u306b\u91cd\u8981\uff0a\uff0a\uff0a\uff0a\uff0a\uff0a\niptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT\niptables -A INPUT -p icmp -j ACCEPT\n#\u4ee5\u4e0a\u3001\u3053\u3061\u3089\u304b\u3089\u6c42\u3081\u305f\u30d1\u30b1\u30c3\u30c8\u306f\u8a31\u53ef\u3059\u308b\u3002\u2190\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u975e\u5e38\u306b\u91cd\u8981\uff0a\uff0a\uff0a\uff0a\uff0a\uff0a\n##\n##\u3053\u306e2\u884c\u304c\u7121\u3044\u3068\u3001\u30ed\u30fc\u30ab\u30eb\u30db\u30b9\u30c8\u304b\u3089\u5916\u90e8\u30b5\u30fc\u30d0\u3078\u306eping\u3084\u540d\u524d\u89e3\u6c7a\u3067\u306e\u63a5\u7d9a\u304c\u51fa\u6765\u306a\u304f\u306a\u308b\n\n\n#\u305d\u308c\u4ee5\u5916\u306f\u30ed\u30b0\u3092\u6b8b\u3059\u3002\n#iptables -A INPUT -j LOG --log-prefix \"drop_packet:\" \n\n###########################################################\n# \u305d\u308c\u4ee5\u5916\n# \u4e0a\u8a18\u306e\u30eb\u30fc\u30eb\u306b\u3082\u5f53\u3066\u306f\u307e\u3089\u306a\u304b\u3063\u305f\u3082\u306e\u306f\u30ed\u30ae\u30f3\u30b0\u3057\u3066\u7834\u68c4\n###########################################################\niptables -A INPUT  -j LOG --log-prefix \"drop_packet_IPTABLES:\"\niptables -A INPUT  -j DROP\n\n\n###########################################################\n# SSH \u7de0\u3081\u51fa\u3057\u56de\u907f\u7b56\n# 30\u79d2\u9593\u30b9\u30ea\u30fc\u30d7\u3057\u3066\u305d\u306e\u5f8c iptables \u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u3002\n# SSH \u304c\u7de0\u3081\u51fa\u3055\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u3001 Ctrl-C \u3092\u62bc\u305b\u308b\u306f\u305a\u3002\n###########################################################\ntrap 'finailize &amp;&amp; exit 0' 2 # Ctrl-C \u3092\u30c8\u30e9\u30c3\u30d7\u3059\u308b\necho \"In 30 seconds iptables will be automatically reset.\"\necho \"Don't forget to test new SSH connection!\"\necho \"If there is no problem then press Ctrl-C to finish.\"\necho \"\u3053\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u898b\u3089\u308c\u305f\u306a\u3089 Ctrl-C \u3092\u62bc\u4e0b\u3057\u3066\u7d42\u4e86\u3057\u3066\u4e0b\u3055\u3044\u3002\u305d\u306e\u307e\u307e\u653e\u7f6e\u3059\u308b\u3068iptables\u3092\u518d\u5ea6\u521d\u671f\u5316\u3057\u3066\u7d42\u4e86\u3057\u307e\u3059\u3002\"\nsleep 30\necho \"rollback...\"\ninitialize\n\n\n<\/code><\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>CentOS7\u3067\u306f\u3044\u308f\u3086\u308b\u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb\u3068\u3057\u3066firewalld\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3088\u304f\u89e3\u3089\u306a\u3044\u306e\u3067\u3001\u6614\u304b\u3089\u4f7f\u3044\u6163\u308c\u305fiptables\u3092\u4f7f\u3046\u3068\u3044\u3063\u305f\u65b9\u304c\u6570\u591a\u304f\u898b\u53d7\u3051\u3089\u308c\u307e\u3059\u3002\u300c\u306a\u3093\u3061\u3083\u3063\u3066\u7ba1\u7406\u8005\u300d\u306e\u79c1\u3082\u305d\u306e\u4e00\u4eba\u3001\u305d\u3082 &hellip; <a href=\"http:\/\/www.feelkind.com\/blog\/?p=94\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":2,"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":96,"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions\/96"}],"wp:attachment":[{"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.feelkind.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}