Wireshark不会显示带有SSL SSL套接字的SSL数据包

Mik*_* S. 3 python sockets ssl ssl-certificate wireshark

使用自签名证书博客跟踪Python SSL套接字回显测试,以测试简单的SSL套接字连接.我生成了一个自签名证书,我使用上面的Python代码来试试.

一切都按照描述的方式工作,但问题是,当我使用Wireshark监控网络数据包时,我看不到任何SSL流量.我所看到的只是普通的TCP数据包,但我期待看到正在使用的SSL协议.我错过了什么吗?

为了完整起见,我添加了代码:

client.py

import socket, ssl, pprint

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Require a certificate from the server. We used a self-signed certificate
# so here ca_certs must be the server certificate itself.
ssl_sock = ssl.wrap_socket(s,
                           ca_certs="server.crt",
                           cert_reqs=ssl.CERT_REQUIRED)

ssl_sock.connect(('localhost', 10023))

print repr(ssl_sock.getpeername())
print ssl_sock.cipher()
print pprint.pformat(ssl_sock.getpeercert())

ssl_sock.write("boo!")

if False: # from the Python 2.7.3 docs
    # Set a simple HTTP request -- use httplib in actual code.
    ssl_sock.write("""GET / HTTP/1.0\r
    Host: www.verisign.com\n\n""")

    # Read a chunk of data.  Will not necessarily
    # read all the data returned by the server.
    data = ssl_sock.read()

    # note that closing the SSLSocket will also close the underlying socket
    ssl_sock.close()
Run Code Online (Sandbox Code Playgroud)

server.py

import socket, ssl

bindsocket = socket.socket()
bindsocket.bind(('', 10023))
bindsocket.listen(5)

def do_something(connstream, data):
    print "do_something:", data
    return False

def deal_with_client(connstream):
    data = connstream.read()
    while data:
        if not do_something(connstream, data):
            break
        data = connstream.read()

while True:
    newsocket, fromaddr = bindsocket.accept()
    connstream = ssl.wrap_socket(newsocket,
                                 server_side=True,
                                 certfile="server.crt",
                                 keyfile="server.key")
    try:
        deal_with_client(connstream)
    finally:
        connstream.shutdown(socket.SHUT_RDWR)
        connstream.close()
Run Code Online (Sandbox Code Playgroud)

Wireshark截图:

Wireshark的

Sam*_*Rad 7

您不会看到SSL/TLS的原因是因为您使用的端口与标准443不同.这就是Wireshark无法自动检测协议的原因.您有两种选择:

  • 将流量解码为SSL:

分析>解码为>传输> SSL>应用

  • 添加您的端口:

编辑>首选项>协议> HTTP> SSL/TLS端口= 443,{端口}