【发布时间】:2017-03-04 17:53:59
【问题描述】:
我目前正在研究一种暴力破解密码的方法,因为我想尝试一下并做一些新的事情。我在下面提供了我正在研究的方法,但这是我首先要做的。最初,我正在为密码生成一个可能值的哈希值,并将其与我在“sample.txt”文件中包含的哈希密码列表进行比较。所以基本上我的目标是从该外部文件中读取散列密码值并将其与所有可能的 3/4 散列密码值进行比较。
当我运行程序时,我不小心将“BruteForce”方法中的while语句的条件设置为true,并且它无休止地运行,但是当我将条件设置为保持生成的密码值的长度为3时只有4,程序突然终止我不知道为什么,我试过调试程序看看哪里出了问题,但我无法推断出任何东西。
这是我的主要方法和“蛮力”方法中的内容:
public TestClass(char[] characterSet, int guessLength) {
cs = characterSet;
cg = new char[guessLength];
Arrays.fill(cg, cs[0]);
}
public static void bruteForce(String username, String hashed_pw) {
//username is the username from the input
//hashed_pw is the hashed value of password
String chars = "0123456789abcdefghijklmnopqrstuvwxyz";
char[] charset = chars.toCharArray();
TestClass bf = new TestClass(charset, 1); //random generation of possible pw value
String attempt = bf.toString();
while ((attempt.length() == 3) || (attempt.length() == 4)) {
String hashed_input = doHash(attempt); //hash the possible pw value
System.out.println("");
System.out.println("Attempt result is: " + attempt);
System.out.println("Hashed of attempt: " + hashed_input);
System.out.println("Hashed Password is : " + hashed_pw);
System.out.println("");
if (hashed_input.equals(hashed_pw)) {
System.out.println("Password Found: " + attempt);
System.out.println(username + "'s password is: " + attempt);
break;
} else {
attempt = bf.toString();
bf.increment();
}
// attempt = bf.toString();
// System.out.println("" + attempt);
// bf.increment();
// return attempt;
}
// return attempt;
}
public char[] cs;
public char[] cg;
public void increment() {
int index = cg.length - 1;
while (index >= 0) {
if (cg[index] == cs[cs.length - 1]) {
if (index == 0) {
cg = new char[cg.length + 1];
Arrays.fill(cg, cs[0]);
break;
} else {
cg[index] = cs[0];
index--;
}
} else {
cg[index] = cs[Arrays.binarySearch(cs, cg[index]) + 1];
break;
}
}
}
@Override
public String toString() {
return String.valueOf(cg);
}
当使用 bruteForce(s[0],s[1]) 运行代码时,它不会提供任何输出,而只会给出 BUILD SUCCESSFUL 消息。
s[0] is the username of the user I'm trying to deduce their password
s[1] is the hashed password I read from an external file
我将 s[1] 值与 bruteForce 方法中的 hashed_input 值进行比较,条件是我的用户可能生成的密码长度仅为 3 或 4 个字符
【问题讨论】:
-
某事物怎么可能同时等于 3 和 4?
-
@Tunaki 这是我的错字,我的意思是等于 3 OR 4
-
看看你的代码,它就是这么做的......
-
现在你可以开始制作minimal reproducible example了。
-
我看过,评论已删除
标签: java if-statement hash while-loop brute-force