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

Download Report

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

實驗 3:Layer 2 交換器裝置之安全性設定與操作
國立雲林科技大學
自由軟體研發中心
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
實驗目的
本實驗講解如何設定Port Security、DHCP Snooping、BPDU Guard等方法來抵御下列幾種攻
擊:
 CAM table overflow
 MAC address spoofing
 DHCP starvation
 STP manipulation
而在講解如何在交換器上設定對應的防禦機制前,將會簡述以上四種攻擊法,能夠讓各位
更能了解這些防禦機制的工作原理。
國立雲林科技大學 自由軟體研發中心
2
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
CAM table overflow 攻擊簡述

CAM table overflow的目的是透過發送大量偽造
MAC address的封包,使得交換器的CAM table
紀 錄 的 對 應 資 料 中 不 含 有 正 常 的 主 機 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
的訊息,。
A to B
Port 2
MAC B
A to B
Port 1
Port 3
MAC A
Port
MAC
1
A
2
B
CAM table size = 3
圖1
MAC C
Port 2
MAC B
Port 1
Port 3
MAC A
CAM table size = 3
Port
MAC
1
A
3
X
3
Y
Y to ?
X to ?
MAC C
圖2
A to B
Port 2
MAC B
A to B
Port 1
Port 3
MAC A
CAM table size = 3
Port
MAC
1
A
3
X
3
Y
A to B
MAC C
圖3
國立雲林科技大學 自由軟體研發中心
3
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
C to A
MAC address spoofing 攻擊簡述

MAC address spoofing的目的是藉由送出一個來
源MAC address為攔截目標的MAC address的封
包給交換器,讓交換器上的CAM table紀錄錯誤
的訊息,讓其後要送給目標主機的訊息都傳送
攻 擊 者 所 在 的 連 接 埠 。 注 意 MAC address
spoofing與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主機才能夠收到原
本該收到的封包。
Port 2
MAC A
Port 1
Port 3
MAC B
CAM table
C to A
MAC C
Port
1
2
3
MAC
B
A
C
圖1
Port 2
MAC A
A to ?
Port 1
Port 3
MAC B
CAM table
MAC C
Port
1
MAC
A,B
2
3
C
圖2
Port 2
MAC A
C to A
Port 1
Port 3
MAC B
CAM table
C to A
MAC C
Port
1
MAC
A,B
2
3
C
圖3
國立雲林科技大學 自由軟體研發中心
4
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
DHCP starvation 攻擊簡述

DHCP starvation的目的是發送偽造MAC address的封包將合法的DHCP伺服器所有可用的IP位址佔用,使
得合法使用者無法從DHCP伺服器取得可用IP位址。然後攻擊者架設一個DHCP伺服器,偽裝成合法的
DHCP伺服器,當使用者發出DHCP request時,當合法的DHCP伺服器收到後因為本身已無可用的IP位置
而不做任何的回應,而此時就由攻擊者所偽裝的DHCP伺服器來回應給使用者。而通常DHCP除了分派
IP位址之外,同時會指定DNS伺服器與預設的閘道器,而攻擊者就是利用將這些位址指向自已所擁有的
主機位址藉此達成man-in-the-middle attack。

我們用下方的圖來簡述DHCP starvation的攻擊流程,如圖1,首先攻擊者發送大量偽造來源MAC address
的DHCP request給合法的DHCP伺服器,嘗試找出DHCP伺服器所有可分配的IP位址範圍並佔用所有可用
的IP位址。

如圖2,當攻擊者將合法的DHCP伺服器的所有可用IP佔用後,自已設置一個偽裝的DHCP伺服器,當合
法使用者發出DHCP request時由攻擊者偽裝的DHCP伺服器回應給使用者。
PC B
PC A
PC B
PC A
DHCP server
DHCP request
Allocate all
available IP
No response
because no
available IP
Assign IP、DNS、gateway
to PC A
Send a mount of DHCP requests
with spoofed source MAC address
Attacker
DHCP server
圖1
國立雲林科技大學 自由軟體研發中心
Attacker
Set up rogue DHCP server
圖2
5
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Root Bridge
STP manipulation 攻擊簡述

STP manipulation的目的是為了要竊聽網路上流
經的封包,做 法是攻擊者將自已偽裝成 Root
Bridge,使得原本不該流經過攻擊者的封包送
往攻擊者端。除了竊聽之外,也可做到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竊聽到原本
不能收到的訊息。
Traffic flow
Switch A
Switch B
STP blocking port
Traffic flow
圖1
Attack Host
Root Bridge
Switch A
Switch B
STP blocking port
I have the
highest priority
圖2
Attack Host
Root Bridge
STP blocking port
Switch A
Switch B
Elected as the
Root Bridge
Traffic flow
Traffic flow
圖3
Attack Host
國立雲林科技大學 自由軟體研發中心
6
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Port Security

Static secure
Fa0/7
主機A
Hub
Switch
只允許主機A通過
主機B
Port Security
Port Security能夠用來指定在交換器上任何一個
實體連接埠允許哪些MAC address可以使用以及
最 大 可 容 納 的 MAC address 數 量 。 利 用 Port
Security 可 以 用 來 防 禦 CAM table Overflow
attacks、MAC Spoofing attacks。
Port Security分為三種方式:
1. Static secure MAC address:在交換器的實
體 連 接 埠 上 手 動 設 定 只 有 哪 些 MAC
address 可以使用。
Dynamic secure
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/7
主機A
Hub
Switch
只允許2位同時在線
主機B
主機C
國立雲林科技大學 自由軟體研發中心
7
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Port Security

Protect & Restrict
MAX=1
Fa0/7
主機A
Hub
Switch
假設主機A目前在線上,
主機B需等待主機A從清
單中移除後才可使用
主機B
Shutdown
Port Security (Cont.)
當交換器連接埠上MAC address數量達到限制的
數量時 (port security violation),有以下三種處
理方式:
1. Protect:當交換器連接埠上MAC address
數量達到限制的數量時,如果接下來的封
包上的來源MAC address不在已學習到的
清單內,則將封包丟棄,直到某些MAC
address因閒置過久而從清單中被移除或是
當最大限制的數量增加時,才可讓新加入
的MAC address使用。使用此種方式的話
當發生security violation時並不會做任何的
通知。
2.
Restrict:當交換器連接埠上MAC address
數量達到限制的數量時,如果接下來的封
包上的來源MAC address不在已學習到的
清單內,則將封包丟棄,直到某些MAC
address因閒置過久而從清單中被移除或是
當最大限制的數量增加時,才可讓新加入
的 MAC address 使 用 。 當 發 生 security
violoation時會送通知到SNMP伺服器以及
產生syslog message。
3.
Shutdown : 當 交 換 器 連 接 埠 上 MAC
address數量達到限制的數量時,該連接埠
會被停用,並顯示為err-disabled,同時會
發送SNMP trap以及產生syslog message。
MAX=1
Fa0/7
主機A
Hub
Switch
主機B
國立雲林科技大學 自由軟體研發中心
8
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Command
Description
Port Security

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.
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數量時採取何種對應方
式。
國立雲林科技大學 自由軟體研發中心
9
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Port Security

Port Security
Switch(config)#int fa0/7
Switch(config-if)#switchport port-security
Switch(config-if)#switchport port-security max 1
Switch(config-if)#switchport port-security violation shutdown
Port Security (Cont.)
左圖為實驗場景與設定:
 將fa0/7這個Port限制最大可使用的MAC為
1個。並且設定若超過所指定的數量,
Switch的動作為Shutdown。

Fa0/7
主機A
主機B
Hub

觀察Port Security
主機A取得IP之後,使用Show port-security,
觀看CurrentAddr欄位,會顯示1,代表目
前此Port有1主機存在(如左所示)。

將 主 機 B 接 至 HUB 。 此 時 , fa0/7 將 會
shutdown。主機A、B將無法連線。
Switch
Port Security 實驗場景
依據左圖的建構目前實驗的環境。
Show Port Security
國立雲林科技大學 自由軟體研發中心
10
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
DHCP Snooping

Rogue DHCP
Attacker
Untrusted
Trusted
Legitimate DHCP Server
Client
Untrusted
Trusted
DHCP Snooping
DHCP 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
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
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 Terminal
Enter configuration commands, one per line. End with CNTL/Z.
switch(config)#ip dhcp snooping
switch(config)#ip dhcp snooping vlan 32
switch(config)#int fa0/36
switch(config-if)#ip dhcp snooping trust
switch(config-if)#ip dhcp snooping limit rate 100
switch(config-if)#exit
switch(config)#^Z
switch#show ip dhcp snooping
Switch DHCP snooping is enabled
DHCP snooping is configured on following VLANs:
32
DHCP snooping is configured on the following Interfaces:
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封包
Insertion of option 82 is enabled
circuit-id format: vlan-mod-port
remote-id format: MAC
Option 82 on untrusted port is not allowed
Verification of hwaddr field is enabled
Interface
Trusted Rate limit (pps)
------------------------ ------- ---------------FastEthernet0/36
yes
100
switch#
國立雲林科技大學 自由軟體研發中心
12
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Rogue DHCP
Attacker
Untrusted
Trusted
Client
Untrusted
Trusted
Dynamic ARP Inspection

Dynamic ARP Inspection
Dynamic ARP Inspection (DAI)是用來核對IP-toMAC 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
Legitimate DHCP Server
switch(config)#
ip arp inspection trust
設定介面是trust還是untrust。
Switch#configure terminal
Switch(config)#ip arp inspection vlan 34
Switch(config)#interface fa0/0
Switch(config-if)#ip arp inspection trust
Switch(config-if)#ip arp inspection limit rate 20 burst interval 2
switch(config)#
ip arp inspection limit rate rate burst interval
interval
設定rate-limit
國立雲林科技大學 自由軟體研發中心
13
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Client B
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
Configure BPDU
guard here.
Web Server
國立雲林科技大學 自由軟體研發中心
14
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
BPDU Guard

switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
switch(config)#spanning-tree portfast bpduguard
switch(config)#show spanning-tree summary totals
Switch is in pvst mode
Root bridge for: none
Extended system ID
is enabled
Portfast Default
is disabled
PortFast BPDU Guard Default is enabled
Portfast BPDU Filter Default is disabled
Loopguard Default
is disabled
EtherChannel misconfig guard is enabled
UplinkFast
is disabled
BackboneFast
is disabled
Configured Pathcost method used is short
BPDU Guard
BPDU Guard用來抵禦STP manipulation attack,
主要是禁止交換器連接埠接收來路不明的
BPDU封包。
設定BPDU Guard的指令如下:
Switch(config)#
spanning-tree portfast bpduguard
啟用BPDU Guard
Switch#
show spanning-tree summary totals
檢視BPDU Guard的設定
Name
Blocking Listening Learning Forwarding STP Active
---------------------- -------- --------- -------- ------------------1 vlan
0
0
0
9
9
switch#
國立雲林科技大學 自由軟體研發中心
15
實驗 3:Layer 2 交換器裝
置之安全性設定與操作
Switch(config-if)#switchport mode access

Configures the ports as access ports and turns off DTP
Mitigating VLAN Hopping Attacks

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。
Switch(config-if)#switchport access vlan vlan-id

Statically assigns the ports to specific unused VLAN
國立雲林科技大學 自由軟體研發中心
16