玩过一些兵棋推演,很好奇这是否可行(他们可能希望您以不同的方式解决它,但仍然如此)。
有一个 .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