HeartBleed python test script

2024/10/5 23:28:57

I came across this Python script that tests the server for the HeartBleed vulnerability:

Would someone be able to explain the content of the "hello", what is being sent and how was this content constructed?

I am not trying to use this script maliciously. I was asked to test a Tomcat 7.0.2 server for the vulnerability: I verified that tcnative-1.dll does use openssl 1.0.1d, but a few of the standalone test tools that I tried testing the server with report that it is not vulnerable.

Answer

hello and hb define bytestrings in a more readable fashion.

The h2bin(x) function does all the work:

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

so the string of hex digits has all whitespace removed, then is decoded from hex to bytes:

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

It's just a compact way to specify a series of bytes using hexadecimal notation and extra whitespace.

The hex data itself is just a normal heartbeat protocol message, in raw bytes. The hello string contains a TLS 1.1 record message, identified by the first byte (16 hex, 22 decimal) as a handshake record, sending a client_hello (sixth byte is 01). This is just setting up a TLS session, telling the server what kind of ciphers the client supports. It doesn't really matter what's contained in this, other than that it tells the server the client supports the Heartbeat extension (a 00 0f byte pair at the end of the message).

It is the hb message that is interesting one, really:

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

18 is the heartbeat content type record, 03 02 identifies the TLS 1.1 protocol version. The 00 03 denotes how large the payload of the message is; 3 bytes, or all of the second line.

The 3 bytes of the message itself consists of the heartbeat type (01, or 'request'), and the message length (40 00, 16384 bytes), followed by no actual message. This causes a broken SSL server to send back a heartbeat response containing 16kb of memory; the non-existing 0-length request message is echoed plus the memory to make up the request length.

https://en.xdnf.cn/q/70431.html

Related Q&A

How to convert a wand image object to numpy array (without OpenCV)?

I am converting pdf files to image using Wand. Then, I do further image processing using ndimage. I would like to directly convert the Wand image into a ndarray... I have seen the answer here, but it u…

Import error running unittest in Python3

I have a problem importing files in Python 3.6. My directories tree is as given below:project/app/├── __init__.py├── a.py└── b.pytest/├── __init__.py├── test_a.py└── test_b.pyIt works…

python: obtaining the OSs argv[0], not sys.argv[0]

(This question was asked here, but the answer was Linux-specific; Im running on FreeBSD and NetBSD systems which (EDIT: ordinarily) do not have /proc.)Python seems to dumb down argv[0], so you dont get…

Why does mypy not accept a list[str] as a list[Optional[str]]?

Example 1: from typing import List, Optionaldef myfunc() -> List[Optional[str]]:some_list = [x for x in "abc"]return some_listMypy complains on example 1:Incompatible return value type (go…

How to do I groupby, count and then plot a bar chart in Pandas?

I have a Pandas dataframe that looks like the following.year month class ---- ----- ----- 2015 1 1 2015 1 1 2015 1 2 2015 1 2 ...I want to be able to create 2 bar chart seri…

How do I execute more code after closing a PyQt window?

Heres an example below:if __name__ == __main__:import sysif (sys.flags.interactive != 1) or not hasattr(QtCore, PYQT_VERSION):QtGui.QApplication.instance().exec_()print "you just closed the pyqt w…

Tor doesnt work with urllib2

I am trying to use tor for anonymous access through privoxy as a proxy using urllib2.System info: Ubuntu 14.04, recently upgraded from 13.10 through dist-upgrade.This is a piece of code I am using for …

Python Selenium Chrome disable prompt for Trying to download multiple files

I am currently running a Python automator which needs to download multiple files within the same session using Selenium Chromedriver.The problem is that when the browser attempts to download the second…

Label outliers in a boxplot - Python

I am analysing extreme weather events. My Dataframe is called df and looks like this:| Date | Qm | |------------|--------------| | 1993-01-…

Matplotlib how to draw vertical line between two Y points

I have 2 y points for each x points. I can draw the plot with this code:import matplotlib.pyplot as pltx = [0, 2, 4, 6] y = [(1, 5), (1, 3), (2, 4), (2, 7)]plt.plot(x, [i for (i,j) in y], rs, markersiz…