25

Suppose we have passwords that are statistically 7-8 characters long. Is appending a 200 character long salt less secure than a 5 character salt, because of the similar hash function inputs?

I was wondering: what if someone tries to guess the salt by brute forcing the salt with for example the password "123456", or another popular password that can be found in the system or even on a known password from the hacker's own account?

Piotr Müller
  • 411
  • 5
  • 6
  • 9
    There's no point in brute-forcing a salt, because it is (or at least, should be) different for every stored password, and because it's stored with the hashed password anyway, so an attacker who has access to the password hashes will also have access to the salts. – Mike Scott Nov 25 '14 at 07:59
  • 9
    The salt won’t strengthen a bad password; it’s still a bad password. – Gumbo Nov 25 '14 at 08:07
  • 4
    Maybe read this answer on what a salt is and how it 'works'. – Monika Nov 25 '14 at 10:33
  • 4
    @Gumbo There are users with passwords so weak a salt won't help. And there are users with passwords so strong a salt isn't necessary. But there are also users with a password strength somewhere in between where a salt makes the difference between the password getting broken or not. – kasperd Nov 25 '14 at 22:58

5 Answers5

49

As Mike and Gumbo have mentioned in comments, a salt isn't intended to add protection to bad passwords. It's meant to keep the attackers from breaking the whole database at once. The length of the salt isn't meant to add difficulty to breaking the stored passwords. It's meant to ensure that your salt is reasonably unique compared to others on the Internet, and (if you're doing it right) no two of your users will have the same salt.

Imagine you have 20 users who all have "god" as their password. Consider the following scenarios:

  1. Passwords are unsalted
    The attacker can use a precomputed table to break one user's password in very short order. On top of that, once he has the first of the 20, he'll also have the other 19 since their hashes would be identical.

  2. Passwords are salted. Salt used is fairly short. Same salt is used for all users.
    The attacker might have to look for a bit, but could possibly come across a precomputed table made specifically for your configuration. After that point, see scenario 1.

  3. Passwords are salted. Salt used is reasonably strong. Same salt is used for all users.
    Chances are, the attacker won't find a pre-computed table for your system on the Internet. He'll have to make one of his own. This will take a bit of extra time. However, after that's done, we're back to scenario 1 again.

  4. Passwords are salted. Salt used is reasonably strong. Each user has a unique salt.
    This is what you should be doing. Not only will the attacker not be able to find a precomputed table for your system, it's not even worth his time to make his own. Any pre-processing he might do would only work against one user. Even if he hits one of the 20 users mentioned earlier, he won't know the other 19 because the hashes will all be different. Each password must thus be individually attacked, and that's going to take awhile if you're also using a strong and slow hashing algorithm like you should be. Chances are, the weak passwords will still end up compromised eventually. It's just going to take the attacker a good bit more time to get through them all, and you won't have chunks of your users getting compromised at once just because they have the same password.

So, use long salts and make them unique per-user. But don't count on that to help individual users much if they're using "god" as their password.

Iszi
  • 27,127
  • 18
  • 101
  • 163
  • 2
    Scenario 2 is unlikely. The chance to find such a rainbow table is very small. But scenario 2 and 3 have the option to create a rainbow table yourself, given enough resources and if you know the salt. This is why option 4 is so secure - creating rainbow tables for all salts is simply too much work. The strenght of the salt is not really relevant I guess, but better make it not too weak. – SPRBRN Nov 25 '14 at 10:52
  • @SPRBRN There's plenty of stupid people and bad implementations out there. I wouldn't be surprised at all if there were at least five people using two-bit salts out there. The longer yours is, the better the chance that you're not matching the next guy's. And the better chance that you won't have two users with the same salt. – Iszi Nov 25 '14 at 14:15
  • 3
    The asker talks about a 200 character salt. I guess he is asking if 200 is more secure than (something like) 20, or if it's the other way around. He is not talking about 2 bits, or are you talking bytes here? In case of 1 or 2 bytes, I guess rainbow tables will be available. – SPRBRN Nov 25 '14 at 14:39
  • 3
    No competent attacker would bother to create a rainbow table for 3), a direct multi-target attack is at least as efficient. A rainbow table is only useful if you want to crack passwords with the same hash at different times. – CodesInChaos Nov 25 '14 at 14:42
  • Once you get 'god' you might add it to your dictionnary and try it on each account. Unless your user base is huge, is it really more secure ?
  • – Guillaume Nov 25 '14 at 14:59
  • @Guillaume This discussion is really more about the security benefit of hashes, not so much about whether it's a good idea to use "god" as a password. Even if it is #1 in the attacker's dictionary though, it's still going to take them longer to match every user who has that password if the salt is unique per-user than it would otherwise. "Longer" being relative, of course, but still a non-zero difference. – Iszi Nov 25 '14 at 15:11
  • 1
    @CodesInChaos Fair point. However, the entire purpose of salt is to eliminate the benefit of pre-computing hashes at all. If you're not using per-user unique salts, there's still some amount of benefit. Even if you're not building a full table up-front, you're effectively building one as you go through and break each user's credentials. – Iszi Nov 25 '14 at 15:15
  • 1
    @Iszi The point of a salt it to prevent multi-target attacks, so I don't deny the security benefit of unique salts. But precomputation is just one variant of a multi-target attack. IMO people worry too much about rainbow tables compared with live multi-target attacks. – CodesInChaos Nov 25 '14 at 15:18
  • 1
    @SPRBRN I was, literally, talking about two bits. Which is why I picked the specific number of five people. (Actually should have said four, for my intents, but my maths brain isn't warmed up yet.) In any case, the statements made regarding length still apply - the longer your salt, the less likely it'll match someone else's and the the less likely you'll have two users with the same. – Iszi Nov 25 '14 at 15:19
  • @Iszi, yeah I guess, but for lazy programmers two bytes (or characters) may be even more simple to program than two bits! – SPRBRN Nov 25 '14 at 15:22
  • 2
    You forgot 0. Passwords are unhashed. - I know it sounds stupid, but it happens! – corsiKa Nov 26 '14 at 00:08
  • How are these salts stored? If they're stored next to the hashed password, isn't it back to scenario 1? – Qix - MONICA WAS MISTREATED Nov 26 '14 at 20:06
  • @Qix The salt isn't supposed to be a secret. Even if the attacker knows the salt, he still won't know what other data (i.e.: password) went into the hashing function to generate the given output. – Iszi Nov 26 '14 at 20:12