
iptables
クライアントから ACK パケットが返されない不完全な SYN パケットによってサーバーの接続制限が満たされるのを防ぐためのルールを作成しようとしました(SYN フラッド攻撃)。
私は[RFC 4987 TCP SYNフラッド攻撃と一般的な軽減策][1]と[Red Hat Enterprise Linux 7 BetaでTCP SYNフラッド攻撃を軽減する][2]を読み、最終的に[ここ][3]の指示に従うようにしました。https://javapipe.com/blog/iptables-ddos-protection/
ただし、次のコマンドを使用した DOS 攻撃では、サイトは簡単にダウンしてしまいます。
hping -S --flood -V -p 443 www.mydomain.com
上記のリンク先の Javapipe.com のチュートリアルの最後に、SYNPROXY がアクティブかどうかを確認するコマンドが記載されています。
SYNPROXY が動作していることを確認するには、watch -n1 cat /proc/net/stat/synproxy を実行します。SYNPROXY を使用するポートに新しい TCP 接続を確立したときに値が変化すれば、動作しています。
コマンドは次のとおりです:
watch -n1 cat /proc/net/stat/synproxy
サーバー上でそのコマンドを使用してページを読み込もうとすると、データは変更されず、すべてゼロになります。
Every 1.0s: cat /proc/net/stat/synproxy Thu Jul 25 19:57:00 2019
entries syn_received cookie_invalid cookie_valid cookie_retrans conn_reopened
00000000 00000000 00000000 00000000 00000000 00000000
iptables -Lの出力は次のとおりです。
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
INPUT_direct all -- anywhere anywhere
INPUT_ZONES_SOURCE all -- anywhere anywhere
INPUT_ZONES all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
REJECT tcp -- anywhere anywhere #conn src/32 > 80 reject-with tcp-reset
ACCEPT tcp -- anywhere anywhere ctstate NEW limit: avg 20/sec burst 20
DROP tcp -- anywhere anywhere ctstate NEW
ACCEPT tcp -- anywhere anywhere tcp flags:RST/RST limit: avg 2/sec burst 2
DROP tcp -- anywhere anywhere tcp flags:RST/RST
DROP all -- anywhere anywhere ctstate INVALID
SYNPROXY tcp -- anywhere anywhere tcp ctstate INVALID,UNTRACKED SYNPROXY sack-perm timestamp wscale 7 mss 1460
DROP all -- anywhere anywhere ctstate INVALID
DROP all -- anywhere anywhere state INVALID
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
FORWARD_direct all -- anywhere anywhere
FORWARD_IN_ZONES_SOURCE all -- anywhere anywhere
FORWARD_IN_ZONES all -- anywhere anywhere
FORWARD_OUT_ZONES_SOURCE all -- anywhere anywhere
FORWARD_OUT_ZONES all -- anywhere anywhere
DROP all -- anywhere anywhere ctstate INVALID
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
OUTPUT_direct all -- anywhere anywhere
Chain FORWARD_IN_ZONES (1 references)
target prot opt source destination
FWDI_public all -- anywhere anywhere [goto]
Chain FORWARD_IN_ZONES_SOURCE (1 references)
target prot opt source destination
Chain FORWARD_OUT_ZONES (1 references)
target prot opt source destination
FWDO_public all -- anywhere anywhere [goto]
Chain FORWARD_OUT_ZONES_SOURCE (1 references)
target prot opt source destination
Chain FORWARD_direct (1 references)
target prot opt source destination
Chain FWDI_public (1 references)
target prot opt source destination
FWDI_public_log all -- anywhere anywhere
FWDI_public_deny all -- anywhere anywhere
FWDI_public_allow all -- anywhere anywhere
REJECT icmp -- anywhere anywhere reject-with icmp-host-prohibited
Chain FWDI_public_allow (1 references)
target prot opt source destination
Chain FWDI_public_deny (1 references)
target prot opt source destination
Chain FWDI_public_log (1 references)
target prot opt source destination
Chain FWDO_public (1 references)
target prot opt source destination
FWDO_public_log all -- anywhere anywhere
FWDO_public_deny all -- anywhere anywhere
FWDO_public_allow all -- anywhere anywhere
Chain FWDO_public_allow (1 references)
target prot opt source destination
Chain FWDO_public_deny (1 references)
target prot opt source destination
Chain FWDO_public_log (1 references)
target prot opt source destination
Chain INPUT_ZONES (1 references)
target prot opt source destination
IN_public all -- anywhere anywhere [goto]
Chain INPUT_ZONES_SOURCE (1 references)
target prot opt source destination
Chain INPUT_direct (1 references)
target prot opt source destination
Chain IN_public (1 references)
target prot opt source destination
IN_public_log all -- anywhere anywhere
IN_public_deny all -- anywhere anywhere
IN_public_allow all -- anywhere anywhere
REJECT icmp -- anywhere anywhere reject-with icmp-host-prohibited
Chain IN_public_allow (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW
ACCEPT tcp -- anywhere anywhere tcp dpt:http ctstate NEW
ACCEPT tcp -- anywhere anywhere tcp dpt:https ctstate NEW
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp ctstate NEW
Chain IN_public_deny (1 references)
target prot opt source destination
Chain IN_public_log (1 references)
target prot opt source destination
Chain OUTPUT_direct (1 references)
target prot opt source destination
サーバーは、Centos 7.6、カーネル: 3.10.0-862.2.3.el7.x86_64 を実行する Digital Ocean の VPS です。
SYNPROXY が実行されない理由、または SYN フラッディングからサーバーを保護する理由と方法を説明してくださる方はいらっしゃいますか?