天天看點

WIRESHARK之SSL解密

本文介紹在Wireshark網絡協定分析儀中如果解密SSL和TLS流量

要求

以下基本知識:

網絡追蹤

網絡,TCP/IP和SSL/TLS協定

證書和公私鑰的使用

Wireshark網絡協定分析儀

Wireshark 軟體支援SSL解密

伺服器或裝置的私鑰,私鑰格式為PKCS#8 PE

背景

在Wireshark中,SSL解析器功能完整,且支援進階特性,如提供加密私鑰時的SSL解密。這對于使用SSL或TLS加密的思傑産品的排錯有很大的幫助。

步驟

Wireshark 設定

在Wireshark中,SSL解析器功能完整,且支援進階特性,如提供加密私鑰時的SSL解密。平時在進行SSL連接配接調試時經常望着抓到的資料包而興歎,有了Wireshark的解密功能,就可以自由檢視了。

從菜單中選擇Edit > Preferences.

打開Preferences 視窗,展開Protocols.

下拉選擇 SSL.

在RSA keys list後的空白處,提供以下資訊<ip>,<port>,<protocol>,<key_file_name> (如上圖所示)其中: <ip>是具有私鑰的伺服器或裝置的IP位址<port> 是SSL/TLS端口号,通常是443<protocol> 通常是HTTP<key_file_name> 是私鑰的名稱和路徑is the location and file name of the private keyNote: 逗号間沒有符号。而且,使用分号間隔用于不同條目。“<ip>,<port>,<protocol>,<key_file_name>;<ip>,<port>,<protocol>,<key_file_name>;<ip>,<port>,<protocol>,<key_file_name>”.

在SSL debug file後的空白處填入排錯檔案的路徑和檔案名

點選 OK.

SSL則被解密(解密的SSL如下圖所示)

私鑰格式

Wireshark隻要有私鑰就可以解密SSL流量。私鑰需要時decrypted PKCS#8 PEM format (RSA)格式。你可以打開私鑰看它的内容。如果是二進制,則是DER格式,不能用于Wireshark解密。

你可以使用OpenSSL轉換密鑰格式。例如,可以将PKCS#8 DER格式的密鑰轉化成decrypted PKCS#8 PEM format (RSA)格式。在$提示符後輸入如下指令:

openssl pkcs8 -nocrypt -in der.key -informat DER -out pem.key -outformat PEM

其中:

der.key 是DER密鑰檔案的檔案名和路徑

pem.key是pem檔案的檔案名和路徑

解密後的decrypted PKCS#8 PEM format (RSA)格式如下:

注意密鑰開頭為:

-----BEGIN RSA PRIVATE KEY-----

如果開頭為:

-----BEGIN ENCRYPTED PRIVATE KEY-----

則這個密鑰需要用适當的方法解密。OpenSSL可以實作。

At the $ prompt, enter the command: 在$提示符,輸入指令:openssl rsaIf you enter this command without arguments, you are prompted as follows: 如果輸入指令不帶參數,則出現以下字樣:read RSA key

輸入解密的私鑰檔案名

你可以在openssl rsa後加上參數,假如你知道私鑰和解密的PEM的檔案名。例如,私鑰的檔案名是myprivkey.pvk和解密的檔案名問keyout.pem,指令如下:

openssl rsa –in myprivkeypvk -out keyout.pem

參考資料

<a href="http://www.wireshark.org/" target="_blank">http://www.wireshark.org/</a>

<a href="http://wiki.wireshark.org/SSL" target="_blank">http://wiki.wireshark.org/SSL</a>

<a href="http://www.wireshark.org/docs/dfref/s/ssl.html" target="_blank">http://www.wireshark.org/docs/dfref/s/ssl.html</a>

<a href="http://www.openssl.org/docs/apps/rsa.html#EXAMPLES" target="_blank">http://www.openssl.org/docs/apps/rsa.html#EXAMPLES</a>

<a href="http://sourceforge.net/project/showfiles.php?group_id=23617&amp;release_id=4880" target="_blank">http://sourceforge.net/project/showfiles.php?group_id=23617&amp;release_id=4880</a>

本文轉自 拾瓦興閣 51CTO部落格,原文連結:http://blog.51cto.com/ponyjia/1545095

繼續閱讀