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

相关推荐
码农秋6 分钟前
Element Plus DatePicker 日期少一天问题:时区解析陷阱与解决方案
前端·vue.js·elementui·dayjs
未来之窗软件服务10 分钟前
未来之窗昭和仙君(五十六)页面_预览模式——东方仙盟筑基期
前端·仙盟创梦ide·东方仙盟·昭和仙君·东方仙盟架构
top_designer12 分钟前
Illustrato:钢笔工具“退休”了?Text to Vector 零基础矢量生成流
前端·ui·aigc·交互·ux·设计师·平面设计
星哥说事17 分钟前
星哥带你玩飞牛NAS-13:自动追番、订阅下载 + 刮削,动漫党彻底解放双手!
前端
donecoding25 分钟前
前端AI开发:为什么选择SSE,它与分块传输编码有何不同?axios能处理SSE吗?
前端·人工智能
安_30 分钟前
<style scoped>跟<style>有什么区别
前端·vue
姝然_952731 分钟前
Claude Code 命令完整文档
前端
wjcroom31 分钟前
web版进销存的设计到实现一
前端
无知的前端35 分钟前
Flutter常见问题以及解决方案
前端·flutter·dart
BD_Marathon1 小时前
Vue3_Vite构建工程化前端项目
前端