iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💬
Analyzing HTTP/2 Frames with Scapy in Python
Scapy is an interactive packet manipulation library. You can install it with pip using the following command:
pip install scapy
Let's try using it by starting the REPL:
>>> from scapy.contrib.http2 import H2Frame, H2_CLIENT_CONNECTION_PREFACE
>>> H2Frame
<class 'scapy.contrib.http2.H2Frame'>
>>> H2_CLIENT_CONNECTION_PREFACE
b'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n'
Let's analyze a Settings frame:
>>> pck = b'\x00\x00\x00\x04\x00\x00\x00\x00\x00'
>>> frame = H2Frame(pck)
>>> frame.show()
###[ HTTP/2 Frame ]###
len = 0x0
type = SetFrm
flags = set()
reserved = 0
stream_id = 0
For comparison, I will also provide the results of receive_data from h2.
>>> import h2.connection
>>> import h2.events
>>> data = b'\x00\x00\x00\x04\x00\x00\x00\x00\x00'
>>> c = h2.connection.H2Connection()
>>> events = c.receive_data(data)
>>> [event for event in events]
[<RemoteSettingsChanged changed_settings:{}>]
>>> [isinstance(event, h2.events.RemoteSettingsChanged) for event in events]
[True]
Discussion