GitHub热门项目-Hashcat密码破解原理与实战
Hashcat是世界上最快的密码恢复工具,支持GPU加速和300+哈希算法。本文将深入讲解密码哈希原理、Hashcat核心功能、攻击模式、规则引擎,以及实战破解技巧。
一、Hashcat概述 1.1 项目信息
1.2 核心特性 1 2 3 4 5 6 7 8 9 10 11 12 13 ┌─────────────────────────────────────────────────────────────┐ │ Hashcat 核心特性 │ ├─────────────────────────────────────────────────────────────┤ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ GPU 加速 │ │ 300 + 算法 │ │ 多攻击模式 │ │ │ │ CUDA / OCL │ │ Hash Types │ │Attack Modes │ │ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ 规则引擎 │ │ 分布式破解 │ │ 会话恢复 │ │ │ │Rule Engine │ │ Distributed │ │ Session │ │ │ └─────────────┘ └─────────────┘ └─────────────┘ │ └─────────────────────────────────────────────────────────────┘
1.3 支持的哈希类型
类别
哈希类型
Mode编号
原始哈希
MD5, SHA1, SHA256, SHA512
0, 100, 1400, 1700
加盐哈希
md5($salt.$pass), sha256($salt.$pass)
10, 1410
迭代哈希
PBKDF2, bcrypt, scrypt
12000, 3200, 8900
系统密码
Windows NTLM, Linux SHA512crypt
1000, 1800
网络协议
WPA/WPA2, Kerberos, NTLM
22000, 13100, 5600
应用密码
MySQL, PostgreSQL, Oracle
300, 12, 112
文档加密
Office, PDF, ZIP, 7z
9400-9800, 10500, 13600
二、密码哈希原理 2.1 哈希函数基础 常见哈希算法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import hashlibmd5_hash = hashlib.md5(b"password" ).hexdigest() sha1_hash = hashlib.sha1(b"password" ).hexdigest() sha256_hash = hashlib.sha256(b"password" ).hexdigest() sha512_hash = hashlib.sha512(b"password" ).hexdigest() import ossalt = os.urandom(16 ) salted_hash = hashlib.sha256(salt + b"password" ).hexdigest()
2.2 密码存储演进 1 2 3 4 5 6 7 8 9 10 11 12 13 14 演进历程: 1. 明文存储 (极不安全) password → "password" 2. 简单哈希 (不安全) password → MD5("password") → "5f4dcc3b..." 3. 加盐哈希 (较安全) password → MD5(salt + "password") → "a1b2c3d4..." 4. 慢哈希 (推荐) password → bcrypt("password", cost =12 ) → "$2b$12$..." password → Argon2("password") → "$argon2id$..."
2.3 常见系统密码格式 系统密码格式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 aad3b435b51404eeaad3b435b51404ee:8846f7eaee8fb117ad06bdd830b7586c $6 $rounds =5000$saltsalt $hash .. .$5 $rounds =5000$saltsalt $hash .. .$1 $saltsalt $hash .. .$2a $10 $N9qo8uLOickgx2ZMRZoMye .. .*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 md5be86a79bf2043622d58d5453c47d4860 $krb5tgs $23 $*user$realm $spn *$hash .. .WPA*02 *hash*mac_ap*mac_sta*e ssid***
三、Hashcat安装与配置 3.1 安装方式 安装Hashcat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 sudo apt updatesudo apt install hashcatgit clone https://github.com/hashcat/hashcat.git cd hashcatmake sudo make installbrew install hashcat hashcat --version hashcat -I hashcat -b hashcat -b -m 1000
3.2 GPU驱动配置 GPU配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 sudo apt install nvidia-driver-535sudo apt install nvidia-cuda-toolkitnvidia-smi hashcat -I sudo apt install rocm-opencl-runtimesudo apt install intel-opencl-icdhashcat -d 1,2,3 hashcat -d 1 -w 3
四、攻击模式详解 4.1 字典攻击 (Mode 0) 字典攻击 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 hashcat -m 0 -a 0 hash.txt wordlist.txt hashcat -m 0 -a 0 hash.txt dict1.txt dict2.txt dict3.txt wget https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt hashcat -m 0 -a 0 hash.txt wordlist.txt -r rules/best64.rule hashcat -m 0 hash.txt --show hashcat -m 0 -a 0 hash.txt wordlist.txt -o cracked.txt
4.2 组合攻击 (Mode 1) 组合攻击 1 2 3 4 5 6 7 8 9 10 11 12 hashcat -m 0 -a 1 hash.txt dict1.txt dict2.txt hashcat -m 0 -a 1 hash.txt dict1.txt dict2.txt -j '$@' -k '$!'
4.3 暴力破解 (Mode 3) 暴力破解 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 hashcat -m 0 -a 3 hash.txt ?d?d?d?d?d?d?d?d hashcat -m 0 -a 3 hash.txt ?l?l?l?l?l?l?l?l hashcat -m 0 -a 3 hash.txt ?u?l?l?l?l?l?l?d hashcat -m 0 -a 3 hash.txt -1 ?l?d ?1?1?1?1?1?1?1?1 hashcat -m 0 -a 3 hash.txt ?a?a?a?a?a?a --increment --increment-min 4 hashcat -m 0 -a 3 hash.txt ?u?l?l?l?l?l?d?d?d?s
4.4 混合攻击 (Mode 6/7) 混合攻击 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 hashcat -m 0 -a 6 hash.txt wordlist.txt ?d?d?d?d hashcat -m 0 -a 7 hash.txt ?d?d?d?d wordlist.txt hashcat -m 0 -a 6 hash.txt wordlist.txt ?d?d?d?d hashcat -m 0 -a 6 hash.txt wordlist.txt ?s?d?d
五、规则引擎 5.1 规则语法 规则语法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 : l u c C t r d f $X ^X [ ] DN iNX sXY @X 'N xNM pN zN ZN kN * NM
5.2 规则示例 实用规则 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 cat > custom.rule << 'EOF' : l u c $1 $! $123 $2024 ^1 c $1 c $! c $123 l $1 l $! sa@ se3 si1 so0 sa@ se3 c $1 sa@ EOF hashcat -m 0 -a 0 hash.txt wordlist.txt -r custom.rule hashcat -m 0 -a 0 hash.txt wordlist.txt -r rules/best64.rule -r rules/toggles1.rule hashcat -m 0 -a 0 hash.txt wordlist.txt --generate-rules=1000
5.3 Leet Speak规则 Leet规则 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 cat > leet.rule << 'EOF' : sa@ se3 si1 so0 ss$ st7 sa@ se3 sa@ se3 si1 sa@ se3 si1 so0 sa4 se3 sa4 sl1 sg9 EOF hashcat -m 0 -a 0 hash.txt wordlist.txt -r leet.rule
六、实战场景 6.1 Windows密码破解 Windows NTLM 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 hashcat -m 1000 -a 0 ntlm_hashes.txt rockyou.txt hashcat -m 1000 -a 0 ntlm_hashes.txt rockyou.txt -r rules/best64.rule hashcat -m 1000 -a 3 ntlm_hashes.txt ?u?l?l?l?l?l?d?d?d?s hashcat -m 5600 -a 0 ntlmv2_hashes.txt rockyou.txt secretsdump.py -ntds ntds.dit -system SYSTEM LOCAL -outputfile hashes hashcat -m 1000 -a 0 hashes.ntds rockyou.txt
6.2 Linux密码破解 Linux Shadow 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 hashcat -m 1800 -a 0 shadow_hashes.txt rockyou.txt hashcat -m 7400 -a 0 shadow_hashes.txt rockyou.txt hashcat -m 500 -a 0 shadow_hashes.txt rockyou.txt sudo cat /etc/shadow | grep -v ':\*:' | grep -v ':!:' > shadow_hashes.txtunshadow /etc/passwd /etc/shadow > combined.txt
6.3 Kerberos票据破解 Kerberoasting 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 hashcat -m 13100 -a 0 kerberos_hashes.txt rockyou.txt hashcat -m 13100 -a 0 kerberos_hashes.txt rockyou.txt -r rules/best64.rule hashcat -m 18200 -a 0 asrep_hashes.txt rockyou.txt hashcat -m 13100 -a 0 kerberos_hashes.txt rockyou.txt -O -w 3
6.4 WiFi密码破解 WPA/WPA2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 airodump-ng wlan0mon -c 6 --bssid XX:XX:XX:XX:XX:XX -w capture hcxpcapngtool -o hash.hc22000 capture.cap cap2hccapx capture.cap hash.hccapx hashcat -m 22000 -a 0 hash.hc22000 rockyou.txt hashcat -m 2500 -a 0 hash.hccapx rockyou.txt hashcat -m 22000 -a 3 hash.hc22000 ?d?d?d?d?d?d?d?d hashcat -m 22000 -a 3 hash.hc22000 1?d?d?d?d?d?d?d?d?d?d
6.5 文档密码破解 Office/PDF/ZIP 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 office2john.py document.docx > office_hash.txt pdf2john.py document.pdf > pdf_hash.txt zip2john archive.zip > zip_hash.txt rar2john archive.rar > rar_hash.txt hashcat -m 9600 -a 0 office_hash.txt rockyou.txt hashcat -m 9500 -a 0 office_hash.txt rockyou.txt hashcat -m 9400 -a 0 office_hash.txt rockyou.txt hashcat -m 10500 -a 0 pdf_hash.txt rockyou.txt hashcat -m 10700 -a 0 pdf_hash.txt rockyou.txt hashcat -m 13600 -a 0 zip_hash.txt rockyou.txt hashcat -m 11600 -a 0 7z_hash.txt rockyou.txt
七、性能优化 7.1 优化参数 性能优化 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 -w 1 -w 2 -w 3 -w 4 -O --gpu-temp-abort=90 --gpu-temp-retain=80 -d 1,2,3 -D 1 --session=mysession --restore --status --status-timer=10 -o cracked.txt --outfile-format=2 --show --left
7.2 分布式破解 分布式配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 hashcat -m 0 -a 3 hash.txt ?a?a?a?a?a?a --skip 0 --limit 1000000 hashcat -m 0 -a 3 hash.txt ?a?a?a?a?a?a --skip 1000000 --limit 1000000 git clone https://github.com/hashtopolis/server.git python3 hashtopolis.py --url https://server/api --token TOKEN
八、防御建议 8.1 密码存储最佳实践
推荐
不推荐
Argon2id
MD5, SHA1
bcrypt (cost≥12)
简单SHA256
scrypt
无盐哈希
PBKDF2 (iterations≥100000)
自定义哈希
8.2 密码策略建议 1 2 3 4 5 6 7 □ 最小长度 : 12字符以上 □ 复杂度 : 混合大小写、数字、特殊字符 □ 禁止常见密码 : 使用密码黑名单 □ 禁止个人信息 : 用户名、生日等 □ 定期更换 : 90天或发现泄露时 □ MFA : 启用多因素认证 □ 密码管理器 : 使用随机生成的强密码
九、总结 Hashcat是密码安全评估的核心工具,掌握其使用对于渗透测试和安全审计至关重要。关键要点:
选择正确的哈希模式 :使用hashcat --help | grep -i "hash_name"查找
合理的攻击策略 :字典→规则→混合→暴力
优化性能 :GPU加速、优化内核、合理的工作负载
规则是关键 :好的规则可以大幅提升成功率
了解目标 :根据目标环境选择合适的字典和规则
注意 :本文内容仅供授权的安全测试和学习研究使用,未经授权破解他人密码属于违法行为。