python绝技:黑客篇-第一章

本书第一章主要介绍了python的基础知识,包括变量、数据类型、函数、迭代、判断语句、语句块、异常处理及常用模块的介绍。介绍了第三方库的安装方式,并在最后使用两个案例实现了密码暴力破解的功能,由于python笔者已经较为熟悉,此处不再赘述python的基础知识了。


python第三方模块的安装方法总结:

1. 源代码安装

  1. 下载源代码安装包,使用wget工具直接从网络下载对应的数据包
    wget http://XXXXXXXXXXX/XXX/XX/XX.tar.gz
  2. 使用tar命令解压缩
    tar -xzf xxx.tar.gz
    cd xxx
  3. 利用python setup.py install 在解压缩的目录下完成安装
    python setup.py install

2. pip安装

  pip install xxx

3. easy_install安装

 easy_install xxx

4. 使用pycharm安装

 在pycharm setting中
python绝技:黑客篇-第一章_第1张图片
image.png

点击+号,在弹出窗口中搜索需要的包


python绝技:黑客篇-第一章_第2张图片
image.png

点击install package完成安装即可

unix口令破解器

  1. crypt加密版
    需要导入crypt包,然后使用crypt.crypt(word,salt)将字典中的明文密码加密,salt是加盐后的密码前两位,word为字典中的密码,cryptPass为待破的密码.

def checkPassCrypt(cryptPass):
salt = cryptPass[0:2]
dictFile = open('dictionary.txt', 'r')
for word in dictFile.readlines():
word = word.strip("\n")
cryptWord = crypt.crypt(word, salt)
if cryptWord == cryptPass:
print("[+] Found Password : %s \n" % (word))
return
print("[-] Password Not Found.\n")
return
```

  1. sha-512加密版
    sha512或者其他sha256等hash加密的均可以使用python的hashlib
    将字典的密码使用sha512加密然后与原加密的hash比对进行破解
    hashlib.sha512(passwrod).hexdigest()
def chechPassSHA512(cryptPass):
    dictFile = open('dictionary.txt', 'r')
    for word in dictFile.readlines():
        word = word.strip("\n")
        cryptWord = hashlib.sha512(word).hexdigest()
        if cryptWord == cryptPass:
            print("[+] Found Password : %s \n" % (word))
            return
    print("[-] Password Not Found.\n")
    return

zip文件口令破解机

主要使用zipfile库,使用ZipFile类中的extratall()完成指定密码后的zipfile文件解压,解压路径是当前路径,也可以使用path进行路径指定
还用到了optparser库进行命令行参数的解析
用到threading进行多线程操作

import zipfile
from threading import Thread
import optparse


def extractZipFile(zFile, password):
    try:
        zFile.extractall(pwd=password)
        print('[+] Found Password:%s\n' % (password))
    except:
        pass


def main():
    parser = optparse.OptionParser("usage%prog -f  -d ")
    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 or options.dname == None:
        print(parser.usage)
        exit(0)
    else:
        zname = options.zname
        dname = options.dname
    zFile = zipfile.ZipFile(zname)
    passFile = open(dname)
    for line in passFile.readlines():
        password = line.strip('\n')
        t = Thread(target=extractZipFile, args=(zFile, password))
        t.start()


if __name__ == '__main__':
    main()

你可能感兴趣的:(python绝技:黑客篇-第一章)