gpt4 book ai didi

python - Wireshark 不显示带有 Python SSL 套接字的 SSL 数据包

转载 作者:太空宇宙 更新时间:2023-11-03 13:17:04 24 4
gpt4 key购买 nike

我关注了Python SSL socket echo test with self-signed certificate博客来测试一个简单的 SSL 套接字连接。我生成了一个自签名证书,并使用上面的 Python 代码来尝试一下。

一切都按描述工作,但问题是,当我使用 Wireshark 监视网络数据包时,我没有看到任何 SSL 流量。我所看到的只是普通的 TCP 数据包,但我希望看到正在使用的 SSL 协议(protocol)。我错过了什么吗?

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

客户端.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 截图:

wireshark

最佳答案

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

  • 将流量解码为 SSL:

Analyze > Decode As > Transport > SSL > Apply

  • 添加您的端口:

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

关于python - Wireshark 不显示带有 Python SSL 套接字的 SSL 数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25874304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com