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中
image.png

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


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 <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 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()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • python学习笔记 声明:学习笔记主要是根据廖雪峰官方网站python学习学习的,另外根据自己平时的积累进行修正...
    renyangfar阅读 8,287评论 0 10
  • 第1章 小试牛刀 $ 是普通用户,# 表示管理员用户 root。 shebang:#!。sharp / hash ...
    巴喬書摘阅读 11,572评论 1 4
  • Check dependencies[BCEROR]** Your App ** has conflicting ...
    zhangyin阅读 9,996评论 0 50
  • 风清从后面追上来,晟涵看着他有点发呆,云扬倒是反应很快,转身拉着晟涵就朝前猛走。晟涵被拉的一个趔趄,“唉,云扬,风...
    JKLmilly阅读 3,414评论 12 23
  • 恍惚间还记得那个秋天,台阶充当红娘,让下楼的你遇到上楼的我,你在上,我看了你的脸,你在下,留给我一个相思的背影,我...
    离酒歌阅读 4,863评论 3 2

友情链接更多精彩内容