PHP 的 crypt 挑战

发布于 2024-09-25 11:27:55 字数 314 浏览 0 评论 0原文

一位朋友给了我一个挑战:他使用 PHP 的 crypt 函数 (CRYPT_STD_DES)(来自 PHP4)加密了一个字符串。我知道用于加密的盐,并且由于 crypt 是一种单向算法,我必须使用暴力方法,并且我知道密码仅由小写字母组成。

现在,我的机器有 16 个核心(2x Xeon)和大量 RAM。实施这种强制攻击的最有效方法是什么(我假设我必须使用 PHP,这不太好,但如果你们中的任何人有想法......)

[编辑]

而且我忘了提一下,加密后的表示长度为 13 个字符,字符串少于 8 个字母,就像简单的密码加密一样:)

A friend gave me a challenge: he encrypted a string using PHP's crypt function (CRYPT_STD_DES) (from PHP4). I know the salt used to encrypt, and as crypt is a one-way algorithm I must use brute-force method, and I know that passwords only consist of lower-case letters.

Now, I have machine with 16 cores (2x Xeon), and lots of RAM. What is most efficient way to implement this force attack (I assume I'll have to use PHP, which is not quite ok, but if any of you have ideas...)

[EDIT]

And i forgot to mention, encrypted representaction is 13chars length, and string is less than 8 letters, just like a simple password encryption :)

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

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

发布评论

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

评论(3

街角迷惘 2024-10-02 11:27:55

这是代码的 C 语言快速尝试(使用 gcc -O2 -lcrypt 编译)
在 Ubuntu 10.04.1 上

  #define _XOPEN_SOURCE
  #include <unistd.h>
  #include <stdio.h>
  #include <stdlib.h>

  void inc(char *p)
  {
     int i;
     for (i=0 ; i<8 && p[i]=='z' ; i++);
     if (i >= 8) exit(printf("Not found :-(\n"));
     if (!p[i]) p[i]='a';
     else p[i]++;
     while (--i >= 0) p[i]='a';
  }

  int main ()
  {
    char *salt = "XY";
    char *buzz = "XYaAbBcCZ0123";

    char pass[] = { 'a',0,0,0,0,0,0,0,0 };

    while(1)
      if ( ! strcmp(crypt(pass, salt), buzz))
        exit(printf("Found %s :-)\n", pass));
      else
        inc(pass);
  }

该代码应该在一两天内(2.10^11 组合)在一台现在的电脑上运行,您可以在多台机器上运行它,一台机器从“a”到“gzzzzzzzz” ,另一个从“haaaaaaa”到“nzzzzzzz”等等......例如。

This is a quick try in C of the code (compiled with gcc -O2 -lcrypt)
on Ubuntu 10.04.1

  #define _XOPEN_SOURCE
  #include <unistd.h>
  #include <stdio.h>
  #include <stdlib.h>

  void inc(char *p)
  {
     int i;
     for (i=0 ; i<8 && p[i]=='z' ; i++);
     if (i >= 8) exit(printf("Not found :-(\n"));
     if (!p[i]) p[i]='a';
     else p[i]++;
     while (--i >= 0) p[i]='a';
  }

  int main ()
  {
    char *salt = "XY";
    char *buzz = "XYaAbBcCZ0123";

    char pass[] = { 'a',0,0,0,0,0,0,0,0 };

    while(1)
      if ( ! strcmp(crypt(pass, salt), buzz))
        exit(printf("Found %s :-)\n", pass));
      else
        inc(pass);
  }

That code should run within a day or two (2.10^11 combinations) on a nowadays pc, you can run it on several machines, one doing from "a" to "gzzzzzzz", another from "haaaaaaa" to "nzzzzzzz" etc... for instance.

笑梦风尘 2024-10-02 11:27:55

来自 PHP 手册:

crypt() 将使用标准 Unix 返回一个散列字符串
基于 DES 的算法或替代算法
可能可用的算法
系统。

某些操作系统支持更多
比一种类型的哈希值。实际上,
有时基于标准 DES
算法被基于 MD5 的算法所取代
算法。触发哈希类型
通过盐论证。在 5.3 之前,
PHP 将确定可用的
安装时的算法基于
系统的 crypt()。如果没有盐
提供的话,PHP会自动生成
标准两个字符 (DES)
盐,或十二个字符(MD5),
取决于 MD5 的可用性

换句话说,crypt() 函数只是从 C 库调用操作系统的 crypt() 函数。这意味着两件事。

首先,加密类型标准化。你不需要使用PHP来运行暴力破解,你只需要知道所使用的算法即可。许多程序(例如 Cane 和 Abel 或 Jack the Ripper)都能够通过暴力、字典或彩虹表攻击来破解多种算法。

其次,加密类型基于加密所在的操作系统。这意味着您可能必须尝试几种不同的加密方法,除非有明显的线索表明使用了哪种方法(加密字符串的模式可能会提示您某些信息)。

我绝对不建议尝试使用 PHP 来暴力破解它,因为解释语言的运行速度比编译语言慢得多。

From the PHP manual:

crypt() will return a hashed string using the standard Unix
DES-based algorithm or alternative
algorithms that may be available on
the system.

Some operating systems support more
than one type of hash. In fact,
sometimes the standard DES-based
algorithm is replaced by an MD5-based
algorithm. The hash type is triggered
by the salt argument. Prior to 5.3,
PHP would determine the available
algorithms at install-time based on
the system's crypt(). If no salt is
provided, PHP will auto-generate
either a standard two character (DES)
salt, or a twelve character (MD5),
depending on the availability of MD5

In other words, the crypt() function just calls the Operating System's crypt() function from the C library. This means two things.

First, the type of encryption is standardized. You don't need to use PHP to run the brute force, you just need to know the algorithm used. Many programs like Cane and Abel or Jack the Ripper are able to break several algorithms via brute force, dictionary, or rainbow table attacks.

Second, the type of encryption is based on the Operating System on which is was encrypted. This means you may have to try several different encryption methods unless there's an obvious clue as to which was used (the pattern of the encrypted string may clue you in to something).

I would definitely NOT suggest trying to use PHP to brute force it, as interpreted languages run much slower than their compiled counterparts.

你的他你的她 2024-10-02 11:27:55

最有效(尽管可能是最没有挑战性)的方法可能是找到已经实现它的人(使用 John the Ripper例如)。

The most efficient (though probably the least challanging) way is probably to find someone who has already implemented it (use John the Ripper for example).

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