Skip to main content

Bloom-Filter-Hash

Tain a set of Bloom Filters to help reduce the charset needed when brute forcing a password.

Install

pip install bloom-filter-hash

Train Filters

Create the set of bloom filters for passwords of length 2 using the charset of lowercase letters. (Default hashing algorithm is sha256, and default location to store the filters is ./pretrained_filters)

Using Command Line

bloom-hash train "abcdefghijklmnopqrstuvwxyz" 2

Using Python Package

from bloom_filter_hash import train

train(
    "abcdefghijklmnopqrstuvwxyz",
    password_length=2,
    # n_jobs=1, # Sets the number of multiprocessing process to run
)

Train Positional Filters

The basic set of filters we can create from the code above only tells us what chars are potentially in the password. We can extend this to create filters that tell us the potential char and index. Thus reducing the number of positions we need to try.

Using Command Line

bloom-hash train-positions "abcdefghijklmnopqrstuvwxyz" 2

Using Python Package

from bloom_filter_hash import train_positions

train_positions(
    "abcdefghijklmnopqrstuvwxyz",
    password_length=2,
)

Break Hash

Break the hash for the following sha256 hashed password ab using our pre-created filters above. (Same method works for both normal and positions trained filters)

Using Command Line

bloom-hash break fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603 --hash-alg sha256

Using Python Package

from bloom_filter_hash import break_hash

password = break_hash(
    'fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603', 
    'sha256', 
)
print(password)

Python is slow so rather than using python to break the hash you can get use the hashcat function to generate a HashCat command on the filter hits to utilize the efficiencies of HashCat to break the hash. (Same method works for both normal and positions trained filters)

hashcat Command Line

bloom-hash hashcat fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603 --hash-alg sha256

hashcat Python Package

from bloom_filter_hash import hashcat

command = hashcat(    
    'fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603', 
    hash_alg='sha256'
)
command
# >>> hashcat -m 1400 -a 3 fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603 --custom-charset1 ba ?1?1

Pre-trained Filters

I have some pre-trained filters you can use for basic experimentation. I do plan on slowly adding more but my main limitation if how long they take to create as they require running though the whole list of possible passwords.

You can download the pre-trained filter from HuggingFace here

In the ./notebooks/example.ipynb you can find how to download and use them.


Methodology

Memory Requirements

Storage of pre-created hash lists can require very large amounts of storage. For example if we wanted to store all alphanumeric passwords of length 6 using sha256.

We have:

  • Character set: 62 (lowercase + 26 uppercase + 10 digits = 62 alphanumeric characters)
  • Password length: 6
  • One hash is 32 bytes
  • One password is 6 bytes (approx 1 byte per char)

Therefore in total you would need $62^6 * (32+6) \approx 2.15*10^{12}\ bytes \approx 2\ Terabytes$

The approximate equivalent for storing all the hashes into a bloom filter (with error rate of 1%) is

$$ m = -\frac{n\ln p}{(\ln2)^2} = -\frac{62^6\ln 0.01}{(\ln2)^2} \approx 5.44 * 10^{11}\ bits \approx 68\ Gigabytes $$

Where:

  • $n$ = Number of elements in the filter
  • $p$ = Desired false-positive rate (1%)

So as we can see the memory requirements is almost 4% of the full pre-computed hash list.

How it works

Using the efficient storage of bloom filters we can build up a set of filters to try and reduce the amount of work needed to brute force a password hash.

This works by creating a family of filters.

  1. Given a charset, password length, and hashing algorithm
  2. Iterate through all password combinations in the charset
  3. For each char in the password, we add that hash to the corresponding bloom filter that stores all hashes that contain that specific char.
    • For example: We has password "aab", so the we add the hash to 2 different bloom filters that store all passwords of length 3:
      • Bloom filter for passwords that contain "a"
      • Bloom filter for passwords that contain "b"

Then to break a hash we check to see if the password has been seen in any of our pre-created filters, therefore leaving us with a massively reduced charset to brute force through.

TODO:

  • Add method to try break multiples hashes at once
  • Extend to custom hashing algorithms?

Metadata

Release files for bloom-filter-hash 0.1.4

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

Source distribution (sdist)

Source distribution for bloom-filter-hash 0.1.4
File Size Uploaded
bloom_filter_hash-0.1.4.tar.gz 51.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bloom-filter-hash 0.1.4
File Interpreter ABI Platform
bloom_filter_hash-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 62.7 kB

Release files / bloom_filter_hash-0.1.4.tar.gz

Download URL bloom_filter_hash-0.1.4.tar.gz
Size 51.0 kB
Tags Source
SHA-256 checksum
How to use checksums
44ce79e10082dec10737de94d6bff61617e569a004b559de00f2cd2128fc1a9c
BLAKE2b-256 checksum
How to use checksums
8c0bda1124367fe9f6dc6b9e1a37296c905608379a731b06f339f1c60575ec2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bloom_filter_hash-0.1.4-py3-none-any.whl

Download URL bloom_filter_hash-0.1.4-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7026856e94cf19df88d9dd800374bfea7d741a875a5ee7ed8d69526d64cb8dc1
BLAKE2b-256 checksum
How to use checksums
2380fc6d73c838099ddb5a4cd7dbdc87275c43df797dd7c9f685f8cc9e80b167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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