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 | ✅ | ✅ |
| SHA1 | ✅ | ✅ |
| SHA224 | ✅ | ❌ |
| SHA256 | ✅ | ✅ |
| SHA384 | ✅ | ❌ |
| SHA512 | ✅ | ✅ |
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
- Compare my implementation with python hashlib
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| length-extension-tool-0.1.0.tar.gz | 10.1 kB | Without provenance | Details for length-extension-tool-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| length_extension_tool-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for length_extension_tool-0.1.0-py3-none-any.whl |
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
|
Security for length-extension-tool 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.