python絕技:黑客篇-第一章

本書第一章主要介紹了python的基礎(chǔ)知識(shí),包括變量、數(shù)據(jù)類型、函數(shù)、迭代、判斷語句、語句塊、異常處理及常用模塊的介紹。介紹了第三方庫的安裝方式,并在最后使用兩個(gè)案例實(shí)現(xiàn)了密碼暴力破解的功能,由于python筆者已經(jīng)較為熟悉,此處不再贅述python的基礎(chǔ)知識(shí)了。


python第三方模塊的安裝方法總結(jié):

1. 源代碼安裝

  1. 下載源代碼安裝包,使用wget工具直接從網(wǎng)絡(luò)下載對(duì)應(yīng)的數(shù)據(jù)包
    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

點(diǎn)擊+號(hào),在彈出窗口中搜索需要的包


image.png

點(diǎn)擊install package完成安裝即可

unix口令破解器

  1. crypt加密版
    需要導(dǎo)入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比對(duì)進(jìn)行破解
    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文件口令破解機(jī)

主要使用zipfile庫,使用ZipFile類中的extratall()完成指定密碼后的zipfile文件解壓,解壓路徑是當(dāng)前路徑,也可以使用path進(jìn)行路徑指定
還用到了optparser庫進(jìn)行命令行參數(shù)的解析
用到threading進(jìn)行多線程操作

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • python學(xué)習(xí)筆記 聲明:學(xué)習(xí)筆記主要是根據(jù)廖雪峰官方網(wǎng)站python學(xué)習(xí)學(xué)習(xí)的,另外根據(jù)自己平時(shí)的積累進(jìn)行修正...
    renyangfar閱讀 3,252評(píng)論 0 10
  • 第1章 小試牛刀 $ 是普通用戶,# 表示管理員用戶 root。 shebang:#!。sharp / hash ...
    巴喬書摘閱讀 6,670評(píng)論 1 4
  • Check dependencies[BCEROR]** Your App ** has conflicting ...
    zhangyin閱讀 4,616評(píng)論 0 50
  • 風(fēng)清從后面追上來,晟涵看著他有點(diǎn)發(fā)呆,云揚(yáng)倒是反應(yīng)很快,轉(zhuǎn)身拉著晟涵就朝前猛走。晟涵被拉的一個(gè)趔趄,“唉,云揚(yáng),風(fēng)...
    JKLmilly閱讀 558評(píng)論 12 23
  • 恍惚間還記得那個(gè)秋天,臺(tái)階充當(dāng)紅娘,讓下樓的你遇到上樓的我,你在上,我看了你的臉,你在下,留給我一個(gè)相思的背影,我...
    離酒歌閱讀 1,270評(píng)論 3 2

友情鏈接更多精彩內(nèi)容