您的位置:首页 > 理论基础 > 计算机网络

https 解密

2020-11-21 16:00 986 查看

概述

在复杂的网络环境中,需要通过抓包来排查网络问题,但是有时候 https 的包是 tls 加密,无法看到真实它在做什么, 需要对其进行解密。

工具

  • tcpdump
  • wireshark
  • https 请求工具 浏览器
  • curl

设置解密变量

export SSLKEYLOGFILE=~/Downloads/ssl.key

测试

发送 https 请求

curl https://baidu.com
<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>bfe/1.0.8.18</center>
</body>
</html>

查看 ssl.key 是否有交换 key

cat ~/Downloads/sslkey.log
CLIENT_RANDOM E358B7ECDEDA7FEC4684942DC6395CFFB34B72918CAFACD69AA06713BB25240D F3934E92E3B1562B13CBA7C8613E7DDCE23A46F68B2B489604C99B65628833738230970A6A2940AA55F600AA06E4874E

有交换 key 说明成功,如果没有交换的 key 信息,那就说明使用的 https 的应用程序(客户端)不支持捕捉

SSLKEYLOGFILE
环境变量输出交换的 key 信息,建议换客户端或查询资料排查。

开始抓包

  1. 查询域名的 IP 地址,通过 dns 解析域名的 IP: 220.181.38.148
$ ping baidu.com -t 1
PING baidu.com (220.181.38.148): 56 data bytes
64 bytes from 220.181.38.148: icmp_seq=0 ttl=49 time=6.459 ms

--- baidu.com ping statistics ---
2 packets transmitted, 1 packets received, 50.0% packet loss
round-trip min/avg/max/stddev = 6.459/6.459/6.459/0.000 ms

在其他终端执行

sudo tcpdump -i any host 220.181.38.148 -w https_baidu.cap -vv
Password:
tcpdump: data link type PKTAP
tcpdump: listening on any, link-type PKTAP (Apple DLT_PKTAP), capture size 262144 bytes
54 packets captured
1027 packets received by filter
0 packets dropped by kernel

发送两次请求

export SSLKEYLOGFILE=~/Downloads/ssl.key
$ curl https://baidu.com
<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>bfe/1.0.8.18</center>
</body>
</html>
$ curl https://baidu.com
<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>bfe/1.0.8.18</center>
</body>
</html>

使用 wireshark 分析抓的包

  1. wireshark 打开抓的包

发现大量的 tls 协议包, 无法知道做了什么请求

  1. 使用 wireshark 打开 sslkey.log
      wireshark --> 首选项 > protocol > ssl

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: