views:

106

answers:

4

Bear with me, I have been only learning PHP for only a few weeks, so example code may confuse me. I think I finally understand salting! It's to protect passwords inside database, if breached.

What I don't understand is, why would a hacker have to crack hashes if they are trying to figure out a user's password (assuming that's their goal)? Wouldn't this be easier? Is the only defense from password guessing is to implement a limit of password entry X amount of times a day or CAPTCHA?

How would a database get hacked in the first place? Is it more password guessing or can hashes be obtained through MySQL injection?

Thanks!

+4  A: 

The idea of salting and hashing is to protect the passwords in case the database has been compromised, whether it was by SQL injection, buffer overflow attacks or simply by going to the server room and pulling the disk out of your server. Salting won't protect you against password guesses, but help in case the attacker gets to the data.

che
+3  A: 

Yes, salting is to protect against the passwords from ever being reversed into plaintext. It also stops someone from saying "the encrypted password is the same on site A as on site B, so the user has the same password in both places".

This isn't just to protect users against hackers; it's also to protect them against you.

Yes, the only defense against password guessing is to slow down or disallow repeated attempts. Most CAPTCHAs are breakable or broken, and you can't impose a CAPTCHA or guess limit on someone who has a copy of the raw database. So keep even the encrypted data out of the hands of malicious individuals. Don't let them at your .htpasswd or /etc/shadow file or your database.

If you are not using salt, generating a rainbow table (in advance) is much easier than guessing a very strong password directly. The key is that building the reverse mapping hash->password can be done once, and the (unsalted) hash is broken forever to anyone possessing the rainbow table.

The database could be hacked if your provider is compromised, if there is an injection vulnerability in your code, if your DB user account password is guessed, if your provider uses eBay to sell off the (presumed wiped) hard drive that had a three-year-old copy of your database on it... It can happen many ways.

Borealid
Salts harden a hash against pre-computation attacks (rainbow tables), not against 'reversing into plaintext' (A hash (salted or not) cannot be reversed). Also, generating a rainbow table is just as expensive as breaking a single password. However, after you have computed a rainbow table you can lookup hashes in the table and quickly find a matching input.
Jacco
@Jacco: if you have a rainbow table, you can map a hash into (some matching) plaintext. Because users tend to choose low-complexity passwords and the hash space is large, the plaintext you find will almost always be the user's password. So no, salting is to prevent reversal into plaintext by way of rainbow tables. And, as I said, the reason generating a rainbow table is easier than breaking a single password is that the rainbow table can be created beforehand.
Borealid
+1  A: 

The key here is that they're not trying to get the password of a user to use on your site, though after you fix the hole that might be useful. It's so that if, for whatever reason, your site is compromised, there isn't damage to you users. People have a tendency to duplicate passwords; that would be bad.

zebediah49
+1  A: 

It might be foolish, but many people use the same passwords for different sites. If your database is compromised and the passwords are simply hashed, then there are techniques (e.g. rainbow tables, even a few web sites) that a hacker could use to find a password value that results in the same hash. That password could then be used to try and gain access to other sites where the user has an account.

If the passwords in your database are salted, then this becomes significantly harder... and if other web sites also salt their passwords with different salts to yours, then it becomes impractical for the hacker.

Mark Baker