Skip to main content

H2SpaceX   H2SpaceX

pypi: 1.2.2 Python: 3.8.8 License: GPL v3

HTTP/2 low level library based on Scapy which can be used for Single Packet Attack (Race Condition on H2)

Dive into Single Packet Attack Article

I wrote an article and published it at InfoSec Write-ups:

TODO

  • Single Packet Attack - POST
    • implement
  • Single Packet Attack - GET
    • Content-Length: 1 Method
    • POST Request with x-override-method: GET header
  • Response Parsing
    • implement
    • implement threaded response parser
    • add response times in nano seconds for timing attacks
    • Body Decompression
      • gzip
      • br
      • deflate
  • Proxy
    • Socks5 Proxy

Change Log & Beta Versions

  • 1.2.2

    • packaging: consolidated build config into pyproject.toml and removed setup.py
      • fixed invalid [options] sections so package discovery is defined correctly
      • exposed the dev extra (twine) that the old setup.py typo had dropped
    • code cleanup
      • removed unused import and a redundant header-normalization call in GET request builder
      • GET requests now respect check_headers_lowercase=False (consistent with other request methods)
    • added tests/ (unit tests for header utilities) and CONTRIBUTING.md (build & release guide)
  • 1.2.1

    • merged PR-6
      • implement setup_connection for H2Connection (no TLS)
    • merged PR-7
      • normalize HTTP header names using Parser instead of regex
    • fixed Issue 8
      • parsing issue with raw data frames (packets)

More Research

Some following statements are just ideas and not tested or implemented.

  • More Request in a Single Packet
    • Increase MSS (Idea by James Kettle)
    • Out of Order TCP Packets (Idea by James Kettle)
    • IP Fragmentation
  • Proxy the Single Packet Request through SOCKS
  • Single Packet Attack on GET Requests
    • Content-Length: 1 Method (Idea by James Kettle)
    • x-override-method: GET Method (Idea by James Kettle)
    • Index HPACK Headers to Make GET Requests Smaller
    • HEADERS Frame without END_HEADER Flag
    • HEADERS Frame Without Some Pseudo Headers

Installation

H2SpaceX works with Python 3 (preferred: >=3.8.8)

pip install h2spacex

Error in Installation

if you get errors of scapy:

pip install --upgrade scapy

Quick Start

You can import the HTTP/2 TLS Connection and set up the connection. After setting up the connection, you can do other things:

from h2spacex import H2OnTlsConnection

h2_conn = H2OnTlsConnection(
    hostname='http2.github.io',
    port_number=443,
    ssl_log_file_path="PATH_TO_SSL_KEYS.log"  # optional (if you want to log ssl keys to read the http/2 traffic in wireshark)
)

h2_conn.setup_connection()
...

see more examples in Wiki Page

Examples

See examples which contain some Portswigger race condition examples.

Examples Page

Enhanced Single Packet Attack Method (Black Hat 2024) for Timing Attacks

James Kettle introduced an improved version of Single Packet Attack in Black Hat 2024 for timing attacks:

Impvoved Version Image

You can implement this method easily using send_ping_frame() method.

See this Wiki and Parse Response (Threaded) + Response Times for Timing Attacks part:

Improved Version of SPA Sample Exploit

Reference of Improved Method:

References & Resources

I also got some ideas from a previous developed library h2tinker.

Finally, thanks again to James Kettle for directly helping and pointing some other techniques.

Release files for h2spacex 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h2spacex 1.2.2
File Size Uploaded
h2spacex-1.2.2.tar.gz 27.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for h2spacex 1.2.2
File Interpreter ABI Platform
h2spacex-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 53.3 kB

Release files / h2spacex-1.2.2.tar.gz

Download URL h2spacex-1.2.2.tar.gz
Size 27.7 kB
Tags Source
SHA-256 checksum
How to use checksums
49c84d91feba0085692b94fe13b9570c424c5d97363b8fe9a6c49e3de791f120
BLAKE2b-256 checksum
How to use checksums
11cf53203f25a3121e53d538cfacf27cb6b7bcc099f3f7a02db8e5be1ccf61b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / h2spacex-1.2.2-py3-none-any.whl

Download URL h2spacex-1.2.2-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc166843b67c124da59107b494a5d7f8b412efef3e6154b879dcb054999dbd60
BLAKE2b-256 checksum
How to use checksums
5baa5d52abaad66bf0f654c6f33eb22bc99129b8242404973310883d481248c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page