IPsec ×××原理与配置



简单的了解一些×××的理论知识:

1.×××的连接模式

×××技术有两种传输模式:隧道模式和传输模式。这两种模式定义了两台实体设备之间传输数据时所采用的不同封装过程。

(1)传输模式

传输模式一个最显著的特点就是:在传输过程中,包头并没有被封装进去,意思是从源端到目的端始终使用原有的IP地址进行通信。而传输的实际数据被封装在×××报文中。

(2)隧道模式

与传输模式的区别显而易见,×××设备将整个三层数据报文封装在×××数据内,再为封装过后的数据报文添加新的IP包头。

2.×××的类型

×××分为站点到站点×××和远程访问×××。

1)站点到站点×××

就是通过隧道模式在×××网关之间保护两个或更多的站点之间的流量,站点间的流量通常是指局域网之间(L2L)的通信流量。

2)远程访问×××

通常用于单用户设备与×××网关之间的通信连接,单用户设备一般为一台PC或小型办公网络等。

加密技术

加密算法:分为两类 对称加密和非对称加密

1.对称加密算法、

(1)DES算法

属IBM的研发的产品,密钥长度为64位,其中8位用于奇偶校验,有效长度为56位。(2)3DES算法

理论上是DES算法的增强版本,因为3DES使用了三个阶段的DES,及同时使用了三个不同的56位密钥,所以相当于产生了一个168位的有效密钥长度。

(3)AES算法

该算法比3DES更为安全,支持128、192和256位密钥长度,有效密钥可达上千位。

优点:1)加解密速度快 缺点:1)不支持身份验证

2)加密长度紧凑 2)密钥管理复杂

3)传输快 3)不安全

2.非对称加密算法

(1)DH算法

常用的算法有:RSA(使用三位数学家名字的首字母来命名)、DSA(数字签名算法)、DH(迪菲-赫尔曼)。前两种常用与验证功能,而DH一般被用来实现ipsec中的Internet密钥交换(IKE)协议。

优点 :安全性较高 缺点:计算过程复杂,比对称加密算法低得多(大约慢1500倍)

数据报文验证

两个方面:身份验证和报文完整性验证。

1.HMAC功能实现验证功能

HMAC算法原理如下:

(1)双方共享执行hash(包括哈希值) 算法的密钥key;

(2)路由器A的用户数据与共享密钥key通过hash算法得到数字签名;

(3)路由器A将数字签名和用户数据一同传送给路由器B;

(4)路由器B执行相同的算法过程得到数字签名;

(5)路由器B比对数字签名是否一致

如果数据在传输过程中被篡改或损坏,接收方同hash算法计算出来的数字签名就会和发送方的数字签名不同,于是得知数据内容在传输过程中被篡改。

2.MD5和SHA

是HMAC的两种常用算法。得到广泛应用。

MD5(信息—摘要算法)在RFC1321中有明确规定,它创建了128位的签名,是目前HMAC功能中应用最为广泛的一种算法。

SHA(安全散列算法)是由NIST开发的。一般称为SHA-1,它可以产生160位的签名(20字节的长度)


IPsec ×××连接

对等体之间建立IPsec ×××的连接需要三个步骤:

1.流量触发IPsec

2.建立管理连接

3.建立数据连接

注:此三步过程省略,(要想了解,请查阅相关资料)

ISAKMP/IKE阶段1

无论×××的类型是站点到站点还是远程访问,都有完成三个任务

1.协商采用何种方式建立管理连接

2.通过DH算法共享密钥信息

3.对等体彼此进行身份验证

建立过程

1.加密算法:DES 、3DES或AES

2.HMAC功能:MD5或SHA-1

3.设备验证的类型:预共享密钥(也可以使用RSA签名等方法)

4.Diffie-Hellman密钥组:Cisco支持1、2、5、7(Cisco路由器不支持密钥组7)

5.管理连接的生存周期

ISAKMP/IKE阶段2

主要在两个IPsec对等体间建立数据连接,其主要完成以下任务:

1.定义对等体间保护何种流量

2.定义用来保护数据的安全协议

3.定义传输集

4.定义数据连接的生存周期及密钥刷新方式

建立过程

1.安全关联(SA)

(1)定义参数索引(SPI):用于唯一标识每条SA连接

(2)安全协议的类型:AH和ESP

(3)目的IP地址

2.ISAKMP/IKE阶段2的传输集

(1)安全协议:AH协议、ESP协议

(2)连接模式:隧道模式、传输模式

(3)加密方式:自定义

(4)验证方式:MD5或SHA-1

IPsec×××-(route)

实验环境:

IPsec VPN原理与配置_IP地址

IP地址及接口规划:\

R1

F0/0:192.168.10.2

R2

F0/0:192.168.10.1

F0/1 100.1.1.1

R3

F0/0:200.1.1.2

F0/1 100.1.1.2

R4

F0/0:200.1.1.1

F0/1 192.168.20.1

R5

F0/1 1 192.168.20.2

注:这里省略设备IP地址的配置

实验要求:

1.R2和R4上建立站点到站点×××;

2.R1能够访问R5,但不能访问外网。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  • 配置管理连接策略:
  • ##用于建立ISAKMP/IKE的管理连接策略,序号范围为1 - 10000,序号值越低,优先级越高##
  • R2(config)#crypto isakmp policy 1
  • ##用于身份验证,采用3des加密算法##
  • R2(config-isakmp)#encryption 3des
  • ##指定设备身份验证的方式,为per-share ##
  • R2(config-isakmp)#au pre-share
  • ##指定验证过程采用HMAC的功能##
  • R2(config-isakmp)#hash sha
  • ##用于指定DH密钥组,默认为1 ,组号越大,算法越安全##
  • R2(config-isakmp)#group 2
  • ##指定了管理连接的生存周期,其默认值为86 400s
  • R2(config-isakmp)#lifetime 60
  • R2(config-isakmp)#ex
  • ##配置预共享密钥##
  • 1.0表示密钥为明文,6表示密钥为密文
  • 2.peer-address 表示对端与之共享密钥的对等体设备地址
  • R2(config)#crypto isakmp key 6 123123 address 200.1.1.1
  • ##配置crypto acl##
  • R2(config)#acc
  • R2(config)#$ 100 per ip 192.168.10.0 0.0.0.255 192.168.20.0 0.0.0.255
  • ##配置阶段2的传输集
  • 1.benet为传输集的名称
  • R2(config)#crypto ipsec transform-set benet esp-des ah-sha-hmac
  • R2(cfg-crypto-trans)#mode tun
  • R2(cfg-crypto-trans)#mode tunnel
  • R2(cfg-crypto-trans)#ex
  • ##配置Crypot MAP##
  • 1.qian为Crypot MAP的名称
  • 2.1位Crypot MAP序号,范围1-65535 ,数值越小,优先级越高
  • R2(config)#crypto map qian 1 ipsec-isakmp
  • % NOTE: This new crypto map will remain disabled until a peer
  • and a valid access list have been configured.
  • ##set peer命令用于指定IPsec的对等体设备,即配置的设备应该与谁建立连接##
  • R2(config-crypto-map)#set peer 200.1.1.1 ##对方的IP地址##
  • ##用于指定传输集名称##
  • R2(config-crypto-map)#set transform-set benet
  • ##调用 Crypto ACL的名称或编号
  • R2(config-crypto-map)#match address 100
  • R2(config-crypto-map)#ex
  • ##将Crypto map应用到接口##
  • R2(config)#int f0/1
  • R2(config-if)#crypto map qian
  • R2(config-if)#
  • *Mar 1 00:10:45.583: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is ON
  • R2(config-if)#
  • 配置IPsec×××(R4)
  • #confi t
  • Enter configuration commands, one per line. End with CNTL/Z.
  • R4(config)#crypto isakmp policy 1
  • R4(config-isakmp)#encryption 3des
  • R4(config-isakmp)#au pre-share
  • R4(config-isakmp)#hash sha
  • R4(config-isakmp)#group 2
  • R4(config-isakmp)#lifetime 60
  • R4(config-isakmp)#ex
  • R4(config)#crypto isakmp key 6 123123 address 100.1.1.1 ##对方的IP地址##
  • R4(config)#acc
  • R4(config)#$ 100 per ip 192.168.20.0 0.0.0.255 192.168.10.0 0.0.0.255
  • R4(config)#crypto ipsec transform-set benet esp-des ah-sha-hmac
  • R4(cfg-crypto-trans)#
  • R4(cfg-crypto-trans)#mode tunnel
  • R4(cfg-crypto-trans)#
  • R4(cfg-crypto-trans)#ex
  • R4(config)#cry
  • R4(config)#crypto map qian 1 ipsec-isakmp
  • % NOTE: This new crypto map will remain disabled until a peer
  • and a valid access list have been configured.
  • R4(config-crypto-map)#set peer 100.1.1.1 ##对方的IP地址##
  • R4(config-crypto-map)#set tra
  • R4(config-crypto-map)#set transform-set benet
  • R4(config-crypto-map)#ma
  • R4(config-crypto-map)#match address 100
  • R4(config-crypto-map)#ex
  • R4(config)#int f0/0
  • R4(config-if)#cry
  • R4(config-if)#crypto map qian
  • R4(config-if)#
  • *Mar 1 00:14:22.779: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is ON
  • R4(config-if)#EdVCIPsec×××#(R2#)
  • ##查看管理连接SA的状态##
  • 该命令显示当前阶段1的SA处于何种状态。ACTIVE表示管理连接建立成功并且已激活
  • R2#show cry isa sa
  • IPv4 Crypto ISAKMP SA
  • dst src state conn-id slot status
  • 200.1.1.1 100.1.1.1 MM_NO_STATE 1001 0 ACTIVE (deleted)
  • IPv6 Crypto ISAKMP SA
  • R2#
  • ##显示数据连接SA的细节信息##
  • R2#sho cry ips sa
  • interface: FastEthernet0/1
  • Crypto map tag: qian, local addr 100.1.1.1
  • protected vrf: (none)
  • local ident (addr/mask/prot/port): (192.168.10.0/255.255.255.0/0/0)
  • remote ident (addr/mask/prot/port): (192.168.20.0/255.255.255.0/0/0)
  • current_peer 200.1.1.1 port 500
  • PERMIT, flags={origin_is_acl,}
  • #pkts encaps: 0, #pkts encrypt: 0, #pkts digest: 0
  • #pkts decaps: 0, #pkts decrypt: 0, #pkts verify: 0
  • #pkts compressed: 0, #pkts decompressed: 0
  • #pkts not compressed: 0, #pkts compr. failed: 0
  • #pkts not decompressed: 0, #pkts decompress failed: 0
  • #send errors 5, #recv errors 0
  • local crypto endpt.: 100.1.1.1, remote crypto endpt.: 200.1.1.1
  • path mtu 1500, ip mtu 1500, ip mtu idb FastEthernet0/1
  • current outbound spi: 0xDA5E7936(3663624502)
  • inbound esp sas:
  • spi: 0xD9E4EE9F(3655659167)
  • transform: esp-des ,
  • in use settings ={Tunnel, }
  • conn id: 1, flow_id: 1, crypto map: qian
  • sa timing: remaining key lifetime (k/sec): (4530656/3476)
  • IV size: 8 bytes
  • replay detection support: Y
  • Status: ACTIVE
  • inbound ah sas:
  • spi: 0xCCDE63C4(3437126596)
  • transform: ah-sha-hmac ,
  • in use settings ={Tunnel, }
  • conn id: 1, flow_id: 1, crypto map: qian
  • sa timing: remaining key lifetime (k/sec): (4530656/3475)
  • replay detection support: Y
  • Status: ACTIVE
  • inbound pcp sas:
  • outbound esp sas:
  • spi: 0xDA5E7936(3663624502)
  • transform: esp-des ,
  • in use settings ={Tunnel, }
  • conn id: 2, flow_id: 2, crypto map: qian
  • sa timing: remaining key lifetime (k/sec): (4530656/3475)
  • IV size: 8 bytes
  • replay detection support: Y
  • Status: ACTIVE
  • outbound ah sas:
  • spi: 0x60E7D4F(101612879)
  • transform: ah-sha-hmac ,
  • in use settings ={Tunnel, }
  • conn id: 2, flow_id: 2, crypto map: qian
  • sa timing: remaining key lifetime (k/sec): (4530656/3474)
  • replay detection support: Y
  • Status: ACTIVE
  • outbound pcp sas:
  • R2#
  • 验证结果:
  • 在R1路上ping通R5;表示已成功建立。
  • R1(config)#do ping 192.168.20.2
  • Type escape sequence to abort.
  • Sending 5, 100-byte ICMP Echos to 192.168.20.2, timeout is 2 seconds:
  • !!!!!
  • Success rate is 100 percent (5/5), round-trip min/avg/max = 64/76/108 ms
  • R1(config)#



IPsec×××—(ASA)

实验环境:


IPsec VPN原理与配置_局域网_02

IP地址及接口规划:

C1

192.168.10.2

C2

192.168.20.2

R1

F0/0 100.1.1.2

F0/1 200.1.1.2

R2

F0/0 192.168.10.1

F0/1 172.16.1.1

R3

F0/0 192.168.20.1

F0/1 172.16.2.1

ASA1

E0/0 100.1.1.1

E0/1 172.16.1.2

ASA2

E0/0 200.1.1.1

E0/1 172.16.2.2

实验要求:

1.在两端的ASA上配置站点到站点×××;

2.ASA上还需配置默认路由出去,静态路由(指向内网)

3.配置好设备地址

4.要求C1能够访问C2


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  • ASA1的配置如下:
  • ciscoasa# confi t
  • ciscoasa(config)# cry isa enable outside ## 启用ISAKMP/IKE ##
  • ##配置管理连接策略##
  • ##用于建立ISAKMP/IKE的管理连接策略,序号范围为1 - 10000,序号值越低,优先级越高##
  • ciscoasa(config)# cry isa poli 1
  • ##用于身份验证,采用3des加密算法##
  • ciscoasa(config-isakmp-policy)# en 3de
  • ##指定设备身份验证的方式,为per-share ##
  • ciscoasa(config-isakmp-policy)# au pre
  • ##指定验证过程采用HMAC的功能##
  • ciscoasa(config-isakmp-policy)# ha sh
  • ##用于指定DH密钥组,默认为1 ,组号越大,算法越安全##
  • ciscoasa(config-isakmp-policy)# gr 2
  • ciscoasa(config-isakmp-policy)# ex
  • ##配置预共享密钥##
  • ciscoasa(config)# cry isa key 123 address 200.1.1.1
  • ##配置crypto acl##
  • ciscoasa(config)# access-list 100 per ip 192.168.10.0 255.255.255.0 192.168.20$
  • ##交换数据连接的传输集##
  • ciscoasa(config)# crypto ipsec transform-set benet esp-3des esp-sha-hmac
  • ciscoasa(config)#
  • ##配置Crypot MAP##(与路由器有点区别)
  • ciscoasa(config)# cry map qian 1 match address 100
  • ciscoasa(config)# cry map qian 1 set peer 200.1.1.1
  • ciscoasa(config)# cry map qian 1 set tran benet
  • ##将Crypot MAP应用到outside接口上##
  • ciscoasa(config)# cry map qian int
  • ciscoasa(config)# cry map qian interface outside
  • ciscoasa(config)#
  • ASA2的配置如下:
  • ciscoasa# confi t
  • ciscoasa(config)# cry isa enable outside
  • ciscoasa(config)# cry isa poli 1
  • ciscoasa(config-isakmp-policy)# en 3de
  • ciscoasa(config-isakmp-policy)# authentication pre-share
  • ciscoasa(config-isakmp-policy)# ha sha
  • ciscoasa(config-isakmp-policy)# gr 2
  • ciscoasa(config-isakmp-policy)# ex
  • ciscoasa(config)# cry isa key 123 address 100.1.1.1
  • ciscoasa(config)# acc
  • ciscoasa(config)# access-list
  • ciscoasa(config)# access-list 100 per ip 192.168.20.0 255.255.255.0 192.168.10$
  • ciscoasa(config)# cry ipse
  • ciscoasa(config)# cry ipsec transform-set benet esp-3des esp-sha-h
  • ciscoasa(config)# cry ipsec transform-set benet esp-3des esp-sha-hmac
  • ciscoasa(config)# cry map qian 1 mat addr 100
  • ciscoasa(config)# cry map qian 1 set peer 100.1.1.1
  • ciscoasa(config)# cry map qian 1 set tran benet
  • ciscoasa(config)# cry map qian int outside



验证结果:

C1能够ping通c2

IPsec VPN原理与配置_VPN设备_03