爆破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:

相关推荐
kyriewen6 小时前
面试官问我:AI 都能写代码了,前端凭什么还值 25K
前端·javascript·人工智能
风骏时光牛马7 小时前
AI源码分析:拆解模型底层实现逻辑
前端
IT_陈寒7 小时前
React子组件莫名其妙重渲染?你可能漏了这个Hook
前端·人工智能·后端
乘风gg7 小时前
DeepSeek V4.1 Flash 来了,明天中午 Flash 降价 60%
前端·ai编程·claude
默_笙8 小时前
❗ 给金鱼装记忆(上):从白板到笔记本,AI 的短期记忆生存指南
前端·javascript
酷酷的逗逗乐8 小时前
前端转 Agent 开发 · 第五节:Memory 会话记忆
前端·程序员
掘金挖土8 小时前
前端手摸手跑路之 AI 应用开发(二)
前端·后端
mayaairi8 小时前
Vue2 组件通讯(四):v-model、scoped样式、mixins与plugins
前端·javascript·vue.js
梦曦i9 小时前
@meng-xi/uni-router 未来展望:夯实基础、深化体验、探索前沿
前端·uni-app
Yeyu9 小时前
AAOS AppCard 实践:怎么把自己的 App 塞进别人的卡片里
前端