hash(hash()) 与加盐哈希

发布于 2024-10-08 16:25:44 字数 495 浏览 1 评论 0原文

自从引入 Rainbow 表 以来,并且仅使用散列密码(例如:MD5)将密码存储在数据库不是最好的安全方式

当人们谈论加盐哈希时,总是以这种方式使用它 hash(password . salt) 甚至 hash(hash(password) . salt)

我不知道为什么要使用盐,并为每个密码添加额外的条目来存储盐? 为什么我们不直接使用hash(hash(password)),甚至hash(hash(hash(password)))

放盐是不是更安全?或者只是更复杂的感觉?

Since the introduction of Rainbow tables, and using only hashed passwords (e.x: MD5) to stored passwords in database is not the best secured way.

When people talk about salted hashes, the always use it in this way hash(password . salt) or even hash(hash(password) . salt).

I don't know why to use salt, and add extra entry for each password to store the salt?
Why don't we just use hash(hash(password)), or even hash(hash(hash(password)))?

Is it more secure to put salt? or just the sense of being more complex?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

木緿 2024-10-15 16:25:44

您可以根据 hash(hash(pwd)) 的字典构建彩虹表,所需时间仅为 hash(pwd) 的两倍(甚至更少,因为性能主要与磁盘写入有关),而且它甚至不会更大。使用盐会极大地扩大表所需的大小,直至达到不切实际的程度。

此外(更重要的是),用户通常拥有相同的密码。如果每个用户没有单独的盐,如果您破解了一个用户的密码,那么您就破解了具有相同密码的所有其他用户。

You can build a rainbow table based on a dictionary for hash(hash(pwd)) in just twice the time as for hash(pwd) (even less because performance is mainly about disc writes) and it wouldn't even be larger. Using salt greatly expands the size needed for the table up to the amount where it becomes impractical.

Also (even more important), users often have the same password. Without an individual salt per user, if you've broken one users password, you've broken all other users that have the same password.

雨落星ぅ辰 2024-10-15 16:25:44

为了简单起见,我们假设每个人都使用数字作为密码。

如果每个人都使用 8 位数字作为密码,那就有 100,000,000 种可能性。如果你想破坏系统,你需要散列所有这些可能性。如果你有一个“哈希的哈希的哈希”,你仍然只需要对这 100,000,000 种可能性进行哈希 - 只是以稍微复杂的方式。

现在假设我们也有一个 4 位数的盐。现在,可能性不再是 100,000,000 种,而是 1,000,000,000,000 种……我们为潜在攻击者提供了 10,000 倍的工作量,而不是 3 倍的工作量。

基本上,可以将盐视为一种人为地使每个人的密码更长的方法,从而扩展字典攻击必须起作用的空间。

编辑:需要明确的是,鉴于盐也是以纯文本形式提供的,您仍然只有 100,000,000 种可能性来尝试攻击任何一个哈希。然而,这意味着在尝试了一个密码的这些可能性之后,攻击者将没有任何有用的信息来攻击另一个密码。如果没有盐,攻击者可以创建包含 100,000,000 种可能性的字典,然后仅根据哈希值就知道数据库中的所有密码。换句话说,盐有助于防止批量攻击。它们还意味着您无法预先生成字典:为了有效地攻击单个密码,您必须事先知道盐。如果没有盐,您可以在访问哈希值本身之前计算每个可能的密码的哈希值。

To keep things simple, let's imagine everyone uses digits as their passwords.

If everyone uses 8 digits as their password, that's 100,000,000 possibilities. If you're trying to break the system, you need to hash all those possibilities. If you have a "hash of hash of hash", you still just need to hash those 100,000,000 possibilities - just in a slightly more complicated way.

Now let's pretend we have a 4 digit salt as well. Now, instead of 100,000,000 possibilities there are 1,000,000,000,000... we've given a potential attacker 10,000 times the work to do, instead of just 3 times as much work to do.

Basically, think of a salt as a way of artificially making everyone's password longer, and thus extending the space that a dictionary attack has to work on.

EDIT: Just to be clear, given that the salt is provided in plain-text as well, you would still only have 100,000,000 possibilities to try to attack any one hash. However, it means that after trying those possibilities for one password, the attacker wouldn't have any useful information for attacking another password. Without a salt, an attacker could create a dictionary of 100,000,000 possibilities and then know all the passwords in a database, given only their hashes. In other words, salts help to prevent bulk attacks. They also mean that you can't pregenerate the dictionary: in order to attack a single password effectively, you have to know the salt beforehand. Without a salt, you could compute the hash of every possible password before you get access to the hashes themselves.

紫瑟鸿黎 2024-10-15 16:25:44

如果您不使用盐,那么攻击者可以构建一个彩虹表来攻击数据库中的每个密码。如果没有盐,多次散列并不能保护您,因为彩虹表的工作原理是按照您所描述的方式将散列链接在一​​起:hash(hash(password))

如果为每个用户添加随机盐,那么攻击者就无法重复使用同一个表来破解两个密码,因此他们的工作变得更加困难。作为一个额外的好处,如果使用盐,具有相同密码的两个用户将散列为不同的值。

你迭代哈希的想法仍然很好,但你也需要盐。如果这样做:

function hashPassword(password, salt) {
    result = hash(salt . password)
    for (i = 0; i < 1000; i++) {
        result = hash(salt . result)
    }
    return result
}

那么攻击者的工作就会困难 1000 倍,而对合法用户的影响可以忽略不计。请注意,攻击者每秒可以在一台低端计算机上测试数百万个候选密码 - 哈希函数的设计速度很快。这 1000 次迭代循环可以将可行的攻击变成需要 100 年或更长时间的攻击。当计算机在 18 个月内加速时,只需将迭代次数更改为 2000。salt

、哈希算法和迭代计数不需要保密,可以与计算的哈希值一起存储在数据库中。您可以选择固定的迭代次数和哈希算法,但盐必须为每个用户随机生成。

If you don't use a salt then an attacker can build a single rainbow table can be used to attack every password in your database. Hashing multiple times does not protect you without a salt, because rainbow tables work by chaining hashes together in exactly the way you describe: hash(hash(password)).

If you add a random salt for each user then the attacker cannot re-use the same table to crack two passwords so their work becomes much harder. As an added benefit, two users with the same password will hash to different values if a salt is used.

Your idea of iterating the hash is still good, but you need the salt too. If you do this:

function hashPassword(password, salt) {
    result = hash(salt . password)
    for (i = 0; i < 1000; i++) {
        result = hash(salt . result)
    }
    return result
}

then you make the attacker's work 1000 times harder with a negligible effect on legitimate users. Note that attackers can test millions of candidate passwords each second on a single, low-end computer - hash functions are designed to be fast. This 1000 iteration loop can change a feasible attack into one that will take 100 years or more. When computers speed up in 18 months time just change the number of iterations to 2000.

The salt, hashing algorithm and iteration count do not need to be secret and can be stored in your database alongside the computed hash. You can choose a fixed iteration count and hash algorithm, but the salt must be randomly generated for each user.

倾城月光淡如水﹏ 2024-10-15 16:25:44

迭代哈希和使用盐都可以提高密码哈希的安全性。但它们可以防范完全不同的攻击。

迭代哈希会增加暴力攻击所需的工作量。但是您不应该像您建议的那样使用朴素迭代,而应该使用为其设计的算法,例如 PBKDF2

盐可以防止预先计算的表,因此对于每个网站和用户来说它应该是不同的。

Both iterating the hash and using a salt increase the security of password hashing. But they protect against completely different attacks.

Iterating the hash increases the work required for brute-force attacks. But you shouldn't use a naive iteration as you suggest, but an algorithm designed for it, such as PBKDF2

A salt protects against pre-calculated tables, so it should be different for every website and user.

¢好甜 2024-10-15 16:25:44

加盐的目的是让字典攻击变得毫无意义。现在,无论您对哈希进行多少次重新哈希,相同的输入总是会产生相同的输出哈希,因此可以为此构建一个字典。因此,虽然多重哈希可能会使暴力攻击变得更加困难,但它对字典攻击没有任何作用。

The point of the salt is to make dictionary attacks moot. Now no matter how much you rehash a hash, the same input is always going to yield the same output hash, and therefore one can build a dictionary for that. So while multiple hashing may make it more difficult for brute-force attacks, it doesn't do anything for dictionary attacks.

雨巷深深 2024-10-15 16:25:44

没有什么可以阻止任何人为双重哈希密码构建彩虹表。

Nothing stops anyone for building a Rainbow table for doubly hashed passwords.

看海 2024-10-15 16:25:44

我使用类似的方法对登录用户的密码进行哈希处理。在会话中生成盐(随机值)并将其发送到客户端。用户输入密码,然后用盐进行哈希处理并发回。这可以确保每次从服务器发送的值都不同,从而使使用中间人攻击更难闯入。

I use a comparible method to hash passwords for users that login. A salt (random value) is generated in the session and is sent to the client. The user enters their password, which is then hashed with the salt and sent back. This makes sure that the value sent from the server is different each time, making it harder to break in using a man in the middle attack.

可是我不能没有你 2024-10-15 16:25:44

盐是特定于站点或用户的值。
这意味着为了检索密码,攻击者必须能够访问数据库并知道盐。

此外,攻击者还可以生成一个表一次,然后将其用于攻击多个站点。但是,使用盐时,攻击者必须为每个站点生成一张表,甚至为每个用户生成一次表(使攻击速度变慢)。

特定于站点的盐对网站的安全性几乎没有增加。正如评论中所述,结合使用特定于站点的盐和特定于用户的盐可以比仅使用特定于站点的盐显着提高安全性。

几年前,我在 stackoverflow 上问了一个关于密码存储的问题,这可能对你有帮助。请参阅PHP 密码的安全哈希和盐

The salt is a site- or user-specific value.
That means that in order to retrieve the passwords, an attacker must have both access to the database AND know the salt.

In addition, the attacker could additionally generate a table once and then use it against multiple sites. However, with salts, attackers must generate one table per site or even once per user(making the attacks slower).

Site-specific salts add very little to the security of a website. As said in comments, having a combination of site-specific and user-specific salts can significantly improve security over just a site-specific salt.

A few years ago I asked here on stackoverflow a question about password storage which might be helpful to you. See Secure hash and salt for PHP passwords.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文