我碰到 这个Python脚本 测试服务器是否存在 HeartBleed 漏洞:

有人能够解释“你好”的内容、正在发送的内容以及该内容是如何构造的吗?

我并不是想恶意使用这个脚本。我被要求测试 Tomcat 7.0.2 服务器上的漏洞:我验证了 tcnative-1.dll 确实使用 openssl 1.0.1d,但我尝试测试服务器的一些独立测试工具报告称它不易受攻击。

有帮助吗?

解决方案

hellohb 以更易读的方式定义字节串。

h2bin(x) 函数完成所有工作:

def h2bin(x):
    return x.replace(' ', '').replace('\n', '').decode('hex')

因此,十六进制数字字符串已删除所有空格,然后从十六进制解码为字节:

>>> '16 03 02 00 dc'.replace(' ', '')
'16030200dc'
>>> '16 03 02 00 '.replace(' ', '').decode('hex')
'\x16\x03\x02\x00\xdc'

它只是使用十六进制表示法和额外空格指定一系列字节的紧凑方法。

十六进制数据本身只是一个普通数据 心跳协议消息, ,以原始字节为单位。这 hello 字符串包含一个 TLS 1.1 记录消息, ,由第一个字节标识(16 十六进制,十进制22)作为握手记录,发送 client_hello (第六个字节是 01)。这只是建立一个 TLS 会话,告诉服务器客户端支持哪种密码。其中包含什么并不重要,除了它告诉服务器客户端支持 Heartbeat 扩展(a 00 0f 消息末尾的字节对)。

它是 hb 信息 这真的很有趣:

hb = h2bin(''' 
18 03 02 00 03
01 40 00
''')

18 是心跳内容类型记录, 03 02 标识 TLS 1.1 协议版本。这 00 03 表示消息的有效负载有多大;3 个字节,或第二行的全部。

消息本身的3个字节由心跳类型(01, ,或“请求”),以及消息长度(40 00, ,16384 字节),然后是 没有实际消息. 。这会导致损坏的 SSL 服务器发回包含 16kb 内存的心跳响应;不存在的0长度请求消息被回显加上内存以弥补请求长度。

其他提示

本页解释了很多关于那个。

const unsigned char good_data_2[] = {
    // TLS record
    0x16, // Content Type: Handshake
    0x03, 0x01, // Version: TLS 1.0
    0x00, 0x6c, // Length (use for bounds checking)
        // Handshake
        0x01, // Handshake Type: Client Hello
        0x00, 0x00, 0x68, // Length (use for bounds checking)
        0x03, 0x03, // Version: TLS 1.2
        // Random (32 bytes fixed length)
        0xb6, 0xb2, 0x6a, 0xfb, 0x55, 0x5e, 0x03, 0xd5,
        0x65, 0xa3, 0x6a, 0xf0, 0x5e, 0xa5, 0x43, 0x02,
        0x93, 0xb9, 0x59, 0xa7, 0x54, 0xc3, 0xdd, 0x78,
        0x57, 0x58, 0x34, 0xc5, 0x82, 0xfd, 0x53, 0xd1,
        0x00, // Session ID Length (skip past this much)
        0x00, 0x04, // Cipher Suites Length (skip past this much)
            0x00, 0x01, // NULL-MD5
            0x00, 0xff, // RENEGOTIATION INFO SCSV
        0x01, // Compression Methods Length (skip past this much)
            0x00, // NULL
        0x00, 0x3b, // Extensions Length (use for bounds checking)
            // Extension
            0x00, 0x00, // Extension Type: Server Name (check extension type)
            0x00, 0x0e, // Length (use for bounds checking)
            0x00, 0x0c, // Server Name Indication Length
                0x00, // Server Name Type: host_name (check server name type)
                0x00, 0x09, // Length (length of your data)
                // "localhost" (data your after)
                0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74,
            // Extension
            0x00, 0x0d, // Extension Type: Signature Algorithms (check extension type)
            0x00, 0x20, // Length (skip past since this is the wrong extension)
            // Data
            0x00, 0x1e, 0x06, 0x01, 0x06, 0x02, 0x06, 0x03,
            0x05, 0x01, 0x05, 0x02, 0x05, 0x03, 0x04, 0x01,
            0x04, 0x02, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02,
            0x03, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03,
            // Extension
            0x00, 0x0f, // Extension Type: Heart Beat (check extension type)
            0x00, 0x01, // Length (skip past since this is the wrong extension)
            0x01 // Mode: Peer allows to send requests
};
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top