爆破shadow文件密码脚本(完成版)

在之前的博客Python爆破shadow文件密码脚本(简化版)中我们做了简化版的爆破shadow文件密码的python脚本,接下来在之前代码的基础上改进:

python 复制代码
import crypt
shadow_line="root:$y$j9T$uEgezfJhn7Ov5naU8bzZt.$9qIqkWYObaXajS5iLDA43uFhdrtt4ZfbmiZjkZFYve2:18711:0:99999:7:::"
print(f"[+] The shadow line is {shadow_line}")

crypt_text=shadow_line.split(":")[1]
print(f"[+] The crypt text is {crypt_text}")

salt=crypt_text[0:crypt_text.rindex("$")]
print(f"[+] The salt is {salt}")

password="root"
new_crypt_text=crypt.crypt(password,salt)

if new_crypt_text == crypt_text:
	print(f"[+] password is {password}"")
else:
	print(f"[+] password not found!")

在kali中找到一个密码字典,查看它的绝对路径复制:

将代码中的password="123456"替换成下面代码

line.strip()函数首尾去空格

print(f"Trying password:")显示爆破的密码和过程

复制代码
flie_path="/home/kali/tools/wordlists/top_password.txt"
wirh open(file=file_path,mode="r") as f:
	for line in f:
		password = line.strip()
		print(f"Trying password:{password}")

由于添加了一个for循环,再稍作修改,让password not found!在for循环结束后输出,并给密码加上绿色醒目:

python 复制代码
from termcolor import colored
import crypt

shadow_line="root:$y$j9T$uEgezfJhn7Ov5naU8bzZt.$9qIqkWYObaXajS5iLDA43uFhdrtt4ZfbmiZjkZFYve2:18711:0:99999:7:::"
print(f"[+] The shadow line is {shadow_line}")

crypt_text=shadow_line.split(":")[1]
print(f"[+] The crypt text is {crypt_text}")

salt=crypt_text[0:crypt_text.rindex("$")]
print(f"[+] The salt is {salt}")

flie_path="/home/kali/tools/wordlists/top_password.txt"
with open(file=flie_path,mode="r") as f:
	for line in f:
		password = line.strip()
		print(f"\r[-] Trying password:{password}")
		
		new_crypt_text=crypt.crypt(password,salt)

		if new_crypt_text == crypt_text:
			print(colored(f"\n[+]password is {password}","green"))
			exit()

	print(f"[+] password not found!")

如图,爆破出密码为root:

相关推荐
htzyl20626 分钟前
前端样式-弹窗淡入淡出,为什么你的 `transition` 一直不生效
前端·css·html
Brookty34 分钟前
CSS基础知识(二):盒模型、内外边距、外边距折叠与父子元素的布局关系
前端·css
十有八七35 分钟前
手搓 Agent(四):长点记性——上下文满了怎么办,怎么记住上一次
前端·人工智能·后端
叫个啥呢2 小时前
第一次写 DSH 插件:跟着自己的喜好实现个简单的代码管理插件
前端
掘金酱2 小时前
AI 带来的新生意|稀土掘金 X-Lab 年度大会招募开启
前端·后端·vibecoding
某哈压力大2 小时前
移动端 rem 适配
前端·vue.js·面试
泯泷2 小时前
Vercel AI SDK 6 完整教程系列 - 第一部分:基础入门篇
前端·javascript
lcy_243 小时前
10 万条数据滚动不卡?聊聊我写的虚拟列表组件 vue-virtualize
前端
zhanlang02173 小时前
HTML 零基础入门到企业实战【第七章 7.5】表单验证基础属性:required、maxlength、placeholder
前端·html