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

相关推荐
mqcode9 分钟前
Vue3 + Element Plus + Vite 企业级后台框架搭建全流程
前端
SL-staff10 分钟前
Web 白板技术架构深度解析:从渲染到协作的选型哲学
前端·架构
微扬嘴角13 分钟前
react篇4--setState、LazyLoad和Hooks
前端·javascript·react.js
杨梦馨25 分钟前
万级数据表格卡死?Web Worker 一招搞定
前端·javascript·vue.js
阿明在折腾25 分钟前
从Canvas到AI模型:我在线工具站里的图片处理实战
前端·后端
CainChen28 分钟前
Chrome 远程调试 Android 卡在 Pending authentication 的解决办法
前端
杨运交28 分钟前
[030][Web模块]Spring Boot 验证与 OpenAPI 集成实战:从校验规则到文档生成
前端·spring boot·python
天le41 分钟前
基于cocos3.x复刻《猪了个猪》挪了个船:位置生成实现
前端
青木_JS41 分钟前
qiankun 子应用重开后仍显示旧数据?问题出在模块顶层的 useStore()
前端
货拉拉技术43 分钟前
面向 Agent Skill 的 CLI/SSO 鉴权体系:安全、无感、可追溯
前端·agent