Post

Password Attacks — Wordlists, Hashcat & John the Ripper

Password Attacks — Wordlists, Hashcat & John the Ripper

Workflow: Thu thập hash → Nhận dạng loại hash → Chọn tool & attack mode → Crack → --show


Password Mutations & Custom Wordlists

CeWL — Website Keyword Wordlist

1
cewl https://www.inlanefreight.com -d 4 -m 6 --lowercase -w inlane.wordlist
OptionGiải thích
-d 4Depth — crawl sâu tối đa 4 cấp link từ URL gốc
-m 6Min word length — chỉ lấy từ có độ dài ≥ 6 ký tự
--lowercaseChuyển toàn bộ từ về chữ thường
-w inlane.wordlistOutput file

Username Anarchy — Username Wordlist Generation

1
2
3
4
5
6
7
# Chuẩn bị file tên
cat names.txt
# Ben Williamson
# Bob Burgerstien
# Jim Stevenson

./username-anarchy -i /home/ltnbob/names.txt > usernames.txt
OptionGiải thích
-i <file>Input file — mỗi dòng một Firstname Lastname

Output ví dụ cho “Jane Doe”: jane, janedoe, jane.doe, janed, j.doe, jdoe, djane, doej, doe.jane,… — tất cả biến thể username phổ biến được sinh tự động.

OSINT sources: LinkedIn, website công ty, Google dork "@company.com" để lấy email → suy ra naming convention trước khi chạy tool.

Tại sao không chỉ dùng wordlist có sẵn? Tổ chức thường dùng naming convention riêng (firstinitiallastname, firstname.lastname,…). Biết convention → giảm tối đa số lần đoán → tránh lockout.


Hash Identification — hashid

1
2
3
hashid -j 193069ceb0461e1d40d216e32c79c704
hashid -m '$1$FNr44XZC$wQxY6HHLrgrGX0e1195k.1'
hashid <hash>
OptionDùng vớiGiải thích
-jJohn the RipperIn kèm JtR --format tương ứng
-mHashcatIn kèm Hashcat -m mode ID tương ứng
(không flag)Tham khảoChỉ liệt kê các loại hash có thể match

Nhận dạng nhanh theo độ dài hex: 32 ký tự = MD5 · 40 = SHA1 · 64 = SHA256 · 128 = SHA512. Prefix $6$ = sha512crypt · $1$ = md5crypt · $2*$ = bcrypt.


Hash Type Reference

Hash TypeHashcat -mJtR --formatNhận dạng
MD50raw-md532 ký tự hex
SHA1100raw-sha140 ký tự hex
SHA2-2561400raw-sha25664 ký tự hex
SHA2-5121700raw-sha512128 ký tự hex
MD4900raw-md432 ký tự hex
NTLM1000ntDump từ SAM/NTDS/LSASS
DCC22100mscach2$DCC2$10240#user#hash
sha512crypt1800sha512cryptLinux $6$
md5crypt500md5cryptLinux $1$
bcrypt3200bcryptWeb app $2*$
Kerberoast TGS13100krb5Active Directory
BitLocker22100bitlockerEncrypted disk
WPA2 PMKID16800wpa2johnWiFi
ZIP17200zipZIP archive
RAR23800rarRAR archive
PDF10500pdfPDF document
SSH22921sshSSH private key

DCC2 vs NTLM: NTLM ~4,600,000 H/s · DCC2 ~5,500 H/s → chậm hơn ~800 lần vì dùng PBKDF2. DCC2 không dùng được cho Pass-the-Hash — phải crack ra plaintext mới dùng được.


Hashcat — Full Reference

Cú pháp chung

1
hashcat -a <attack_mode> -m <hash_type> <hashes> [wordlist/rule/mask]
Tham sốGiải thích
-aAttack mode
-mHash type ID
<hashes>Hash string đơn hoặc file chứa nhiều hashes
-o <file>Output file — lưu kết quả dạng hash:plaintext
--showHiển thị kết quả đã crack từ potfile
--forceBỏ qua cảnh báo (dùng trên VM thiếu GPU)

Attack Mode 0 — Dictionary Attack

1
2
3
4
5
6
7
hashcat -a 0 -m 0 e3e3ec5831ad5e7288241960e5d4fdb8 /usr/share/wordlists/rockyou.txt

# Với rule
hashcat -a 0 -m 0 <hash> /usr/share/wordlists/rockyou.txt -r /usr/share/hashcat/rules/best64.rule

# Generate mutated wordlist (không crack, chỉ xuất wordlist)
hashcat --force password.list -r custom.rule --stdout | sort -u > mut_password.list
OptionGiải thích
-a 0Dictionary attack
-r <rulefile>Áp dụng rule biến thể từ
--stdoutXuất wordlist đã mutate ra terminal

Rule files tại /usr/share/hashcat/rules/:

Rule fileMô tả
best64.rule64 biến thể phổ biến nhất — dùng trước tiên
rockyou-30000.rule30,000 rules mạnh, coverage rộng
dive.ruleRule lớn nhất, toàn diện nhất
d3ad0ne.ruleRule phổ biến trong cộng đồng
leetspeak.ruleBiến thể leet: a→@, e→3, o→0,…
toggles5.ruleToggle hoa/thường các ký tự

Quy trình thực tế: Thử wordlist thuần → nếu fail → thêm best64.rule → nếu fail → thử rockyou-30000.rule hoặc dive.rule.

Viết Custom Rule

FunctionTác dụngVí dụ với password
:Giữ nguyênpassword
cViết hoa chữ đầuPassword
uUppercase toàn bộPASSWORD
lLowercase toàn bộpassword
so0Thay o0passw0rd
sa@Thay a@p@ssword
$!Thêm ! vào cuốipassword!

Cú pháp kết hợp: Nhiều function trên cùng một dòng = áp dụng đồng thời. Ví dụ: c so0 sa@ $!P@ssw0rd!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat custom.rule
:             # password
c             # Password
so0           # passw0rd
c so0         # Passw0rd
sa@           # p@ssword
c sa@         # P@ssword
c sa@ so0     # P@ssw0rd
$!            # password!
$! c          # Password!
$! so0        # passw0rd!
$! sa@        # p@ssword!
$! c so0      # Passw0rd!
$! c sa@      # P@ssword!
$! so0 sa@    # p@ssw0rd!
$! c so0 sa@  # P@ssw0rd!

OSINT → Custom Wordlist: Thu thập thông tin nạn nhân → tạo wordlist gốc → áp rule → xác suất trúng cao hơn rockyou.txt rất nhiều.


Attack Mode 3 — Mask Attack

1
2
hashcat -a 3 -m 0 1e293d6912d074c0fd15844d803400dd '?u?l?l?l?l?d?s'
hashcat -a 3 -m 0 <hash> -1 ?l?d '?1?1?1?1?1?1?1?1'
SymbolCharset
?labcdefghijklmnopqrstuvwxyz
?uABCDEFGHIJKLMNOPQRSTUVWXYZ
?d0123456789
?h0123456789abcdef
?H0123456789ABCDEF
?s!"#$%&'()*+,-./:;<=>?@[]^_
?a?l?u?d?s (tất cả printable)
?b0x00 - 0xff (toàn bộ byte)

Khi nào dùng Mask Attack? Khi biết pattern của mật khẩu: độ dài, loại ký tự, format cố định (VD: Company2024!). Custom charset: dùng -1, -2, -3, -4 để định nghĩa bộ ký tự riêng, tham chiếu bằng ?1, ?2, ?3, ?4.


John the Ripper — Full Reference

Cracking Modes

1
2
3
4
5
6
7
john --single passwd
john --wordlist=rockyou.txt hash.txt
john --wordlist=rockyou.txt --rules hash.txt
john --incremental hash.txt
john --format=raw-md5 hash.txt
john --format=nt hash.txt
john hash.txt --show
ModeGiải thíchDùng khi
--singleSinh candidate từ username, homedir, GECOSTarget Linux, có file passwd
--wordlistDictionary attackCó wordlist sẵn
--rulesBiến thể wordlistKết hợp với --wordlist
--incrementalBrute-force thông minh (Markov chains)Không có wordlist
--formatChỉ định loại hashJtR không tự nhận diện đúng
--showHiển thị passwords đã crack từ john.potSau khi crack xong

Incremental Mode rất tốn tài nguyên — nên tùy chỉnh bộ ký tự và độ dài trong john.conf để tối ưu.


*2john Converters

1
2
3
4
5
6
7
8
9
10
11
12
python3 ssh2john.py SSH.private > ssh.hash
office2john.py Protected.docx > protected-docx.hash
pdf2john.pl PDF.pdf > pdf.hash
zip2john ZIP.zip > zip.hash
rar2john archive.rar > rar.hash
bitlocker2john -i Backup.vhd > backup.hashes
keepass2john Database.kdbx > keepass.hash
gpg2john private.key > gpg.hash
wpa2john capture.pcap > wpa.hash

john --wordlist=rockyou.txt ssh.hash
john ssh.hash --show
ToolDùng cho
ssh2johnSSH private key
office2johnMS Office có mật khẩu
pdf2johnPDF có mật khẩu
zip2johnZIP có mật khẩu
rar2johnRAR có mật khẩu
keepass2johnKeePass database
bitlocker2johnỔ đĩa BitLocker
gpg2johnFile GPG được mã hóa
wpa2johnWiFi WPA/WPA2 handshake

Quy trình chuẩn với John: *2john → tạo .hashjohn --wordlistjohn --show


Hash Format phổ biến với --format

FormatMô tả
raw-md5Raw MD5
raw-sha1Raw SHA1
raw-sha256Raw SHA256
raw-sha512Raw SHA512
ntWindows NTLM
sha512cryptLinux $6$
md5cryptLinux $1$
zipZIP archive
rarRAR archive
pdfPDF document
sshSSH private key
krb5Kerberos 5

AES Brute Force

1
2
3
4
5
file GZIP.gzip

for i in $(cat rockyou.txt); do
  openssl enc -aes-256-cbc -d -in GZIP.gzip -k $i 2>/dev/null | tar xz
done
OptionGiải thích
enc -aes-256-cbcDùng thuật toán AES-256 CBC mode
-dDecrypt mode
-k $iPassword/Key — thử từng từ trong rockyou.txt
tar xzGiải nén output nếu decrypt thành công

Sẽ thấy nhiều dòng gzip: stdin: not in gzip format — bỏ qua, đây là lỗi khi sai password.


Mount BitLocker trên Linux — dislocker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
sudo apt-get install dislocker
sudo mkdir -p /media/bitlocker
sudo mkdir -p /media/bitlockermount

# Crack hash
bitlocker2john -i Backup.vhd > backup.hashes
grep "bitlocker\$0" backup.hashes > backup.hash
hashcat -a 0 -m 22100 backup.hash /usr/share/wordlists/rockyou.txt

# Kiểm tra partition
sudo losetup -f -P Backup.vhd
lsblk | grep loop

# Mount
sudo dislocker /dev/loop0p1 -u<password> -- /media/bitlocker
sudo mount -o loop /media/bitlocker/dislocker-file /media/bitlockermount

cd /media/bitlockermount && ls -la

# Unmount
sudo umount /media/bitlockermount
sudo umount /media/bitlocker
LệnhGiải thích
bitlocker2john -iExtract 4 loại hash từ VHD
grep "bitlocker\$0"Lọc chỉ lấy password hash
-m 22100Hashcat mode cho BitLocker
losetup -f -PGắn VHD thành loop device
-u<password>Password đã crack
mount -o loopMount dislocker-file như ổ đĩa thường

4 loại hash của BitLocker: $bitlocker$0$$bitlocker$1$ → Password hash → crack được. $bitlocker$2$$bitlocker$3$ → Recovery key → không thực tế để crack.

BitLocker crack rất chậm — ~25 H/s ngay cả trên CPU tốt. Cần GPU hoặc thời gian dài.


Pivoting

Luồng tấn công: Attacker → [SSH SOCKS Proxy :9050] → DMZ Host → Internal Network

1
2
3
4
ssh -D 9050 user@<DMZ01>
sudo vim /etc/proxychains.conf        # thêm: socks4 127.0.0.1 9050
sudo proxychains -q nmap -sT -Pn 172.16.119.13 --open
proxychains xfreerdp /v:<ip> /u:htb-student /p:HTB_@cademy_stdnt!
OptionGiải thích
ssh -D 9050Dynamic port forwarding — tạo SOCKS proxy trên localhost:9050
proxychains -q-q = Quiet — tắt verbose output
nmap -sTTCP Connect scan — bắt buộc dùng với proxy
nmap -PnSkip ping — firewall thường block ICMP
nmap --openChỉ hiển thị port đang mở

ProxyChains config /etc/proxychains.conf:

1
2
[ProxyList]
socks4  127.0.0.1  9050
This post is licensed under CC BY 4.0 by the author.