了解彩虹 table Java

Understanding rainbow table Java

我正在上一门密码学课程,但我的老师描述的一些东西真的不清楚而且解释得很糟糕。

他让我在 Java 中创建一个算法来生成一个 RT table (hash/text) 并拥有一个包含 100 个哈希值的文件 (test.txt)至 'crack'。所以我正处于必须比较这两个文件的阶段。但在我看来也是如此 'simple' 我可以查看我的课程,我们讨论了功能缩减,但我不知道如何(何时)实现它。

我已经可以读取文件了,我可以逐行读取我的大文件并将每个哈希值与我的小文件进行比较。我不知道在哪里,尤其是如何在我的算法中实现函数约简以及它包含什么。

非常感谢您的帮助,如果需要我把我的代码。

private static void bufferedReaderFilePasswordFirst() throws IOException {
        Path path = Paths.get("C:\Users\basil\OneDrive - Haute Ecole Bruxelles Brabant (HE2B)\Documents\NetBeansProjects\sha256\passwords.txt");
        int nbOfLine = 0;
        StringBuffer oui = new StringBuffer();
        List<String> test = hashMap();
        
        final DecimalFormat df = new DecimalFormat();
        final DecimalFormatSymbols ds = df.getDecimalFormatSymbols();
        ds.setGroupingSeparator('_');
        df.setDecimalFormatSymbols(ds);
        
        try (BufferedReader readerPasswordGenerate = Files.newBufferedReader(path, Charset.forName("UTF-8"));) {

            String currentLinePassword = null;
            long start = System.nanoTime();
            while(((currentLinePassword = readerPasswordGenerate.readLine()) != null)){
                String firstWord = currentLinePassword.substring(0, currentLinePassword.indexOf(":"));
                int indexList = test.indexOf(firstWord);
                if(indexList!=-1){
                    System.out.println(indexList);
                    String secondWord = currentLinePassword.substring(currentLinePassword.lastIndexOf(":") + 1);
                    oui.append(secondWord).append(System.lineSeparator());
                }
                nbOfLine++;

                if(nbOfLine%1_000_000==0){
                    System.out.printf(
                            "%s / %s%n",
                            df.format(nbOfLine),
                            df.format(10000000));
                }
            }
            System.out.println(oui);
            final long consumed = System.nanoTime() - start;
            final long totConsumed = TimeUnit.NANOSECONDS.toMillis(consumed);
            final double tot = (double) totConsumed;
            System.out.printf("Done. Took %s seconds", (tot / 1000));
        } catch (IOException ex) {
            ex.printStackTrace(); //handle an exception here
        }
    }

测试列表只是要破解的100个哈希列表

in my course and we talk about function reduction but I don't see how (when) to implement it.

我认为您对彩虹 table 甚至 是什么 以及它们与简单的 table 密码和哈希值有何不同感到困惑这些密码。

Rainbow tables 是一种节省存储空间 space 的方法,与完全预先计算的 table 相比,以增加根据候选密码检查每个密码哈希值所需的时间密码和哈希值。

Rainbow tables 使用了“缩减函数”。 reduction 函数接受哈希和列号(见下文)并使用它来生成可能的密码。本质上,它是一个随机密码生成器,使用哈希和列作为输入种子。

Rainbow tables取明文密码候选输入,然后重复
哈希当前明文
将散列减少为新的明文
直到一些预先选择的重复次数完成,并散列最终的明文。然后您只存储起始密码候选和最终哈希。每次迭代都是一个“列”。大多数未存储,但它们的编号用于改变缩减函数的输出并防止出现一些问题。

从哈希中查找密码:

  • 在 table 中查找散列。如果存在,则跳出循环。
  • 如果不存在,将散列减少为另一个明文,对其进行散列,然后返回开始使用该散列。

您现在知道 table 这个特定哈希属于哪个链(如果有的话)。 获取该链的起始明文,并开始散列并减少它,直到你得到已知的散列。之前的明文就是密码!

Rainbow tables 不适用于任何使用“salt”值的密码散列系统。第一个这样的系统是 Unix's crypt in 1976,所以这往往是一个无用的攻击。它仍然被教授,因为这个名字很酷,而且仍然有人制作不加盐密码哈希的系统。

This article is a decent explanation. Wikipedia 有更多细节。