/etc/passwd及/etc/shadow

在写 UNIX Password Cracker之前我们首先要了解UNIX系统是如何保存用户密码的。
/etc/passwd内容如下:

/etc/shadow内容如下(密码域结构:$指示加密方式$干扰串$密码hash值):

etc/passwd、/etc/shadow文件权限如下:

各域解释如下:

(仅上图转载自https://blog.csdn.net/zhuoya_/article/details/77418413)
为此可以看出**/etc/passwd文件所有用户都可以读,而/etc/shadow仅有rootshadow**组用户可以读。

UNIX Password Cracker

UNIX Password Cracker实现思路:

  • 拿到**/etc/shadow**文件然后提取其中的密码域
  • 分析密码域的结构确定salt(即hash算法干扰串
  • 逐条计算字典中的条目的hash值并与密码域的hash值进行比对
比如:
>>> import crypt
>>> dir(crypt)
['__doc__', '__file__', '__name__', '__package__', 'crypt']
>>> crypt.crypt('root','$6$.XjiYlU6$')
'$6$.XjiYlU6$X7ux./bZdhR9.iVRy8UE10Wlk4oD3TxQsw6QymbsNTfreg/2n1Fhj3Ug1qqc.Wkp7/Gb7YcIyotOKYunJhbMV/'
  • 如果相同则对应的密码字典中的词既是密码

完整代码如下:

import crypt
import re
r = re.compile('(\$\d\$.*\$)')
def testPass(cryptPass):if cryptPass:print "[+] No Password" return salt = r.findall(cryptPass)if not salt:print '[-] Password Has Expired or Been Locked'return dictFile = open('dictionary.txt','r')for word in dictFile.readlines():word = word.strip('\n')cryptWord = crypt.crypt(word,salt[0])if (cryptWord == cryptPass):print "[+] Found Password: "+word+"\n"returnprint "[-] Password Not Found.\n"return
def main():passFile = open('passwords.txt')for line in passFile.readlines():if ":" in line:user = line.split(':')[0]cryptPass = line.split(':')[1].strip(' ')print "[*] Cracking Password For: "+usertestPass(cryptPass)
if __name__ == "__main__":main()

Zipfile Password Cracker

关键点zipfile.ZipFile类实例化后的extactall方法在提取文件内容时通过pwd参数可以指定密码。
Zipfile Password Cracker实现思路:

  • 使用文件名初始化zipfile.ZipFile得到zFile
  • 调用zFile的extracall方法并指定pwd参数
  • 出现异常则可判断密码不正确
  • 否则密码正确

完整代码如下:

import zipfile
import optparse
from threading import Thread
def extractFile(zFile, password):try:zFile.extractall(pwd=password)print '[+] Found password ' + password + '\n'except:pass
def main():parser = optparse.OptionParser("usage%prog "+\"-f <zipfile> -d <dictionary>")parser.add_option('-f', dest='zname', type='string',\help='specify zip file')parser.add_option('-d', dest='dname', type='string',\help='specify dictionary file')(options, args) = parser.parse_args()if (options.zname == None) | (options.dname == None):print parser.usageexit(0)else:zname = options.znamedname = options.dnamezFile = zipfile.ZipFile(zname)passFile = open(dname)
for line in passFile.readlines():password = line.strip('\n')t = Thread(target=extractFile, args=(zFile, password))t.start()
if __name__ == '__main__':main()

在上述代码中optparse模块已经过期,推荐使用argparse模块,其次是没必要对每一条密码记录开启一个线程,使一个线程处理多条字典密码。改进后代码如下。

import zipfile
import argparse
import sys
import  threading
import Queue
word_list = Queue.Queue()
flag = threading.Event()
def extractFile(zFile):while not (word_list.empty() or flag.is_set()):try:zFile.extractall(pwd=word_list.get())print '[+] Found password ' + password + '\n'flag.set()except:pass
def main():parser = argparse.ArgumentParser(prog=sys.argv[0], usage="-f <zipfile> -d <dictionary>")parser.add_argument('-f', dest='zname', action='store',help='specify zip file')parser.add_argument('-d', dest='dname', action='store',help='specify dictionary file')options = parser.parse_args()if (options.zname == None) | (options.dname == None):print parser.usageexit(0)zname = options.znamedname = options.dnamezFile = zipfile.ZipFile(zname)passFile = open(dname)for line in passFile.readlines():word_list.put(line.strip('\n'))for i in range(20):t = threading.Thread(target=extractFile, args=(zFile,))t.start()
if __name__ == '__main__':main()

Violent python - UNIX Password CrackerZipfile Password Cracker相关推荐

  1. Python+UNIX和Linux系统管理指南

    收藏自用 链接:Python+UNIX和Linux系统管理指南

  2. Ubuntu Linux root password - default password

    Q. I have just installed Ubuntu Linux. But, what is the default root password? I can only login as a ...

  3. python unix时间戳格式化输出_python正常时间和unix时间戳相互转换的方法

    本文实例讲述了python正常时间和unix时间戳相互转换的方法.分享给大家供大家参考.具体分析如下: 这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来, 例如:133 ...

  4. python unix时间戳转换成时间_关于python:将unix时间戳字符串转换为可读日期

    我有一个用python表示unix时间戳(即"1284101485")的字符串,我想把它转换成一个可读的日期.当我使用time.strftime时,我得到一个TypeError: ...

  5. html密码域的type属性,查看网页黑点密码 将type=password中password修改成为text

    将type="password"中的password修改成为text修改完成后点击回车 查看网页黑点密码,这个功能很好用哦 用了这招,将小黑点变成直接显示密码!忘记密码也能立刻想起 ...

  6. python unix时间戳_Python 获得13位unix时间戳的方法

    在python 开发web程序时,需要调用第三方的相关接口,在调用时,需要对请求进行签名.需要用到unix时间戳. 在python里,在网上介绍的很多方法,得到的时间戳是10位.而java里默认是13 ...

  7. python unix时间戳与正常时间转化

    有时候业务需要,需要把正常的时间格式与unix时间戳格式进行转换. 在python中转化方式如下,直接利用time中的函数: #! /usr/bin/env python #coding:utf-8i ...

  8. python unix 时间戳转北京时间,python时间与Unix时间戳相互转换方法详解

    对于时间数据,如2018-09-25 09:28:59,有时需要与Unix时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块,具体的函数如下: 其中uni ...

  9. python unix 时间戳转北京时间,python正常时间和unix时间戳相互转换的方法

    # -*- coding: utf-8 -*- import time def timestamp_datetime(value): format = '%Y-%m-%d %H:%M:%S' # va ...

  10. python unix时间戳_Python怎样获得13位unix时间戳

    python datetime和unix时间戳之间相互转换 1.代码: import time import datetime # 1.datetime转unix时间戳 # (1).逐个打印 n = ...

最新文章

  1. BZOJ 2131 免费的馅饼(DP,二维偏序问题 / 旋转坐标轴转化问题)【BZOJ 修复工程】
  2. Nginx 使用中文URL,中文目录路径
  3. Kubernetes 在宜信落地实践
  4. 003Java语言环境搭建
  5. mysql 唯一索引 死锁_MySQL 死锁套路:唯一索引 S 锁与 X 锁的爱恨情仇
  6. jsx怎么往js里传参数_在vue中使用jsx语法的使用方法
  7. 死锁产生的原因及条件、如何避免死锁
  8. 单片机串口通信学号显示_触摸屏与单片机串口通信测试
  9. MySQL_日期时间处理函数及应用
  10. webpack-loader(加载器)
  11. JMETER 分布式踩过的坑及填坑方法
  12. java geoprocessor_ArcGIS GeoEvent Processor for Server 安裝與配置 (僅適用於壓縮安裝包)...
  13. momentum、Adagrad、RMSProp、Adam梯度下降总结
  14. php之获取ip(网站地址)
  15. js前端生成excel文件(表格)并下载
  16. 有一种记录叫“时光轴”!
  17. 抖音电商难做吗?为什么又累又卷还是做不好?
  18. 微信小程序设置横竖屏
  19. 第一组 beta冲刺(2/3)
  20. 学习笔记1—元胞自动机(CA)模型①

热门文章

  1. (转)一些jbx的配置
  2. 浅述Docker的容器编排
  3. 微信公众号发送红包(源码)
  4. BIOS与UEFI以及模拟环境
  5. Polygon与以太坊通信机制研究
  6. SHON WEBB:坚持做这四件事,会让你的自律达到新的高度
  7. android botton控件基本属性
  8. 个人公众号,用于开发经验分享
  9. 笑傲江湖 琴箫合奏之曲
  10. 文献翻译——YOLO9000:Better,Faster,Stronger(YOLOv2)