1. # 最近Cilium的Service Mesh中使用到IPSec,所以我们今天来一起看一下IPSec的技术细节。

1.IPSec Overview

image.png
https://docs.oracle.com/cd/E19253-01/819-7058/ipsec-ov-2/index.html
image.png

2.使用Wireshark解析IPSec

  1. # 1. 通常我们抓取到的IPSec报文都是ESP格式,没有办法解开对应的报文,所以我们先了解怎么把这个密文解开来感受一下,然后再去看具体的实践原理:
  2. # 参考这篇文章: https://blog.csdn.net/xqjcool/article/details/115873905
  3. # 实际上我们需要在Wireshark上添加对应的SPI(Security parameter index)。但是添加这个SPI的信息,需要知道加密的key和认证秘钥以及对应的算法。
  4. 我们这里给出一个demo wiresharp的包:
  5. # 这个信息我们在普通的Linux上,我们可以通过 ip x s 去获取对应的信息:[在VPP中的,可以使用 vppctl show ipsec sa]
  6. # ip xfrm state
  7. src 10.2.29.8 dst 10.2.29.12
  8. proto esp spi 0x01fb01bd reqid 48 mode transport
  9. replay-window 0
  10. auth-trunc hmac(md5) 0x00000000000000000000000000000002 96 # Authentication Type and Authentication Key.
  11. enc cbc(aes) 0x00000000000000000000000000000001 # Encryption Type and Encryption Key.
  12. sel src 0.0.0.0/0 dst 0.0.0.0/0
  13. src 10.2.29.12 dst 10.2.29.8
  14. proto esp spi 0x80000001 reqid 47 mode transport
  15. replay-window 0
  16. auth-trunc hmac(md5) 0x00000000000000000000000000000002 96
  17. enc cbc(aes) 0x00000000000000000000000000000001
  18. sel src 0.0.0.0/0 dst 0.0.0.0/0
  19. # 需要把这些信息填些在wirehsakr中:[这样我们就可以把原始的ESP解析成明文来解读]

image.png
加上对应的加解密的Key,我们就可以看到明文的信息:
image.png
具体的Wirehark报文可以从获取:
https://github.com/BurlyLuo/train/blob/main/IPSec/sip_ipsec.pcap
核心逻辑便是拿到加解密的Key,然后填些到Wireshark中去做相应的解析即可。