c - 如果已知 salt 和密码哈希,则暴力强制 crypt()?

标签 c linux password-encryption brute-force crypt

<分区>

玩过一些兵棋推演,很好奇这是否可行(他们可能希望您以不同的方式解决它,但仍然如此)。

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

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

考虑到 salt 和散列密码已经已知,是否有暴力破解的方法?

最佳答案

与旧版 Unix 变体中使用的原始基于 DES 的 crypt() 算法不同,该算法可以使用相对适度的现代资源进行暴力破解,包括大多数 GNU/Linux 版本在内的新版 Unix 使用扩展的加密密码规范。如果加密密码(或盐)以“$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

关于c - 如果已知 salt 和密码哈希,则暴力强制 crypt()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37115584/

相关文章:

c - 学习集 : How do I place the asterisks and ampersands on function arguments and function calls?

java - C服务器与Java客户端之间的Socket编程

linux - 将输出重定向到变量指定的文件

linux - 查找包含字符串的文件/文件夹并删除但排除字符串被删除

php - CodeIgniter 中的密码散列和验证

java - 使用特定 key 生成 10 位 TOTP 密码

javascript - 将用户名+加密密码发送到 RESTful 服务

c - 删除文件结尾

c - 为什么 lua_tonumber() 在处理大整数时与 lua_tointeger() 有不同的行为?

linux - ARM交叉编译Linux系统安装报错unable to locate package