Pentest Toolkit - Hydra
Hydra(全名:THC-Hydra)是一款強大的密碼破解工具,主要用於執行暴力破解(Brute-force attack)和字典攻擊(Dictionary attack),來測試系統或應用程式的登入憑證安全性。 這款工具由 The Hacker’s Choice(THC) 團隊開發,支援多種協議和服務,廣泛用於滲透測試和資訊安全研究。
Hydra 的特點
- 支援多種協議:可針對 SSH、FTP、HTTP、SMB、RDP、Telnet、MySQL、PostgreSQL、SMTP、SNMP 等多種網路協議進行測試。
- 高效能:支援多執行緒,可以同時進行多個測試,提高破解速度。
- 彈性字典 攻擊:允許使用者自訂字典,並支援組合不同的帳號與密碼字典來進行測試。
- 圖形化介面(Hydra-GTK):除了命令列版本外,也有圖形化介面(雖然較少使用)。
- 跨平台支援:可以在 Linux、Windows(透過 WSL)、macOS 等環境下運行。
Hydra 的使用範例
Hydra 主要透過命令列運行,基本語法如下:
hydra -l <使用者名稱> -P <密碼字典> <目標IP> <服務協議>
範例 1:破解 SSH 登入
hydra -l root -P passwords.txt 192.168.1.100 ssh
這條指令會使用 passwords.txt
內的密碼,嘗試以 root
身份登入 192.168.1.100
的 SSH 服務。
範例 2:破解 FTP 登入
hydra -L users.txt -P passwords.txt ftp://192.168.1.100
這條指令會嘗試使用 users.txt
和 passwords.txt
內的帳密組合,登入目標 FTP 伺服器。
合法用途與風險
Hydra 本質上是一款滲透測試工具,安全研究人員可以用它來測試系統的防禦能力,找出弱密碼並加強保護。然而,未經授權使用 Hydra 來攻擊他人系統是違法的,可能觸犯資訊安全相關法律。
如何防範 Hydra 攻擊?
- 使用強密碼(長度 12 位以上,包含大小寫、數字與特殊符號)。
- 限制登入嘗試次數,啟用帳戶鎖定機制。
- 使用多因素認證(MFA),增加額外的身份驗證層。
- 監控登入紀錄,偵測異常的嘗試行為。
- 更改預設端口(例如將 SSH 由 22 改為其他非標準端口)。
透過 WSL 執行 Hydra
安裝 Hydra
- 首先在 windows 上運行 WSL,我們使用的是 Ubuntu 22.04 的版本。
wsl -d Ubuntu
---
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.153.1-microsoft-standard-WSL2 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
This message is shown once a day. To disable it please create the
/home/calvin/.hushlogin file.
- 可以使用 apt 的方式安裝,也可以使用 github 的方式安裝,如果使用 apt 執行完下面就結束了,我們這邊使用 github 來安裝最新的。
# 透過apt的方式安裝
sudo apt install hydra-gtk
# 透過github安裝原始碼
git clone https://github.com/vanhauser-thc/thc-hydra.git
---
Cloning into 'thc-hydra'...
remote: Enumerating objects: 3644, done.
remote: Counting objects: 100% (1382/1382), done.
remote: Compressing objects: 100% (185/185), done.
remote: Total 3644 (delta 1264), reused 1213 (delta 1195), pack-reused 2262 (from 2)
Receiving objects: 100% (3644/3644), 3.40 MiB | 3.67 MiB/s, done.
Resolving deltas: 100% (2464/2464), done.
- 進入 thc-hydra 中以後,執行 configure 來進行安裝檔設定。
cd thc-hydra/
./configure
---
Starting hydra auto configuration ...
...中間省略...
Writing Makefile.in ...
now type "make"
- 在 make 前,我們需要先安裝編譯所需要的套件。
sydo apt-get update
sudo apt-get install -y libssl-dev libssh-dev libidn11-dev libpcre3-dev libgtk2.0-dev libmysqlclient-dev libpq-dev libsvn-dev firebird-dev libncurses5-dev desktop-file-utils
- 安裝完畢之後,就可以進行 make 編譯了。
make
- 接下來就可以進行安裝,之後就可以透過指令來運行他。
sudo make install
---
Now type make install
strip hydra pw-inspector
echo OK > /dev/null && test -x xhydra && strip xhydra || echo OK > /dev/null
mkdir -p /usr/local/bin
cp -f hydra-wizard.sh hydra pw-inspector /usr/local/bin && cd /usr/local/bin && chmod 755 hydra-wizard.sh hydra pw-inspector
echo OK > /dev/null && test -x xhydra && cp xhydra /usr/local/bin && cd /usr/local/bin && chmod 755 xhydra || echo OK > /dev/null
sed -e "s|^INSTALLDIR=.*|INSTALLDIR="/usr/local"|" dpl4hydra.sh | sed -e "s|^LOCATION=.*|LOCATION="/etc"|" > /usr/local/bin/dpl4hydra.sh
chmod 755 /usr/local/bin/dpl4hydra.sh
mkdir -p /usr/local/etc
cp -f *.csv /usr/local/etc
mkdir -p /usr/local/man/man1/
cp -f hydra.1 xhydra.1 pw-inspector.1 /usr/local/man/man1/
mkdir -p /usr/local/share/pixmaps
cp -f xhydra.png /usr/local/share/pixmaps/
mkdir -p /usr/local/share/applications
desktop-file-install --dir /usr/local/share/applications xhydra.desktop
執行 Hydra
- 測試 hydra 是否安裝成功。
hydra -help
---
Hydra v9.6dev (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
...後面省略...
- 使用 hydra 對一個本機登入的表單在
http://127.0.0.1:8080/login
進行登入測試,輸入不斷輸入 password 來暴力破解。
hydra -l admin -P rockyou.txt 127.0.0.1 -s 8080 http-get "/login?username=^USER^&password=^PASS^"
Hydra v9.6dev (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-02-12 21:44:05
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344398 login tries (l:1/p:14344398), ~896525 tries per task
[DATA] attacking http-get://127.0.0.1:8080/login?username=^USER^&password=^PASS^
[STATUS] 9361.00 tries/min, 9361 tries in 00:01h, 14335037 to do in 25:32h, 16 active
密碼字典
RockYou.txt 是什麼?
rockyou.txt
是歷史上最知名的密碼字典之一,它包含 超過 1,430 萬個真實使用者的密碼,主要來自 2009 年 RockYou.com 遭駭客攻擊後洩漏的密碼資料庫。這份字典被廣泛用於密碼分析、滲透測試、密碼強度研究,也是各種暴力破解工具(如 Hydra、John the Ripper、Hashcat)的標準密碼字典之一。
RockYou 密碼洩漏事件
- 時間:2009 年
- 來源:RockYou.com(社交遊戲與應用程式公司)
- 原 因:網站未加密存儲使用者密碼,導致駭客成功入侵並取得完整的明文密碼檔案。
- 影響:超過 3,200 萬筆使用者帳號密碼被洩漏,其中 1,430 萬筆整理為
rockyou.txt
。
RockYou.txt 內容
這份字典只包含密碼,不含使用者名稱,每一行代表一個密碼,例如:
123456
password
12345678
qwerty
abc123
letmein
monkey
RockYou.txt 下載與存放位置
RockYou 可以從這裡下載:🔗https://github.com/danielmiessler/SecLists
wget https://github.com/danielmiessler/SecLists/raw/master/Passwords/Leaked-Databases/rockyou.txt.tar.gz
tar -xvzf rockyou.txt.tar.gz
rm -rf rockyou.txt.tar.gz
使用 RockYou.txt 進行滲透測試
以下是一些使用 rockyou.txt
進行測試的範例 (請確保在合法範圍內使用!)
使用 Hydra 嘗試 SSH 破解
hydra -l root -P /usr/share/wordlists/rockyou.txt 192.168.1.100 ssh
使用 John the Ripper 破解雜湊
john --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt
使用 Hashcat 破解密碼雜湊
hashcat -m 0 -a 0 hashes.txt /usr/share/wordlists/rockyou.txt