6

Is this the right way to crack a password hashed with PHP?

  • I used the password_hash function to hash a password (PHP version 7.3).

  • Then I created a word list using a Python script. It's around 1GB in size.

  • Then I created a PHP script to read that word list and check the password using password_hash.

  • Finally I executed the PHP script using terminal.

Its working fine but is taking too much time to crack the password. As a student I like to write my own scripts and tools. Does any one have an idea on how to do this with better performance and efficiency?

I also searched about using clusters and GPU for password cracking, and I'm not sure if that might help.

  • 6
    Try using Hashcat. – forest Dec 13 '19 at 2:41
  • 1
    I've updated my answer to add some real numbers if you're interested. – Conor Mancone Dec 13 '19 at 18:29
  • 5
    Double check step three. You're showing that you're using password_hash() again, when you probably meant to type password_verify(). password_hash() will create a new salt each time, so will produce different output for the same input. -- Essentially, if step 3 as written is what you're actually doing, then finding a 4 character password goes from "sometime within 30 days" to "maybe sometime before the heat death of the universe, if you're lucky." – Ghedipunk Dec 13 '19 at 18:46
9

Overview

Modern hashing methods (which password_hash uses) are intentionally slow to make it impossible to do exactly what you are trying to do. Most are even resistant against parallelization with a GPU.

So if your goal is to speed up running through a 1 GB password list against a modern password algorithm, there is only one answer: there is no way to do so without running the whole thing on a gigantic computing cluster. Even then, a long enough password can be literally uncrackable.

You cannot accomplish what you are trying to do.

The Numbers

"You cannot do this" is the sort of statement that could use some hard numbers!

Hashing Rate

To crack a password we first need to know how fast we can test hashes. I'm borrowing liberally from a real-life example when someone tried to crack the passwords in the Ashley Madison data dump using a cracking rig with 4 GPUs. This is far better hardware than your typical home user will have access to. In that case bcrypt was configured to use a cost factor 12 (aka 4069 rounds of hashing), and the 4 GPU rig could only manage 156 hashes per second. For a lower cost factor the hash rate rises quickly. PHP uses 10 by default, which naively would result in a 4 times higher hash rate. We'll round up for fun and pretend we manage to hit 750 hashes/second.

Hashes

Next we need to know how many passwords we're trying to crack. Let's use a few examples: all possible 4 character passwords (numbers, letters, 10 special characters), all possible 6 character passwords, all possible 8 character passwords, or a 1Gbyte file filled with passwords. This is how many passwords are in each list:

  1. All 4 digit passwords: 72^4 = ~27,000,000 combinations
  2. All 6 digit passwords: 72^6 = ~74,000,000,000 combinations
  3. All 8 digit passwords: 72^8 = ~700 trillion combinations
  4. A 1Gbyte file: ~100,000,000 passwords (assuming 10 bytes per password on average)

Hashing time

We know how many passwords we want to hash and our hashing rate (750/s), so now simple math tells us how long it will take to run through these lists with a top-of-the-line hashing algorithm:

  1. All 4 digit passwords: ~10 hours
  2. All 6 digit passwords: ~6 years
  3. All 8 digit passwords: ~30,000 years
  4. A 1 GB file: ~1.5 days

For more realistic numbers I roughly estimated the hash rate using one of the CPUs of my own machine, managing about 10 hashes per second. Using that hash rate:

  1. All 4 digit passwords: ~30 days
  2. All 6 digit passwords: ~450 years
  3. All 8 digit passwords: ~2 million years
  4. A 1 GB file: ~115 days

Summary

Buy yourself a half dozen high quality GPUs and, presuming you use the default cost factor, you would be able to crack all possible 4 digit passwords in about a day. Try doing just the 6 digit passwords and it will still take you years. Your 1 GB file filled with passwords is harder to guess the time for, but realistically that will still take a few days to run through even with a bunch of GPUs helping you out.

|improve this answer|||||
  • 3
    I wouldn't say it's impossible to accomplish. It depends on the strength on the passwords being cracked. Trying to find weak passwords (e.g. 5 characters) is still reasonably feasible on a good enough cluster – MechMK1 Dec 13 '19 at 10:44
  • 1
    @MechMK1 I based that on the fact that the word list is 1GB in size, which, overall, I expect to be far too large to run against a modern hashing algorithm. You're right though, it's not quite that simple. When I have some time later I'll add in some actual numbers. – Conor Mancone Dec 13 '19 at 11:02
  • 2
    A 1GB wordlist is definitely not realistic, and not using a dedicated hashing rig or better yet a cloud service, makes this even less realistic. But you know, we all gotta start somewhere :D – MechMK1 Dec 13 '19 at 11:03
2

I really like Conor Mancone's answer. The only thing I'd add is that you could improve efficiency by checking the most likely passwords first, maybe by using lists of previously leaked passwords or things you know about the target (eg. local sports teams).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.