【问题标题】:Brute forcing crypt() if salt and password hash are known? [closed]如果知道盐和密码哈希,则强制使用 crypt()? [关闭]
【发布时间】:2016-05-09 12:15:29
【问题描述】:

玩了一些战争游戏,很好奇这是否可能(他们可能希望你以不同的方式解决它,但仍然如此)。

有一个 .c 文件,其函数的代码如下所示:

char buffer[20];
scanf("%s", buffer);
char* hash = crypt(buffer, "$6$")
char* password = "$6$123456abcdef" #long string 
if (strcmp(password, hash) == 0) supersecretfunction();

考虑到盐和散列密码已经知道,有没有办法暴力破解?

【问题讨论】:

  • 取决于加密。为了蛮力,您需要能够将加密的纯文本与密文进行比较(即,您需要能够重现整个加密方法。看到您拥有此功能并且您知道盐,我会说您会能够。这一切都归结为加密的密钥长度。现代加密方法在计算上很难在蛮力中使用。所以找出你需要检查多少可能的密码,看看需要多长时间。

标签: c linux password-encryption brute-force crypt


【解决方案1】:

与旧 Unix 变体中使用的原始基于 DES 的 crypt() 算法不同,该算法可以使用相对适度的现代资源进行暴力破解,包括大多数 GNU/Linux 风格在内的新 Unices 使用扩展的加密密码规范。如果加密密码(或 salt)以“$id$”开头,其中“id”是算法标识符,您可以识别这一点,请参见下表。

"$6$" 表示使用 SHA-512 进行加密(实际上是散列)。在第二个“$”之后是盐,另一个“$”和密码的 SHA-512。

这里详细描述了使用的SHA-512算法:https://github.com/dchest/historic-password-hashes/blob/master/glibc-sha-crypt.txt

默认情况下,此算法涉及 5000 轮 SHA-512 用于加密单个密码。即使是中等长度/复杂度的密码,进行蛮力攻击在计算上也是不可行的。基于字典的攻击是可行的,但对于较短、不太复杂的密码仍然很耗时。

有关密码字段的格式,请参阅上面的链接文章或摘要请参阅http://man7.org/linux/man-pages/man3/crypt.3.html,以下部分引用:

   If salt is a character string starting with the characters "$id$"
   followed by a string terminated by "$":

          $id$salt$encrypted

   then instead of using the DES machine, id identifies the encryption
   method used and this then determines how the rest of the password
   string is interpreted.  The following values of id are supported:

          ID  | Method
          ─────────────────────────────────────────────────────────
          1   | MD5
          2a  | Blowfish (not in mainline glibc; added in some
              | Linux distributions)
          5   | SHA-256 (since glibc 2.7)
          6   | SHA-512 (since glibc 2.7)

   So $5$salt$encrypted is an SHA-256 encoded password and
   $6$salt$encrypted is an SHA-512 encoded one.

   "salt" stands for the up to 16 characters following "$id$" in the
   salt.  The encrypted part of the password string is the actual
   computed password.  The size of this string is fixed:

   MD5     | 22 characters
   SHA-256 | 43 characters
   SHA-512 | 86 characters

   The characters in "salt" and "encrypted" are drawn from the set
   [a-zA-Z0-9./].  In the MD5 and SHA implementations the entire key is
   significant (instead of only the first 8 bytes in DES).

编辑:这篇文章可能也很有趣:https://www.win.tue.nl/~aeb/linux/hh/hh-4.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    • 2011-12-06
    • 2020-04-27
    • 2011-01-09
    • 2010-11-30
    • 2014-06-09
    • 1970-01-01
    相关资源
    最近更新 更多