Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wireshark doesn't show SSL packets with Python SSL sockets

I followed Python SSL socket echo test with self-signed certificate blog to test a simple SSL socket connection. I generated a self-signed certificate and I used the above Python code to just try that out.

Everything works as described but the problem is, I don't see any SSL traffic when I monitor network packets using Wireshark. All I see is just normal TCP packets but I'm expecting to see SSL protocol being used. Am I missing something?

For the sake of completeness I add the code:

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()

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()

Wireshark screenshot:

wireshark

like image 706
Mikael S. Avatar asked Feb 13 '23 00:02

Mikael S.


1 Answers

The reason you won't see SSL/TLS is because you're using a different port than the standard 443. That's why Wireshark is unable to detect the protocol automatically. You have two options:

  • Decode the traffic as SSL:

Analyze > Decode As > Transport > SSL > Apply

  • Add your port:

Edit > Preferences > Protocols > HTTP > SSL/TLS Ports = 443, {port}

like image 89
Sam R. Avatar answered Mar 08 '23 03:03

Sam R.