交換機二層安全

二層安全:


Switch Security交換機安全

   越底層安全問題越嚴重

   DMZ區域概念:UNTRUST和TRUST區域均能主動訪問DMZ區域,但是DMZ不能主動訪問任何區域。


【目錄】

1、MAC layer attacks

    ***方法: 

    MAC地址flooding***

    MAC地址的欺騙***

    

    解決方案:

    基於源MAC地址允許流量:端口安全

    基於源MAC地址限制流量:static CAM (發現***後採取的辦法)

    阻止未知的單/組播幀

    802.1x基於端口的認證


2、VLAN attacks

    ***方法: 

    主機與SWITCH形成TRUNK接口

    

    解決方案: 

    switch mode access

    VACL

    PVLAN


3、spoof attacks

    3.1、DHCP spoof

    解決方案:

    DHCP snooping

    

    3.2、IP spoof

    解決方案:

    IP 源防護

    

    3.3、ARP spoof

    解決方案:

    靜態綁定ARP條目

    DAI


4、attacks on switch devices

關閉不必要的服務,比如CDP

限制廣播/組播流量

爲交換機設置登錄密碼

使用SSH實現安全的登錄


【原文】

<part-1.MAC層***>

   A、MAC Flooding MAC layer attacks

   原理:***者不斷更換源MAC地址,佔滿交換機的內存表,使交換機內存溢出

   解決辦法:

1.基於主機MAC來允許流量

 ·可定義2個參數:授權的MAC地址/允許學習多少個MAC地址(默認=1)

 ·違背端口安全,採取的行爲:

  1.shutdown:將永久性或特定週期內Err-Disable端口(默認行爲),併發送snmp trap

  2.restrict:當超過所允許學習的最大MAC數時,將未授權主機的幀丟棄drop,並將violation計數器增加

  3.protect :當超過所允許學習的最大MAC數時,將未授權主機的幀丟棄drop


Sw1(config-if)#shutdown

Sw1(config-if)#switchport mode access    啓用端口安全時,必須先設爲access接口

Sw1(config-if)#switchport port-security    啓用端口安全(默認只能學一個MAC)

Sw1(config-if)#switchport port-security maximum 1   指定最大允許學多少個地址,默認就是1

Sw1(config-if)#switchport port-security mac-address aaaa.bbbb.cccc

Sw1(config-if)#switchport port-security violation [protect|restrict|shutdown]指定行爲

Sw1(config-if)#no shutdown


Sw1(config-if)#switchport port-security aging time 1 (分鐘)設定多長時間後能重新學習MAC地址,也就是設定現有MAC地址的有效期。 /*不能使用sticky和shutdown動作

Sw1(config-if)#switchport port-security mac-address sticky  將動態學到的地址粘住,永久使用


Sw1#show port-security                  可以看到哪些接口應用了端口安全

Sw1#show port-security address          可以看到授權的MAC地址

Sw1#show port-security interface f0/1   可以看到接口的具體狀態


Sw1#show interfaces fastEthernet 0/1

FastEthernet0/1 is down, line protocol is down (err-disabled)  置爲err-disabled狀態


通常做接口安全,要先把接口shut down,這樣它就不會自動學習


讓err-disable接口自動恢復

errdisable recovery cause psecure-violation

show errdisable recovery


2.基於主機MAC來限制流量 (3550上纔可以做)

 列表中定義的MAC將被限制流量


Sw1(config)#mac-address-table static 0010.7b80.7b9b vlan 1 drop

Sw1# show mac address-table


3.阻塞未知單(組)播擴散 (3550上纔可以做)

 對未知MAC地址,SW將從本VLAN的其他端口轉發出去,但對於某些端口(端口安全只需要一個MAC/已到最大MAC)沒必要再轉發這些單(組)播。就可以在這些端口上設定這一特性,通常結合端口安全port security來做。



Sw1(config-if)#switchport block [unicast | multicast]


Rack08Sw1#show int f0/1 switchport 


...Unknown unicast blocked: enabled

...Unknown multicast blocked: disabled


4、802.1x基於端口的認證

一種第二層的訪問控制方法,通過AAA服務器對接入一個接口的用戶進行認證,以決定客戶能否訪問網絡。


配置:

SW(config)#aaa new-model

SW(config)#aaa authentication dot1x default group radius

SW(config)#dot1x system-auth-control


SW(config)#interface f0/1

SW(config-if)#dot1x port-control auto


<part-2 VLAN attacks>

     Explaining VLAN Hopping

     原理:造成不同VLAN能互訪

     造成原因:1、***者發起DTP幀,同交換機形成TRUNK,可截獲TRUNK轉發報文。(接口未做任何配置)

                      2、VLAN Hopping with Double Tagging ***者同交換機形成TRUNK引起的***。(接口未做任何配置)

     解決辦法:

1、switchport mode access

   switchport access vlan  *    /* 該VLAN爲一個未使用的VLAN


2、Vlan 的 access-map (可以基於mac與ip)

VACL也叫VLAN映射表,通過VACL可以實現對一個VLAN中的流量進行過濾。VACL可以根據二層信息進行過濾,也可以根據三層信息來進行過濾。


1、通過調用IP  ACL,可以根據三層的IP地址、協議以及端口號等信息進行過濾。

2、通過調用MAC  ACL,可以根據MAC地址進行過濾,還可以過濾其它的非IP流量。


     每一個VACL可以包含多條語句,每一條語句對於匹配的流量可以有三種不同的操作:

     1、forward   轉發,對數據幀或數據包進行正常轉發

     2、drop   丟棄,當數據流與某個拒絕語句匹配上,將被丟棄

     3、重定向  對於數據流的轉發方向作重定向   (高端交換機才支持)

     注意:如果沒有說明一條語句的操作行爲,默認的行爲是forward。如果進入VLAN的數據流沒有匹配上任何一條語句,最後將被丟棄掉。


基於IP的:

Config#access-list 1 permit 192.168.1.1 0.0.0.0


Config#vlan access-map wolf 10

Config-access-map#match ip address 1

Config-access-map#action drop

Config#vlan access-map wolf 20

Config-access-map#action forword


默認是轉發的  show run 可以看到有 action forword

調用:vlan filter wolf vlan-list 100 全局模式下調用,要指明用在哪個VLAN中,也可對所有ALL


基於mac地址的(MAC地址列表):

1、先寫MAC地址列表

mac access-list extended ccnp

 permit host 00e0.1e3d.d18c any


2、再寫access-map

vlan access-map wolf 10

 action drop

 match mac address ccnp

vlan access-map wolf 20

 action forward


3、調用:

Sw1(config)#vlan filter wolf vlan-list 10

                      Access-map的名字   vlan號

Sw1(config)#vlan filter wolf vlan-list all   對所有VLAN


注意:做這個實驗時,要在每一臺路由器上先clear ip arp 10.1.1.22


3、Private VLANS

解決VLAN個數限制、相同VLAN之間不能互訪

Primary VLAN 爲實際使用VLAN

Secondary VLANs(ISOLATED VLAN、Community VLAN)

Secondary VLANs之間是不能互訪的,ISOLATED VLAN不可互訪,Community VLAN可互訪

     

  3.1 PVLAN Port Types

     Promiscuous: Communicate with all other ports    屬於Primary VLAN

     Isolated:Communicate with only promiscuous ports  屬於Secondary VLAN

     Community:Communicate with other members of community and all promiscuous ports.  屬於Secondary VLAN


  3.2 組網

      需求:R1可以和R2/R3/R4/R5互訪

            R2和R3可以互訪

            R4和R5不能互訪

            VLAN 501(R2和R3)和VLAN 502(R4和R5)不能互訪

           小VLAN 501和502屬於大VLAN 20

           配置步驟:最低的型號是S3560,3750,6000;S3550和S2950僅支持ISOLATE-VLAN

           VTP mode transparent/off  

           vlan 20

           private-vlan primary

           vlan 501

           private-vlan community 

           vlan 502

           private-vlan isolated


           vlan 20

           private-vlan association 501,502


           int f 0/1

           switchport mode private-vlan promiscuous

           switchport private-vlan mapping 20 501,502


           int r f 0/2,f0/3

           switchport mode private-vlan host

           switchport private-vlan host-association 20 501


           int r f 0/4,f0/5

           switchport mode private-vlan host

           switchport private-vlan host-assciation 20 502


           show vlan private-vlan

           show int f 0/1 switchport 


           S2950、S3550和S3560配置ISOLATE-VLAN方法

           int r f0/1,f0/3

           switchport mode access

           switchport access vlan 100

           switchport protected

           注意:protected端口之間是不能訪問的,但是protected與普通端口之間是能訪問的。


    3.3 private-vlan的擴展,配置沿用

          interface vlan 20

            ip address 1.1.1.100 255.255.255.0

        在SW上配置了SVI接口地址後,只有private-vlan可以網管該int vlan 20,其它均不可以。若想community和isolated VLAN可以訪問該接口,則添加如下命令:           

          interface vlan 20

             private-vlan mapping 501,502

        還有在SW上開啓ip routing命令

    驗證:

    show vlan private-vlan


<part-3 Spoofing  attacks>

1、 DHCP Spoof Attacks

解決辦法:

DHCP snooping

原理:

--啓用後,可以將交換機的端口分爲trusted接口和Untrusted接口,默認在交換機上啓用後,所有接口變爲Untrusted接口,需要手動設置trusted接口。

--對於Untrusted接口,只能接收DHCP的請求消息,不會向這個接口發送出DHCP的請求消息。並且drop掉接口進來的DHCP的響應消息。

--對於trusted接口,沒有任何限制,也不做檢測。


注意:早期的IOS不支持


配置實例:

image.png

第一步:

SW1(config)#ip dhcp snooping         必須先開啓這一命令,相當於總開關

SW1(config)#ip dhcp snooping vlan 1  再指定VLAN,這一步也必須要,默認VLAN 1的接口爲untrusted接口


第二步:指定trusted接口,通常是trunk接口、連接真實DHCP服務器的接口。

SW1(config-if)#ip dhcp snooping trust


第三步:還要在被信任的DHCP服務器上打上下列命令:(如果是用遠端路由器和交換機做DHCP服務器的話才需要,若是本設備做DHCP服務無需開啓該命令)

R1(config)#ip dhcp relay information trust-all  /* 若SW關閉了option 82(no ip dhcp snooping information option),該命令可以不配置;另外若是使用了PVLAN技術,也無需開啓該命令


SW1#show ip dhcp snooping binding


SW01#show ip dhcp snooping binding 

MacAddress          IpAddress        Lease(sec)  Type           VLAN  Interface

------------------  ---------------  ----------  -------------  ----  --------------------

E8:40:40:E4:73:C2   10.1.1.94        1052        dhcp-snooping   1    FastEthernet0/23

Total number of bindings: 1


關鍵點:DHCP snooping會在接入的交換機上建立一個DHCP綁定表,爲每一個分配的IP建立一個表項,其中包括客戶端的IP地址、MAC地址、端口號、VLAN編號、租用和綁定類型等信息。也可手動向這個綁定表中添加表項。


SW1#show ip dhcp snooping binding   只顯示動態的綁定項

SW1#show ip dhcp snooping database

SW1#show ip source binding   顯示動態和靜態綁定項 


SW1(config)#ip dhcp snooping binding 1234.5678.abcd vlan 20 172.16.1.1 interface f0/5 靜態綁定一個條目


其它命令:

SW1(config)#ip dhcp snooping information option   啓用option82選項,默認就已開啓

SW1(config)#ip dhcp snooping limit rate 100   限定接口每秒可收多少個DHCP請求包


SW01#show ip dhcp snooping binding 

MacAddress          IpAddress        Lease(sec)  Type           VLAN  Interface

------------------  ---------------  ----------  -------------  ----  --------------------

E8:40:40:E4:73:C1   10.1.1.54        85809       dhcp-snooping   1     FastEthernet0/23

20:37:06:DC:36:40   10.1.1.56        86204       dhcp-snooping   1     FastEthernet0/19

Total number of bindings: 2


2、IPSG源保護(SNOOPING的擴展)---防止網絡層的IP地址欺騙

源保護特性可防止非法設備盜用合法設備的IP接入網絡,只能用於二層端口


需要用到IP綁定表,有兩種方式獲得綁定條目:

    1、靜態綁定IP源地址

    2、使用DHCP snooping技術中動態生成的源IP綁定表


原理:一旦在一個接口啓用了源保護,這個接口默認拒絕所有IP,除非在IP綁定表中有這個接口對應的IP地址綁定條目。


SW1(config)#ip source binding aaaa.bbbb.cccc vlan 1 100.1.1.1 interface f0/1  靜態綁定


SW1(config)#ip dhcp snooping  

SW1(config)#ip dhcp snooping vlan 1

SW1(config)#interface f0/10

SW1(config-if)#ip verify source    開啓源保護,只基於IP進行檢查,在3560和3750上這樣配

SW01#show ip verify source 

Interface  Filter-type  Filter-mode  IP-address       Mac-address        Vlan   Log

---------  -----------  -----------  ---------------  -----------------  ----   ---

Fa0/23     ip           active       10.1.1.94                           1      disabled

SW1(config-if)#ip verify source port-security  開啓源保護,基於IP和MAC進行檢查,默認對於所有的IP是deny-any,對於mac的動作是permit-any。如果做了端口安全,對於mac的動作就是deny-any。

SW01#show ip verify source 

Interface  Filter-type  Filter-mode  IP-address       Mac-address        Vlan   Log

---------  -----------  -----------  ---------------  -----------------  ----   ---

Fa0/23     ip-mac       active       10.1.1.94        E8:40:40:E4:73:C2  1      disabled



 思科4500、6500和7600需要用如下命令開啓

SW1(config-if)#ip verify source vlan dhcp-snooping  

SW1(config-if)#ip verify source vlan dhcp-snooping port-security 


show ip verify source  查看所允許的IP地址,爲比較源地址提供依據

show ip source binding


ip source binding AAAA.BBBB.CCCC vlan 1 10.1.1.200 interface Fa0/9


SW01#show ip source binding 

MacAddress          IpAddress        Lease(sec)  Type           VLAN  Interface

------------------  ---------------  ----------  -------------  ----  --------------------

E8:40:40:E4:73:C1   10.1.1.54        85259       dhcp-snooping   1     FastEthernet0/23

20:37:06:DC:36:40   10.1.1.56        85654       dhcp-snooping   1     FastEthernet0/19

AA:AA:BB:BB:CC:CC   10.1.1.200       infinite    static          1     FastEthernet0/9

Total number of bindings: 3


3、DAI(dynamic arp inspection)防止數據鏈路層的ARP報文的源IP地址欺騙

是一種能夠驗證網絡中ARP數據包的安全特性,可以防止中間人***。


通常需要和DHCP的snooping結合使用,因爲要利用到DHCP snooping技術生成的綁定表。也可靜態寫IP和MAC的綁定表


原理:啓用DAI後,需要將接口分爲trusted和untrusted,默認所有接口都是untrusted接口。

      對於untrusted接口,要進行ARP的檢查,必須是和dhcp-snooping綁定表中的條目相匹配的ARP包才允許通過。

      對於trusted接口,不需要進行ARP檢查。


定義trusted和untrusted接口

  trusted:不控制收發arp報文

  untrusted:不收arp request報文


SW1(config)#ip arp inspection vlan 1

SW1(config-if)#ip arp inspection trust  指定arp檢測的trust接口,一定要做

SW1(config-if)#ip arp inspection limit rate 100  限制每秒所接收的arp包個數


show ip arp inspection interfaces

show ip arp inspection vlan 1


一個實際案例:(不跟DHCP的snooping結合,單獨使用DAI)

 arp access-list ARPTEST

  permit ip host 162.16.40.1 mac host 0000.0c07.ac28

                             源IP地址            源MAC地址


ip arp inspection vlan 1

  ip arp inspection filter ARTTEST vlan 1 static


另外一種情況,IPSG靜態表項也可以實現該功能。

  ip source binding aaaa.bbbb.cccc vlan 1 100.1.1.1 interface f0/1  


注意:ARP包是直接封裝進二層的,所以上面的IPSG源保護技術沒法對付ARP欺騙


<part-4 attacks on switch devices>

    關閉不必要的服務

1. CDP協議

   show cdp neighbor detail


   接口   IP地址

   IOS    VERSION

   NATIVE VLAN

   VTP Domain


  解決辦法:

  1、全局關閉  no cdp run

  2、針對接口操作  no cdp enable


2、廣播/組播抑制

用於對流入端口的廣播和組播流量進行監控,超過閥值後丟棄數據包。


3550(config-if)#storm-control broadcast level 5  按百分比進行監控

3550(config-if)#storm-control broadcast bps 10  按實際流量,注意單位是M


3、SSH(Secure Shell Protocol)

Describing Vulnerablities in the Telnet Protocol

Telnet 協議不安全,用戶名和密碼容易暴露。可以啓用更高級的安全協議。

SSH

 開啓SSH設備:

  ip domain-name wolf.com

  crypto key generate rsa general-keys modulus 1024 


  line vty 0 4

  login local

  transport input ssh

  username wolf password cisco


  登錄設備:

  SSH -l wolf 12.1.1.2

  提示password: cisco




&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



配置案例:

dhcp snooping



ip dhcp snooping 

ip dhcp snooping information option

ip dhcp snooping vlan 10,20



int fa0/0

des access port

ip dhcp limit rate 10


int gi0/0

des uplink

switchport mode trunk

switchport trunk allowed vlan 10,20

ip dhcp snooping trunk



DAI


ip dhcp snooping 

ip dhcp snooping information option

ip dhcp snooping vlan 10,20

ip arp inspection vlan 10,20


int fa0/0

des access port

ip dhcp limit rate 10


int gi0/0

des uplink

switchport mode trunk

switchport trunk allowed vlan 10,20

ip dhcp snooping trunk

ip arp inspection trunk



如果有靜態


arp access-list test

 permit ip host 10.1.1.2 mac host 0017.5aa7.2d28


ip arp inspection filter test vlan 10





IP Source Guard




ip dhcp snooping 

ip dhcp snooping information option

ip dhcp snooping vlan 10,20

ip arp inspection vlan 10,20




int gi0/0

des uplink

switchport mode trunk

switchport trunk allowed vlan 10,20

ip dhcp snooping trunk

ip arp inspection trunk


int fa0/1

sw mo acc

sw ac vlan 2

sw port-securit 

ip arp inspection limit rate 10

ip verify source port-security

ip dhcp snooping limit rate 10


show ip verify source 



如果靜態


ip source binding 0017.5aa7.2d28 vlan 2 10.1.1.2 interface fa0/2


int fa0/2

ip verify source 

接口的過濾。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章