跳转至

哈希破解 (Hash Cracking)

目录 (Summary)

Hashcat

Hashcat 安装 (Hashcat Install)

apt install cmake build-essential -y
apt install checkinstall git -y
git clone https://github.com/hashcat/hashcat.git && cd hashcat && make -j 8 && make install
  1. 提取哈希。
  2. 确定哈希格式:hashcat.net/example_hashes
  3. 根据哈希格式建立破解策略(如:字典 -> 字典+规则 -> 掩码 -> 组合模式 -> Prince 攻击 -> ...)。
  4. 坐等明文。
  5. 审查策略。
  6. 必要时重新开始。

字典攻击 (Dictionary)

将给定列表(即字典)中的每个单词进行哈希计算,并与目标哈希进行比较。

hashcat --attack-mode 0 --hash-type $number $hashes_file $wordlist_file -r $my_rules

掩码攻击 (Mask attack)

掩码攻击是一种旨在优化暴力破解的攻击模式。

将给定字符集和长度下的每一种可能性(如 aaa, aab, aac, ...)进行哈希计算,并与目标哈希进行比较。

# 掩码:1位大写 + 5位小写 + 2位数字 以及 1位大写 + 6位小写 + 2位数字
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?u?l?l?l?l?l?d?d
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?u?l?l?l?l?l?l?d?d 
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 -1 "*+!??" ?u?l?l?l?l?l?d?d?1
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 -1 "*+!??" ?u?l?l?l?l?l?l?d?d?1 

# 掩码:1位大写 + 3位小写 + 4位数字 以及 1位大写 + 4位小写 + 4位数字
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?u?l?l?l?d?d?d?d
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?u?l?l?l?l?d?d?d?d
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?u?l?l?l?l?l?d?d?d?d
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 -1 "*+!??" ?u?l?l?l?d?d?d?d?1
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 -1 "*+!??" ?u?l?l?l?l?d?d?d?d?1

# 掩码:6位小写 + 2位数字 + 特殊符号(+!?*)
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 -1 "*+!??" ?l?l?l?l?l?l?d?d?1
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 -1 "*+!??" ?l?l?l?l?l?l?d?d?1?1

# 掩码:6位小写 + 2位数字
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 /content/hashcat/masks/8char-1l-1u-1d-1s-compliant.hcmask
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 -1 ?l?d?u ?1?1?1?1?1?1?1?1

# 其他示例
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?a?a?a?a?a?a?a?a?a
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?a?a?a?a?a?a?a?a 
hashcat -m 1000 --status --status-timer 300 -w 4 -O /content/*.ntds -a 3 ?u?l?l?l?l?l?l?d?d?d?d
hashcat --attack-mode 3 --increment --increment-min 4 --increment-max 8 --hash-type $number $hashes_file "?a?a?a?a?a?a?a?a?a?a?a?a"
hashcat --attack-mode 3 --hash-type $number $hashes_file "?u?l?l?l?d?d?d?d?s"
hashcat --attack-mode 3 --hash-type $number $hashes_file "?a?a?a?a?a?a?a?a"
hashcat --attack-mode 3 --custom-charset1 "?u" --custom-charset2 "?l?u?d" --custom-charset3 "?d" --hash-type $number $hashes_file "?1?2?2?2?3"
快捷键 对应字符
?l 小写字母 (abcdefghijklmnopqrstuvwxyz)
?u 大写字母 (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
?d 数字 (0123456789)
?s 特殊符号 (!"#$%&'()*+,-./:;<=>?@[]^_`{}~)
?a 包含以上所有 (?l?u?d?s)
?b 二进制数据 (0x00 - 0xff)

John the Ripper (John)

John 常用用法 (John Usage)

# 对包含待破解哈希的密码文件运行
john passwd

# 使用特定字典
john --wordlist=<字典文件路径> passwd

# 使用特定字典并配合规则
john --wordlist=<字典文件路径> passwd --rules=Jumbo

# 显示已破解的密码
john --show passwd

# 恢复中断的会话
john --restore

彩虹表 (Rainbow tables)

在预先计算好的哈希表中查找目标哈希。这是一种通过空间换取时间的方法,可以更快地破解哈希,但比传统的字典或暴力攻击消耗更多的内存。如果哈希值使用了“加盐 (Salted)”处理(即可变随机值作为前缀/后缀),则此攻击无效,因为预计算表会因此失效。

技巧与心得 (Tips and Tricks)

在线破解资源 (Online Cracking Resources)

参考资料 (References)