【发布时间】:2013-12-20 04:15:03
【问题描述】:
对于一个课程,我得到了一个 base64 编码的加盐 sha-256 哈希密码文件。
文件格式为:
用户名:base64 编码的 sha256 密码:salt
我最初的想法是对哈希进行 base64 解码,这样我就剩下:
用户名:salted 哈希密码:salt
然后通过 JTR 或 hashcat 运行它来破解密码。
我的问题出在base64解码过程中。
我的代码如下:
public static byte[] decode(String string) {
try {
return new BASE64Decoder().decodeBuffer(string);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void splitLine(String strLine)
throws Exception {
StringTokenizer st = new StringTokenizer(strLine, ":");
if (st.hasMoreTokens())
userName = st.nextToken();
if (st.hasMoreTokens())
password = st.nextToken();
if (st.hasMoreTokens())
salt = st.nextToken();
}
public static void main(String[] argv) {
String line = null;
String pwdFile = null;
int count = 0;
try {
pwdFile = argv[0];
BufferedReader br = new BufferedReader(new FileReader(pwdFile));
line = br.readLine();
while (line != null) {
splitLine(line);
/* 替代#1:为哈希生成大量不可打印字符 */ System.out.println(userName+":"+new String(decode(password))+":"+salt);
/* 替代#2:给出散列每个字节的十进制值列表 */ System.out.println(userName+":"+Arrays.toString(decode(password))+":"+salt);
count++;
line = br.readLine();
}
br.close();
System.err.println("total lines read: " + count);
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
使用替代#1,我的输出文件中的行数比输入文件中的多 50,000 行,因此我假设一些解码的字符串包含我也需要修复的换行符。
如何以 hashcat 或 JTR 将识别为加盐 sha256 的格式返回并打印密码的原始哈希值?
【问题讨论】: