實驗 3 : Layer 2 交換器裝置之安全性設定與操作

16
國國國國國國國國 國國國 國國國國 國國 3 Layer 2 國國國國國國國國國國國國國國

description

實驗 3 : Layer 2 交換器裝置之安全性設定與操作. 實驗目的. 本實驗講解如何設定 Port Security 、 DHCP Snooping 、 BPDU Guard 等方法來抵御下列幾種攻擊: CAM table overflow MAC address spoofing DHCP starvation STP manipulation 而在講解如何在交換器上設定對應的防禦機制前,將會簡述以上四種攻擊法,能夠讓各位更能了解這些防禦機制的工作原理。. - PowerPoint PPT Presentation

Transcript of 實驗 3 : Layer 2 交換器裝置之安全性設定與操作

Page 1: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

國立雲林科技大學自由軟體研發中心

實驗 3 : Layer 2 交換器裝置之安全性設定與操作

Page 2: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

2國立雲林科技大學 自由軟體研發中心

實驗目的本實驗講解如何設定 Port Security 、 DHCP Snooping 、 BPDU Guard 等方法來抵御下列幾種攻擊: CAM table overflow MAC address spoofing DHCP starvation STP manipulation

而在講解如何在交換器上設定對應的防禦機制前,將會簡述以上四種攻擊法,能夠讓各位更能了解這些防禦機制的工作原理。

Page 3: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

3國立雲林科技大學 自由軟體研發中心

CAM table overflow 攻擊簡述 CAM table overflow 的目的是透過發送大量偽造 MAC address 的封包,使得交換器的 CAM ta

ble 紀錄的對應資料中不含有正常的主機 MAC address ,在這種狀況下交換器的工作方式就如同集線器一樣,將收到的封包將所有的連接埠送 ( 除了來源的連接埠 ) ,攻擊者便可藉此竊聽所有流經交換器的訊息。

場景如左圖 1 ,一開始交換器上的 CAM table存有主機 A 位於連接埠 1 、主機 B 位於連接埠2 的對應資訊,當主機 A 要傳送資料給主機 B時,由於 CAM table 中存在主機 B 存在連接埠2 這項對應資訊,所以 A 傳送給 B 的訊息會直接送往連接埠 2 。

如圖 2 ,之後主機 C 發送偽造 MAC address 的封包,當交換器收到後會更新 CAM table 中的資料,此時因為數量超過了 CAM table 所能紀錄的大小,所以會將先前存在的對應資料覆蓋掉,可以看到 CAM table 中紀錄到了 X 、 Y 這兩個不存在的 MAC address 位在連接埠 3 的資訊。 如圖 3 ,最後假設主機 A 要傳訊息給主機 B ,交換器收到封包後發現 CAM table 中沒有紀錄主機 B 是位在哪個連接埠,因此將該訊息送往連接埠 2 、 3 。此時主機 C 就可收到主機 A 傳給主機 B 的訊息,。

MAC A

MAC C

MAC B

1

Port MAC

A

B2

Port 1

Port 3

Port 2

CAM table size = 3

A to B

A to B

圖 1

MAC A

MAC C

MAC B

1

Port MAC

A

X3

X to ?

Y to ?

Port 1

Port 3

Port 2

Y3

CAM table size = 3

圖 2

MAC A

MAC C

MAC B

1

Port MAC

A

X3

Y3

Port 1

Port 3

Port 2

A to B

A to B

A to BCAM table size = 3

圖 3

Page 4: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

4國立雲林科技大學 自由軟體研發中心

MAC address spoofing 攻擊簡述 MAC address spoofing 的目的是藉由送出一個來源 MAC address 為攔截目標的 MAC address 的封包給交換器,讓交換器上的 CAM table 紀錄錯誤的訊息,讓其後要送給目標主機的訊息都傳送攻擊者所在的連接埠。注意 MAC address s

poofing 與 CAM table overflow 的差別在於 MAC address spoofing 只會收到攻擊目標的封包,而 CAM table overflow 則是會竊聽到所有流經交換器的封包。

我們用左方的圖來簡述 MAC address spoofing的攻擊流程,場景如左圖 1 ,一開始 CAM table 中紀錄主機 A 在連接埠 2 、主機 B 在連接埠1 、主機 C 在連接埠 3 。

之後主機 B 送出一個來源 MAC address 欄位填上 A 的 MAC address 的封包,當交換器收到後,會更新 CAM table ,使得交換器認為主機 A 在連接埠 1 ,如圖 2 。 接著所有要送給主機 A 的訊息,全部都會往連接埠 1 傳送,使得主機 B 可以收到原本要傳給主機 A 的訊息,如圖 3 。直到 A 主機再度送出訊框更新 CAM table 中的資訊, A 主機才能夠收到原本該收到的封包。

MAC B

MAC C

MAC A

2Port

MAC

1

B A

Port 1

Port 3

Port 2

3

C

C to A

C to A

CAM table

圖 1

MAC B

MAC C

MAC A

2Port

MAC

1

A,B

Port 1

Port 3

Port 2

C to A

C to A

3

C

CAM table

圖 3

MAC B

MAC C

MAC A

2Port

MAC

1

A,B

Port 1

Port 3

Port 2

A to ?

3

C

CAM table

圖 2

Page 5: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

5國立雲林科技大學 自由軟體研發中心

DHCP starvation 攻擊簡述 DHCP starvation 的目的是發送偽造 MAC address 的封包將合法的 DHCP 伺服器所有可用的 IP 位址佔用,使得合法使用者無法從 DHCP 伺服器取得可用 IP 位址。然後攻擊者架設一個 DHCP 伺服器,偽裝成合法的 DHCP 伺服器,當使用者發出 DHCP request 時,當合法的 DHCP 伺服器收到後因為本身已無可用的 IP 位置而不做任何的回應,而此時就由攻擊者所偽裝的 DHCP 伺服器來回應給使用者。而通常 DHC

P 除了分派 IP 位址之外,同時會指定 DNS 伺服器與預設的閘道器,而攻擊者就是利用將這些位址指向自已所擁有的主機位址藉此達成 man-in-the-middle attack 。 我們用下方的圖來簡述 DHCP starvation 的攻擊流程,如圖 1 ,首先攻擊者發送大量偽造來源 MAC addr

ess 的 DHCP request 給合法的 DHCP 伺服器,嘗試找出 DHCP 伺服器所有可分配的 IP 位址範圍並佔用所有可用的 IP 位址。 如圖 2 ,當攻擊者將合法的 DHCP 伺服器的所有可用 IP 佔用後,自已設置一個偽裝的 DHCP 伺服器,當合法使用者發出 DHCP request 時由攻擊者偽裝的 DHCP 伺服器回應給使用者。

Attacker

DHCP serverPC BPC A

Send a mount of DHCP requests with spoofed source MAC address

Allocate all available IP

圖 1Attacker

DHCP serverPC BPC A

Assign IP、DNS、gateway to PC A

No response because no available IP

Set up rogue DHCP server

DHCP request

圖 2

Page 6: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

6國立雲林科技大學 自由軟體研發中心

STP manipulation 攻擊簡述 STP manipulation 的目的是為了要竊聽網路上流經的封包,做法是攻擊者將自已偽裝成 Root Br

idge ,使得原本不該流經過攻擊者的封包送往攻擊者端。除了竊聽之外,也可做到 DoS 的效果,利用發送 STP configuration/topology change BPDUs ,迫使 STP 重新計算路徑,在重新計算路徑的這段時間可能會造成網路 30~45 秒的中斷,達到 DoS 的效果。

我們用左方的圖來簡述 STP manipulation 的攻擊流程,場景如圖 1 ,一開始交換器 A 被選為Root Bridge ,交換器 A 、 B 要傳送訊框時,是直接互傳給對方。

如圖 2 ,之後攻擊者假冒成交換器,廣播 STP topology change BPDUs 宣稱他的優先權較高。

接著當其它交換器收到時,認為攻擊者系統的優先權較高,應為 Root Bridge ,因此重新計算連接到攻擊者的最短路徑。重新計算出來的路徑如圖 3 ,重新計算出的路徑使得所有原本應直接經由交換器 A 、 B轉送的訊框,不是直接傳送給對方,而是要經由攻擊者系統才能到達,因此攻擊者可利用偽裝成 Root Bridge 竊聽到原本不能收到的訊息。

Switch A Switch B

Root Bridge

STP blocking port

Traffic flow

Traffic flow

Attack Host圖 1

Switch A Switch B

Root Bridge

STP blocking port

Attack Host

Elected as the Root Bridge

Traffic flow Traffic flow

圖 3

Switch A Switch B

Root Bridge

STP blocking port

Attack Host

I have the highest priority

圖 2

Page 7: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

7國立雲林科技大學 自由軟體研發中心

Port Security

7

Port SecurityPort Security 能夠用來指定在交換器上任何一個實體連接埠允許哪些 MAC address 可以使用以及最大可容納的 MAC address 數量。利用 Port Security 可以用來防禦 CAM table Overflow attacks 、 MAC Spoofing attacks 。Port Security 分為三種方式:

1. Static secure MAC address :在交換器的實體連接埠上手動設定只有哪些 MAC address 可以使用。

2. Dynamic secure MAC addresses :在交換器的實體連接埠上指定最大可容納的 MAC address 數量。

3. Sticky secure MAC addresses : Static secure MAC addresses 與 Dynamic secure MAC addresses 的結合,全由手動設定會增加管理者的負擔,因此我們只需要針對某些提供重要服務的設備指定 MAC address ,其餘的部分就交由 Dynamic secuire MAC addresses 的方式管理。

Fa0/7Hub Switch主機 A

主機 B

Static secure

只允許主機 A 通過

Dynamic secure

Fa0/7Hub Switch主機 A

主機 B

只允許 2 位同時在線主機 C

Page 8: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

8國立雲林科技大學 自由軟體研發中心

Port Security

Port Security (Cont.)當交換器連接埠上 MAC address 數量達到限制的數量時 (port security violation) ,有以下三種處理方式:1. Protect :當交換器連接埠上 MAC address數量達到限制的數量時,如果接下來的封包上的來源 MAC address 不在已學習到的清單內,則將封包丟棄,直到某些 MAC a

ddress 因閒置過久而從清單中被移除或是當最大限制的數量增加時,才可讓新加入的 MAC address 使用。使用此種方式的話當發生 security violation 時並不會做任何的通知。2. Restrict :當交換器連接埠上 MAC address數量達到限制的數量時,如果接下來的封包上的來源 MAC address 不在已學習到的清單內,則將封包丟棄,直到某些 MAC a

ddress 因閒置過久而從清單中被移除或是當最大限制的數量增加時,才可讓新加入的 MAC address 使用。當發生 security violoation 時會送通知到 SNMP 伺服器以及產生 syslog message 。

3. Shutdown :當交換器連接埠上 MAC address 數量達到限制的數量時,該連接埠會被停用,並顯示為 err-disabled ,同時會發送SNMP trap 以及產生 syslog message 。

Fa0/7Hub Switch主機 A

主機 B

Protect & Restrict

假設主機 A 目前在線上,主機 B需等待主機 A 從清單中移除後才可使用

MAX=1

Fa0/7Hub Switch主機 A

主機 B

Shutdown

MAX=1

Page 9: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

9國立雲林科技大學 自由軟體研發中心

Port Security

Port Security (Cont.)以下是設定 port security 的指令:switch(config-if)#switchport mode {access | trunk}指定交換器連接埠的模式,預設為非 secure port 。switch(config-if)#switchport port-secuirty在該連接埠下啟動 port security 。switch(config-if)#switchport port-security [maximum value]限制 Port 可容納多少的 MAC addresses 。switch(config-if)#switchport port-security violation {protect | restrict | shutdown}當超過可容納的 MAC addresses 數量時採取何種對應方式。

Command Description

switchport mode {access | trunk} Sets the interface mode as access or trunk. An interface in the default mode of dynamic auto cannot be configured as a secure port.

switchport port-security Enables port security on the interface.

switchport port-security [maximum value

[vlan {vlan-list | {access | voice}}]]

Sets the maximum number of secure MAC addresses for the interface. The active Switch Database Management (SDM) template determines the maximum number of available addresses. The default is 1.

switchport port-security violation{protect | restrict | shutdown}

Sets the action to be taken when a security violation is detected. The default mode for security violations is to shut down the interface.

switchport port-security [mac-address macaddress

[vlan {vlan-id | {access | voice}}]

Sets a secure MAC address for the interface. This command may be used to enter the maximum number of secure MAC addresses. If fewer secure MAC addresses are configured than the maximum, the remaining MAC addresses are dynamically learned.

switchport port-security mac-address sticky

Enables sticky learning on the interface.

switchport port-security mac-address sticky

[mac-address | vlan {vlan-id | {access | voice}}]

Sets a sticky secure MAC address. This command can be repeated as many times as necessary. If fewer secure MAC addresses are configured than the maximum, the remaining MAC addresses are dynamically learned, converted to sticky secure MAC addresses, and added to the running configuration.

Page 10: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

10國立雲林科技大學 自由軟體研發中心

Port Security

Port Security (Cont.)左圖為實驗場景與設定:

將 fa0/7 這個 Port限制最大可使用的 MAC為 1 個。並且設定若超過所指定的數量,Switch 的動作為 Shutdown 。

依據左圖的建構目前實驗的環境。 觀察 Port Security

主機 A 取得 IP 之後,使用 Show port-security ,觀看 CurrentAddr 欄位,會顯示 1 ,代表目前此 Port 有 1 主機存在 ( 如左所示 ) 。

將主機 B 接至 HUB 。此時, fa0/7 將會 shutdown 。主機 A 、 B 將無法連線。

Port Security

Fa0/7Hub Switch主機 A

主機 B Port Security 實驗場景Show Port Security

Switch(config)#int fa0/7Switch(config-if)#switchport port-securitySwitch(config-if)#switchport port-security max 1Switch(config-if)#switchport port-security violation shutdown

Page 11: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

11國立雲林科技大學 自由軟體研發中心

DHCP Snooping

DHCP SnoopingDHCP Snooping 是用來過濾來路不明的 DHCP messages 並保護使用者不會從網路上不合法的DHCP 伺服器取得錯誤的網路設定資訊。 DHCP Snooping 透過建立 DHCP Snooping Binding 資料庫來過濾掉非合法的使用者。 DHCP Snooping 啟動之後會監聽流經的 DHCP 封包,利用使用者要與 DHCP Server 取得位址時所發送的 DHCP Reques 與 DHCP Ack記錄此使用者的資訊將之儲存於 DHCP Snooping binding table ,此表中會紀錄,使用者對應的 MAC 位址、 IP位址、租用時間、 vlan編號等等的資訊。

DHCP Snooping 會設定交換器中哪些 Port或是哪些 vlan 為 trust 的介面,只有 trust 的介面才可以收送 DHCP Offer 封包。區別 trust 與 untrust介面的依據是根據連接埠是否直接連接到 end-user ,如果是連接到 end-user 則為 untrust 的介面,若是接到 DHCP Server或是另一臺交換器的話,則為 trust 的介面。

11

Rogue DHCP Attacker

Client

Untrusted

Trusted Trusted

Legitimate DHCP Server

Untrusted

Page 12: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

12國立雲林科技大學 自由軟體研發中心

DHCP Snooping

DHCP Snooping (Cont.)設定 DHCP Snooping 的指令如下:

switch(config)# ip dhcp snooping

switch(config)# ip dhcp snooping vlan [number or range]在交換器上啟動 DHCP Snooping 的功能Switch(config)# ip dhcp snooping trust設定介面是 trust還是 untrust 。Switch(config-if)# ip dhcp snooping limit rate rate 每秒最多能收多少 DHCP 封包

Command Purpose

Switch(config)# ip dhcp snooping Enables DHCP snooping globally. You can use the no keyword to disable DHCP snooping.

Switch(config)# ip dhcp snooping vlan number [number]

Enables DHCP snooping on your VLANs.

Switch(config)# ip dhcp snooping information option

Enables DHCP Option 82 data insertion.

Switch(config-if)# ip dhcp snooping trust Configures the interface as trusted or untrusted. You can use the no keyword of to configure an interface to receive only messages from within the network.

Switch(config-if)# ip dhcp snooping limit rate rate

Normally, the rate limit applies to untrusted interfaces. If you want to set up rate limiting for trusted interfaces, keep in mind that trusted interfaces aggregate all DHCP traffic in the switch, and you will need to adjust the rate limit to a higher value.

資料來源 http://www.cisco.com/en/US/docs/switches/lan/catalyst4500/12.1/13ew/configuration/guide/dhcp.html

switch#configure TerminalEnter configuration commands, one per line. End with CNTL/Z.switch(config)#ip dhcp snoopingswitch(config)#ip dhcp snooping vlan 32switch(config)#int fa0/36switch(config-if)#ip dhcp snooping trustswitch(config-if)#ip dhcp snooping limit rate 100switch(config-if)#exitswitch(config)#^Zswitch#show ip dhcp snoopingSwitch DHCP snooping is enabledDHCP snooping is configured on following VLANs:32DHCP snooping is configured on the following Interfaces:

Insertion of option 82 is enabled circuit-id format: vlan-mod-port remote-id format: MACOption 82 on untrusted port is not allowedVerification of hwaddr field is enabledInterface Trusted Rate limit (pps)------------------------ ------- ----------------FastEthernet0/36 yes 100switch#

Page 13: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

13國立雲林科技大學 自由軟體研發中心

Dynamic ARP Inspection

Dynamic ARP InspectionDynamic ARP Inspection (DAI) 是用來核對 IP-to-MAC address bindings 以丟棄不正確的 ARP 封包。 DAI 使用 DHCP Snooping database 來核對bindings ,當封包來自於 trust 的介面時,封包不需要經過 DAI檢查,而當封包是從 untrust 的介面送來時, DAI 會對這些封包檢查。當啟用DAI 時,能夠對流進的 ARP 封包限流來預防 DoS 攻擊,預設的在 untrust 的介面上的限流是每秒 14 個封包, trust 的介面上則沒有限制。以下是設定 DAI 的指令:switch(config)#ip arp inspection vlan vlan啟用 DAI

switch(config)# ip arp inspection trust設定介面是 trust還是 untrust 。switch(config)#ip arp inspection limit rate rate burst interval interval設定 rate-limit

Switch#configure terminalSwitch(config)#ip arp inspection vlan 34Switch(config)#interface fa0/0Switch(config-if)#ip arp inspection trustSwitch(config-if)#ip arp inspection limit rate 20 burst interval 2

Rogue DHCP Attacker

Client

Untrusted

Trusted Trusted

Legitimate DHCP Server

Untrusted

Page 14: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

14國立雲林科技大學 自由軟體研發中心

BPDU Guard

在 STP 中,只要連接埠有參與 STP 的運作,那麼該設備就有機會可以成為 root bridge影響 STP topology 。要成為 root bridge ,自已本身的優先權要比目前的 root bridge 的 priority低,才能夠取代原先的 root bridge 。當取代原本的 root bridge 時, STP topology 會重新計算,大約需要30~50 秒的時間,在這段時間內可能造成某些服務 time out 。如果有人利用這種方式一直迫使 STP 不停的重新計算 Topology ,會造成阻斷式服務攻擊 (DoS) 。

運作 STP 的交換器在告知其它的交換器自已的priority 時,是利用 BPDU 封包,因此我們可以利用 BPDU Guard 來防止 STP manipulation attack 。

BPDU Guard 的原理是假設我們知道目前整個網路的 topology ,知道交換器的哪些連接埠是有連接參與 STP 的交換器,只允許這些連接埠發送 BPDU 封包,禁止沒有參與 STP 的連接埠發送 BPDU 封包,如果在這些連接埠上接收到BPDU 的封包則視為異常狀況,會將該連接埠disable 。

Client A

Web Server

Client B

Configure BPDU guard here.

Page 15: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

15國立雲林科技大學 自由軟體研發中心

BPDU Guard

BPDU GuardBPDU Guard 用來抵禦 STP manipulation attack ,主要是禁止交換器連接埠接收來路不明的 BPDU 封包。設定 BPDU Guard 的指令如下:Switch(config)#spanning-tree portfast bpduguard啟用 BPDU Guard

Switch#show spanning-tree summary totals檢視 BPDU Guard 的設定

switch#configure terminalEnter configuration commands, one per line. End with CNTL/Z.switch(config)#spanning-tree portfast bpduguardswitch(config)#show spanning-tree summary totalsSwitch is in pvst modeRoot bridge for: noneExtended system ID is enabledPortfast Default is disabledPortFast BPDU Guard Default is enabledPortfast BPDU Filter Default is disabledLoopguard Default is disabledEtherChannel misconfig guard is enabledUplinkFast is disabledBackboneFast is disabledConfigured Pathcost method used is short

Name Blocking Listening Learning Forwarding STP Active---------------------- -------- --------- -------- ---------- ----------1 vlan 0 0 0 9 9switch#

Page 16: 實驗  3 : Layer 2  交換器裝置之安全性設定與操作

實驗 3:Layer 2 交換器裝置之安全性設定與操作

16國立雲林科技大學 自由軟體研發中心

Mitigating VLAN Hopping Attacks

Switch(config-if)#switchport mode access

Configures the ports as access ports and turns off DTP

Switch(config-if)#switchport access vlan vlan-id

Statically assigns the ports to specific unused VLAN

Mitigating VLAN Hopping Attacks要減緩 vlan hopping attacks 可根據以下幾點設定:1. 所有的 trunk port 使用專用的 VLAN ID 。2. 關閉所有未使用的連接埠,以及將這些連接埠分入一個未使用的 VLAN 。3. 使用 switchport mode access 指令將與使用者連接的連接埠設為非 trunk port 。4. 在網路骨幹上的交換器之間的連接,要確實的設為 trunking 。5. 不要使用 VLAN 1 做為管理的專用 VLAN 。