Skip to main content

HashTools

This is a pure python project implementing hash length extension attack. It also supports the implementation of some popular hashing algorithms.

Currently Supported Algorithms

Algorithm Implementation Length Extension Attack
MD5 :white_check_mark: :white_check_mark:
SHA1 :white_check_mark: :white_check_mark:
SHA224 :white_check_mark: :x:
SHA256 :white_check_mark: :white_check_mark:
SHA384 :white_check_mark: :x:
SHA512 :white_check_mark: :white_check_mark:

Installation

pip install HashTools

Usage

Using algorithm normally

Using update method (like python hashlib)

import HashTools

magic = HashTools.new(algorithm="sha256")
magic.update(b"Hello World!")
print(magic.hexdigest())

or just one line

import HashTools

msg = b"Hello World!"
print(HashTools.new(algorithm="sha256", raw=msg).hexdigest())

Using hash length extension attack

Using extension method

import HashTools
from os import urandom

# setup context
secret = urandom(16)        # idk ¯\_(ツ)_/¯
original_data = b"&admin=False"
sig = HashTools.new(algorithm="sha256", raw=secret+original_data).hexdigest()

# attack
append_data = b"&admin=True"
magic = HashTools.new("sha256")
new_data, new_sig = magic.extension(
    secret_length=16, original_data=original_data,
    append_data=append_data, signature=sig
)

Testing

def test_imple():
    algorithms = [
        "md5", "sha1", "sha224", "sha256", "sha384", "sha512"
    ]

    print("> Implementation test...")
    for alg in algorithms:
        msg = urandom(randint(0, 1024))

        py_hash = hashlib.new(alg)
        my_hash = HashTools.new(alg)

        py_hash.update(msg)
        my_hash.update(msg)

        test1 = py_hash.hexdigest()
        test2 = my_hash.hexdigest()
        
        if test1 != test2:
            print(f"[!] {alg.ljust(6)} failed the validation test!")
            print(test1)
            print(test2)
            exit(1)
        else:
            print(f"[+] {alg.ljust(6)} passed the validation test!")

    print("> All test passed!!!")
  • Testing length extension attack
def test_attack():
    algorithms = [
        "md5", "sha1", "sha256", "sha512"
    ]

    print("> Implementation test...")
    for alg in algorithms:
        # setup context
        length = randint(0, 1024)           
        secret = urandom(length)            # idk ¯\_(ツ)_/¯
        original_data = b"admin=False"
        sig = HashTools.new(algorithm=alg, raw=secret + original_data).hexdigest()
        
        # attack
        append_data = b"admin=True;"
        magic = HashTools.new(alg)
        new_data, new_sig = magic.extension(
            secret_length=length, original_data=original_data,
            append_data=append_data, signature=sig
        )

        if new_sig != HashTools.new(algorithm=alg, raw=secret + new_data).hexdigest():
            print(f"[!] Our attack didn't work with {alg.ljust(6)}")
            exit(1)
        else:
            print(f"[+] {alg.ljust(6)} passed")

    print("> All test passed!!!")

License

References

  • Pub, F. I. P. S. (2012). Secure hash standard (shs). Fips pub, 180(4).

Metadata

Release files for length-extension-tool 0.1.0

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

Source distribution (sdist)

Source distribution for length-extension-tool 0.1.0
File Size Uploaded
length-extension-tool-0.1.0.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for length-extension-tool 0.1.0
File Interpreter ABI Platform
length_extension_tool-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.7 kB

Release files / length-extension-tool-0.1.0.tar.gz

Download URL length-extension-tool-0.1.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
591df10c57a28f81fd0a82dbc758bd869383422daa35d168f1937b6396796822
BLAKE2b-256 checksum
How to use checksums
8a3f80d4ca8259e7ebbb740d2bf2e00a324b53b5f8f8f84b09f3888f231af390
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / length_extension_tool-0.1.0-py3-none-any.whl

Download URL length_extension_tool-0.1.0-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13880f649024a1485c411510faf43888051e551113788a27e1d5df977dd193ae
BLAKE2b-256 checksum
How to use checksums
24146dba5adb7207f0c30bc78391eb107ee41cef27435415dd4a72eb3fdace11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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