Blog | G5 Cyber Security

Neural Networks vs Hashing: Can AI Crack Passwords?

TL;DR

While neural networks can learn to approximate hashing functions and potentially crack some passwords, they aren’t a magic bullet. They require massive datasets of password/hash pairs for training, are vulnerable to adversarial attacks, and generally perform worse than dedicated cracking tools like hashcat or John the Ripper for common hashing algorithms.

1. Understanding Hashing

Hashing is a one-way function: easy to compute the hash from a password, but extremely difficult (ideally impossible) to reverse engineer the password from the hash. Good hashing algorithms are designed to be:

Common hashing algorithms include MD5 (now considered insecure), SHA-1 (also weak), SHA-256, and bcrypt/Argon2 (more secure).

2. How Neural Networks Attempt to Crack Hashes

Neural networks can be trained as a function approximator. Instead of trying to reverse the hash mathematically, they learn a mapping from hashes to potential passwords based on a large training dataset.

3. Step-by-Step Training Example (Conceptual)

  1. Data Preparation: Collect a large dataset of password/hash pairs. Clean and pre-process the data (e.g., convert passwords to numerical representations).
  2. Model Definition: Create an MLP in Python using TensorFlow or PyTorch.
    import tensorflow as tf
    model = tf.keras.models.Sequential([
      tf.keras.layers.Dense(128, activation='relu', input_shape=(hash_length,)), # hash_length is the size of your hashes in bits
      tf.keras.layers.Dense(64, activation='relu'),
      tf.keras.layers.Dense(password_length) # password_length is the maximum length of passwords you're trying to predict
    ])
  3. Compilation: Choose an optimizer (e.g., Adam) and loss function (e.g., categorical cross-entropy if predicting characters).
    model.compile(optimizer='adam', loss='categorical_crossentropy')
  4. Training: Train the model on your dataset.
    model.fit(X_train, y_train, epochs=10)
  5. Prediction: Feed a hash to the trained model and get its prediction for the password.
    prediction = model.predict(hash_to_crack)

4. Limitations & Why It’s Difficult

5. When Neural Networks Might Be Useful

Exit mobile version