DynagenでCCIEを目指す
CBAC DDOS対策
最終更新:
it_certification
-
view
1. 目的
- CBACを用いてDDOS攻撃対策を実装します。
2. 構成
2.1. 設定概要
- Host OSをサービスを提供するHTTPサーバとします。
- R1はDDOS攻撃を防ぐファイアウォールとして機能させます。
- Guest OSはDDOS攻撃を行うホストとして使用します。
2.2. 構成図

2.3. netファイル
model = 3660 [localhost] [[3660]] image = C:\Program Files\Dynamips\images\c3660-ik9o3s-mz.124-6.T.bin ram = 128 [[ROUTER R1]] f0/0 = NIO_gen_eth:\Device\NPF_{8B89D910-5ED3-4A43-9DE9-6A272A3D7592} f0/1 = NIO_gen_eth:\Device\NPF_{5933302A-7AAA-475C-A8FE-A6B82B0C0F98}
2.4. 初期設定
- R1
! version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption ! hostname R1 ! boot-start-marker boot-end-marker ! logging buffered 4096 debugging ! no aaa new-model ! resource policy ! memory-size iomem 5 ! ! ip cef no ip domain lookup ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! interface FastEthernet0/0 ip address 192.168.200.1 255.255.255.0 duplex auto speed auto ! interface FastEthernet0/1 ip address 192.168.201.1 255.255.255.0 duplex auto speed auto ! ip http server no ip http secure-server ! ! ! no cdp run ! ! ! control-plane ! ! ! ! ! ! ! ! ! line con 0 line aux 0 line vty 0 4 ! ! end
2.5. サーバ側 ルーティング設定
- Host OS
route add 192.168.201.0 mask 255.255.255.0 192.168.200.1
- Guest OS
route add -net 192.168.200.0/24 gw 192.168.201.1
2.6. Apache 設定
Host OSにApache httpサーバを構築します。設定はデフォルトのままで80番ポートで待ち受けます。
2.7. syn flood攻撃スクリプトの作成
以下のようなスクリプトを作成し、Guest OSからHost OSへSyn flood攻撃が行えるようにします。
[root@localhost ~]# cat syn_flood.sh #!/bin/sh DELAY=0.01 while true : do sport=$RANDOM dport=80 hping 192.168.200.100 -S -p $dport -s $sport -c 1 > /dev/null 2>&1 echo sport:${sport} sleep $DELAY done [root@localhost ~]#
2.8. iptablesの設定
syn flood攻撃を成功させるためには、SYN + ACKを無視しなければなりません。iptablesデフォルト設定では、SYN + ACKに対してRSTを返す設定になっている可能性があります。
私の場合は、送信元ポート80であるものを無視するように設定しました。設定例は以下の通りです。
私の場合は、送信元ポート80であるものを無視するように設定しました。設定例は以下の通りです。
[root@localhost ~]# cat /etc/sysconfig/iptables *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :RH-Firewall-1-INPUT - [0:0] -A INPUT -j RH-Firewall-1-INPUT -A FORWARD -j RH-Firewall-1-INPUT -A RH-Firewall-1-INPUT -i lo -j ACCEPT -A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT -A RH-Firewall-1-INPUT -p 50 -j ACCEPT -A RH-Firewall-1-INPUT -p 51 -j ACCEPT -A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -m tcp -p tcp --sport 80 -j DROP <- syn flood攻撃を成功させるために、SYN + ACKを無視します。 -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10022 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT
3. [検証] デフォルト設定の確認
3.1. 設定投入
R1 Fa0/1にてTCPを監査する設定を投入します。このデフォルト設定により、どのようなDDOS対策が実装されているかを以降のシナリオで観察します。
R1(config)#ip inspect name TCP tcp R1(config)# R1(config)#interface FastEthernet 0/1 R1(config-if)#ip inspect TCP in
3.2. 攻撃開始
Guest OSからHost OSへ攻撃するスクリプトを実行します。
[root@localhost ~]# sh syn_flood.sh sport:4088 sport:8308 sport:51 sport:22443 - 以下 省略 -
3.3. コンソールの確認
攻撃を開始するとコンソールには、以下のようなメッセージが表示されます。単一ホストからのhalf-open connectionが50を超えると、防御機能として古いコネクションから順に破棄されます。
R1(config-if)# *Mar 1 00:32:25.863: %FW-4-HOST_TCP_ALERT_ON: Max tcp half-open connections (50) exceeded for host 192.168.200.100. *Mar 1 00:32:30.887: %FW-4-HOST_TCP_ALERT_ON: Max tcp half-open connections (50) exceeded for host 192.168.200.100. *Mar 1 00:32:35.915: %FW-4-HOST_TCP_ALERT_ON: Max tcp half-open connections (50) exceeded for host 192.168.200.100. *Mar 1 00:32:38.143: %FW-4-ALERT_ON: getting aggressive, count (51/500) current 1-min rate: 501 R1(config-if)#
デフォルトの設定を確認します。IOSのバージョンによりデフォルト値は異なりますが、私が検証したIOSでは、単一ホストから50までのhalf-open connectionを受け付ける事が分かります。
R1#show ip inspect all Session audit trail is disabled Session alert is enabled one-minute (sampling period) thresholds are [400:500] connections max-incomplete sessions thresholds are [400:500] max-incomplete tcp connections per host is 50. Block-time 0 minute. <- 単一ホストから50までのhalf connectionを許可します。 tcp synwait-time is 30 sec -- tcp finwait-time is 5 sec tcp idle-time is 3600 sec -- udp idle-time is 30 sec dns-timeout is 5 sec Inspection Rule Configuration Inspection name TCP tcp alert is on audit-trail is off timeout 3600 Interface Configuration Interface FastEthernet0/1 Inbound inspection rule is TCP tcp alert is on audit-trail is off timeout 3600 Outgoing inspection rule is not set Inbound access list is not set Outgoing access list is not set Half-open Sessions Session 662B93C8 (192.168.201.101:12650)=>(192.168.200.100:80) tcp SIS_OPENING Session 662B6848 (192.168.201.101:4213)=>(192.168.200.100:80) tcp SIS_OPENING Session 662B3758 (192.168.201.101:26495)=>(192.168.200.100:80) tcp SIS_OPENING Session 662B4FD0 (192.168.201.101:25177)=>(192.168.200.100:80) tcp SIS_OPENING Session 662BF038 (192.168.201.101:31008)=>(192.168.200.100:80) tcp SIS_OPENING Session 662BFDD0 (192.168.201.101:15025)=>(192.168.200.100:80) tcp SIS_OPENING - 以下 省略 -
4. [検証] デフォルト値の変更
4.1. 設定投入
単一ホストからのhalf-open connection数に関する設定を変更します。20までのhalf-open connectionを許可し、上限を超えた場合は1分間の通信断を発生される設定に変更します(block-time 0と指定した場合は、通信断なしの意味です)。
R1(config)#ip inspect tcp max-incomplete host 20 block-time 1
4.2. 攻撃開始
Guest OSからHost OSへ攻撃するスクリプトを実行します。
[root@localhost ~]# sh syn_flood.sh sport:2211 sport:8128 sport:21979 sport:5641 - 以下 省略 -
4.3. コンソールの確認
攻撃を開始するとコンソールには、以下のようなメッセージが表示されます。1分間のblockが発生した事と、1分後にblockが解除された事が確認できます。
R1(config)# *Mar 1 00:38:42.027: %FW-4-HOST_TCP_ALERT_ON: Max tcp half-open connections (20) exceeded for host 192.168.200.100. *Mar 1 00:38:42.035: %FW-2-BLOCK_HOST: Blocking new TCP connections to host 192.168.200.100 for 1 minute (half-open count 20 exceeded). *Mar 1 00:39:42.343: %FW-4-UNBLOCK_HOST: New TCP connections to host 192.168.200.100 no longer blocked R1(config)#
5. [検証] その他のチューニング
5.1. 設定可能項目一覧
DDOS攻撃対策としてチューニングできる項目は以下の通りです。なお、デフォルト値は私が検証に使用したIOSの場合です数値です。IOSによりデフォルト値が異なる可能性があるので、必ずshowコマンドでデフォルト値を確認した方が良いと思います。
コマンド | 意味 | デフォルト |
---|---|---|
ip inspect tcp synwait-time | TCPセッションを破棄せずにTCPセッションが確立した状態に達するまで待つ時間です | 30秒 |
ip inspect tcp finwait-time | FINの交換を検知した後でTCPセッションを管理する時間です | 5秒 |
ip inspect tcp idle-time | 通信がなくなってからTCPセッションを管理する時間です | 3600秒 |
ip inspect udp idle-time | 通信がなくなってからUDPセッションを管理する時間です | 30秒 |
ip inspect dns-timeout | 通信がなくなってからDNS名前検索セッションが管理される時間です | 5秒 |
ip inspect max-incomplete high | 管理するhalf connection数です。上限を超えるとconnectionを破棄を開始し、下限を下回ると破棄を終了します。 | 上限500 下限400 |
ip inspect max-incomplete low | ||
ip inspect one-minute high | 1分辺りのconnection数です。上限を超えるとconnectionを破棄を開始し、下限を下回ると破棄を終了します。 | 上限500 下限400 |
ip inspect one-minute low | ||
ip inspect tcp max-imcomplete | 単一ホストからのhalf connection数です。閾値とconnectionを破棄を古い順に破棄し、設定によっては指定時間の通信断を発生させる事ができます。 | 50コネクション 通信断0分 |
デフォルト値は以下の通りshowコマンドで確認する事ができます。
R1#show ip inspect all Session audit trail is disabled Session alert is enabled one-minute (sampling period) thresholds are [400:500] connections max-incomplete sessions thresholds are [400:500] max-incomplete tcp connections per host is 50. Block-time 0 minute. tcp synwait-time is 30 sec -- tcp finwait-time is 5 sec tcp idle-time is 3600 sec -- udp idle-time is 30 sec dns-timeout is 5 sec Inspection Rule Configuration Inspection name TCP tcp alert is on audit-trail is off timeout 3600 Interface Configuration Interface FastEthernet0/1 Inbound inspection rule is TCP tcp alert is on audit-trail is off timeout 3600 Outgoing inspection rule is not set Inbound access list is not set Outgoing access list is not set
5.2. 設定例
max-incompleteのデフォルト値を変更する設定を投入します。
R1(config)#ip inspect max-incomplete low 10 R1(config)#ip inspect max-incomplete high 15
5.3. 攻撃開始
Guest OSからHost OSへ攻撃するスクリプトを実行します。
[root@localhost ~]# sh syn_flood.sh sport:8870 sport:9546 sport:743 sport:27443 - 以下 省略 -
5.4. コンソールの確認
攻撃を開始するとコンソールには、以下のようなメッセージが表示されます。
R1(config)# *Mar 1 00:13:14.867: %FW-4-ALERT_ON: getting aggressive, count (16/15) current 1-min rate: 16 R1(config)# *Mar 1 00:13:56.803: %FW-4-ALERT_OFF: calming down, count (9/10) current 1-min rate: 108 R1(config)#
6. [補足] 設計
6.1. ユーザガイドからの抜粋
Webサイト「ネットワークエンジニアとして」からの抜粋になりますが、ユーザガイドに以下のような記述があるそうです。
An unusually high number of half-open sessions (either absolute or measured as the arrival rate) could indicate that a DoS attack is occurring. For TCP, "half-open" means that the session has not reached the established state. For UDP , "half-open" means that the firewall has detected traffic from one direction only. CBAC measures both the total number of existing half-open sessions and the rate of session establishment attempts.Both TCP and UDP half-open sessions are included in the total number and rate measurements. Measurements are made once a minute.
ip inspect one-minute highとip inspect one-minute lowは無制限にするか、クライアント数に応じた閾値を評価するかしなければならないようです。Cisco機に限らず忘れてはならない設計ポリシーなので、肝に銘じておきましょう。
添付ファイル