Linux 如何在本地获取https包的纯文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9192907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:28:11  来源:igfitidea点击:

How to get plain text of https package locally?

linuxtcpdump

提问by fxp

How to get plain text of a https package sent from my program? There is a tcpdump on my system. thanks.

如何获取从我的程序发送的 https 包的纯文本?我的系统上有一个 tcpdump。谢谢。

回答by Sjoerd

Because any traffic over HTTPS is encrypted, it is not possible to sniff the plaintext using tcpdump.

由于 HTTPS 上的任何流量都是加密的,因此无法使用 tcpdump 嗅探明文。

You can do a man-in-the-middleattack on your HTTPS stream (using Fiddler, for example). However, this will give certificate errors on your client.

您可以对 HTTPS 流进行中间人攻击(例如,使用Fiddler)。但是,这会给您的客户端带来证书错误。

回答by Sjoerd

Wiresharkhas some capabilities to decrypt SSL/TLS traffic; see the SSL page in the Wireshark Wikifor informaton on this. Of course, you will need some information from your machine in order to do it (if you could decrypt arbitrarySSL/TLS traffic, SSL/TLS wouldn't be very useful...). You could either capture the traffic with tcpdump (make sure you capture with -w, so that the trace is saved in pcap format, and with -s 0so that you capture allthe data in the packet) or with Wireshark.

Wireshark有一些功能可以解密 SSL/TLS 流量;有关这方面的信息,请参阅Wireshark Wiki 中的 SSL 页面。当然,你需要从你的机器上获取一些信息才能做到这一点(如果你可以解密任意SSL/TLS 流量,那么 SSL/TLS 就不会很有用......)。您可以使用 tcpdump 捕获流量(确保使用 捕获-w,以便以 pcap 格式保存跟踪,并使用-s 0捕获数据包中的所有数据)或使用 Wireshark。

回答by Hibuki

Use tshark, a wireshark-like commandline tool.

使用 tshark,一个类似wireshark 的命令行工具。

Example usage (with parameters that fit MY system) :

示例用法(使用适合我系统的参数):

tshark -i eth1 port 443 -o "ssl.keys_list:any,443,http,/path/to/your/server.key" -o ssl.debug_file:"/home/your_user/ssl_debug.log"

Of course, replace "eth1" with your interface. The ssl_debug.log is "just in case".

当然,用你的接口替换“eth1”。ssl_debug.log 是“以防万一”。

You can parse more of the data (headers,..) like this

您可以像这样解析更多数据(标题,..)

tshark documentation

tshark 文档