lost and found ( for me ? )

SSL通信デコード w/ Wireshark

[ wireshark コンパイル、インストール ]

# uname -r
2.6.18-164.el5

# cat /etc/redhat-release
CentOS release 5.3 (Final)

現在, 最新版の wireshark 1.2.2 をインストール

# yum install -y libpcap-devel.i386 <- decode するのにこれ必要。--with-ssl を指定したとき、 libpcap-devel がないとコンパイルできない。
# cd wireshark-1.2.2
# ./configure --with-ssl
# make && make install

あと openssl も必要。

- w/ GnuTLS , w/ Gcrypt が表示されること

# /usr/local/bin/wireshark -v | grep -i tls
c-ares, without ADNS, without Lua, with GnuTLS 1.4.1, with Gcrypt 1.2.4, with
Running on Linux 2.6.18-164.el5, with libpcap version 0.9.4, GnuTLS 1.4.1,

[ SSL通信デコード確認 ]

wireshark の wiki のサンプルデータ(SSLキャプチャデータ , サンプル秘密鍵 ) を使用し、まずはデコードできるかためす。

http://wiki.wireshark.org/SSL の SampleCaptures/snakeoil2_070531.tgz を使用

# /usr/bin/wireshark rsasnakeoil2.cap

wireshark -> preferences -> protocols -> ssl


または、~/.wireshark/preferences ファイルに下記を追記。

# less /root/.wireshark/preferences
ssl.desegment_ssl_records: TRUE
ssl.desegment_ssl_application_data: TRUE
ssl.keys_list: 127.0.0.1,443,http,/root/rsasnakeoil2.key
ssl.debug_file: /root/wireshark_ssl_debug.txt

デコードできた。


秘密鍵のパスフレーズは解除しておく必要がある。また、PEM形式、Cipher suite が RSA である必要がある。

パスフレーズがある場合は、下記コマンド実行時に、秘密鍵のパスフレーズをきかれる。
また、rsa でなければ、openssl rsa で開けない。

# openssl rsa -in rsasnakeoil2.key -text | head -5
writing RSA key
Private-Key: (1024 bit)
modulus:
00:a4:6e:53:14:0a:de:2c:e3:60:55:9a:f2:42:a6:
af:47:12:2f:17:ce:fa:ba:dc:4e:63:56:34:b9:ba:
73:4b:78:44:3d:c6:6c:69:a4:25:b3:61:02:9d:09:

パスフレーズを解除した 秘密鍵の作成方法

# openssl rsa -in server.key -out server_no_pass.key
秘密鍵のパスフレーズ入力

デコードしたファイルを保存すれば、tshark でも閲覧可能。

# tshark -r ssl.pcap -V | less
Secure Socket Layer
SSLv3 Record Layer: Application Data Protocol: http
Content Type: Application Data (23)
Version: SSL 3.0 (0x0300)
Length: 432
Encrypted Application Data: 4AC33E9D7778012CB4BC4C9A84D7B9900C2110F0FA007C16...
Hypertext Transfer Protocol
GET / HTTP/1.1\r\n
[Expert Info (Chat/Sequence): GET / HTTP/1.1\r\n]
[Message: GET / HTTP/1.1\r\n]

デコードできない場合は、debug file で、原因追究。
下記は成功例

# less wireshark_ssl_debug.txt
ssl_decrypt_record: mac ok
ssl_add_data_info: new data inserted data_len = 231, seq = 6379, nxtseq = 6610
association_find: TCP port 443 found 0xa437bb0
dissect_ssl3_record decrypted len 231
decrypted app data fragment:


[ opensslでテスト用に作成した秘密鍵を使用して、SSL通信をデコードできるかテスト ]

- /etc/httpd/conf.d/ssl.conf ( 秘密鍵 )

SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

PEM ( RSA key ) 、パスフレーズは解除されている

# openssl rsa -in /etc/pki/tls/private/localhost.key -text | head -5
writing RSA key
Private-Key: (1024 bit)
modulus:
00:b9:a0:eb:8e:c0:dd:00:d3:e4:4f:3e:04:cc:91:
9f:95:e7:1b:d6:1d:de:21:05:cd:3f:de:74:9f:66:
10:7d:9d:a3:4f:3e:e9:d6:74:fe:cb:40:31:9a:1d:

ssl.keys_list: 127.0.0.1,443,http,/etc/pki/tls/private/localhost.key

wireshark の設定ファイル修正

# egrep private /root/.wireshark/preferences | grep -v "^#"
ssl.keys_list: 127.0.0.1,443,http,/etc/pki/tls/private/localhost.key

デコードできてないな。秘密鍵は読み込めているから、cipher suite がいけないのかな。

# less wireshark_ssl_debug.txt
ssl_init keys string:
127.0.0.1,443,http,/etc/pki/tls/private/localhost.key
ssl_init found host entry 127.0.0.1,443,http,/etc/pki/tls/private/localhost.key
ssl_init addr '127.0.0.1' port '443' filename '/etc/pki/tls/private/localhost.key' passwor
d(only for p12 file) '(null)'
Private key imported: KeyID 5C:7B:8D:47:B6:C7:0A:7E:F5:2A:7F:46:20:BC:47:75:...
ssl_init private key file /etc/pki/tls/private/localhost.key successfully loaded
association_add TCP port 443 protocol http handle 0x986c628

dissect_ssl enter frame #4 (first time)
ssl_session_init: initializing ptr 0xb2dbbac0 size 564
association_find: TCP port 45722 found (nil)
packet_from_server: is from server - FALSE
dissect_ssl server 127.0.0.1:443
conversation = 0xb2dbb870, ssl_session = 0xb2dbbac0
record: offset = 0, reported_length_remaining = 172
dissect_ssl3_record: content_type 22
decrypt_ssl3_record: app_data len 167 ssl, state 0x00
association_find: TCP port 45722 found (nil)
packet_from_server: is from server - FALSE
decrypt_ssl3_record: using client decoder
decrypt_ssl3_record: no decoder available

--

wireshark のサンプルcap の cipher suite は、 Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA ( from キャプチャファイル )

うまくいっていないやつの cipher suite は、Cipher Suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA ( from キャプチャファイル )
DHE (Diffie-Hellman Ephemeral ) がいけないのかな。。

-- difference between DH and DHE

http://assam-at-night.blogspot.com/2008/08/ssltlsdhdhe.html より。

SSL(TLS)のDHとDHEの違い

DHEのEは、EphemeralのE。
DHEは、DHパラメータを通信時に動作に作成する。
DHは、DHパラメータは証明書に書かれている物を使う。よって、static DHとも呼ばれる。
DH-RSAは、証明書にCAがRSAで署名したという事。証明書にRSA鍵が入っているわけではない。
DHE-RSAは、証明書にRSA鍵が入っている。

--


firefox の chipher suite を変更 。
firefox -> url バーに about:config と入力すると各種configの変更ができる。

- default値



- 変更後: dhe とついているのを false に変更



try again !

# tshark -i lo port 443 -w ssl_turn_off_dhe.pcap

使用している chipher suite がかわった。

# tshark -r ssl_turn_off_dhe.pcap -V | less

Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA

デコードできた。


# tshark -r decode_ssl_turn_off_dhe.pcap -V | less
Secure Socket Layer
TLSv1 Record Layer: Application Data Protocol: http
Content Type: Application Data (23)
Version: TLS 1.0 (0x0301)
Length: 432
Encrypted Application Data: 680DE8EFE17492D9B603214B749EC8DA378731DF3C30BF59...
Hypertext Transfer Protocol
GET /hello.txt HTTP/1.1\r\n
[Expert Info (Chat/Sequence): GET /hello.txt HTTP/1.1\r\n]
[Message: GET /hello.txt HTTP/1.1\r\n]
[Severity level: Chat]
[Group: Sequence]
Request Method: GET
Request URI: /hello.txt
Request Version: HTTP/1.1

# less wireshark_ssl_debug.txt
ssl_decrypt_record: mac ok
ssl_add_data_info: new data inserted data_len = 400, seq = 0, nxtseq = 400
association_find: TCP port 47511 found (nil)
association_find: TCP port 443 found 0x9cdb200
dissect_ssl3_record decrypted len 400
decrypted app data fragment: GET /hello.txt HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (X11; U; Linux i686; ja; rv:1.9.0.14) Gecko/2009091106 CentOS/3.0.
14-1.el5.centos Firefox/3.0.14
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ja,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
--

Get things done!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.