#!/usr/bin/env#Coding=utf-8ImportZipFileImportThreadingImportOSImportSYSclassCrackzip:def __init__(self): Self._result=NonedefRun (Self,zfile,password):Try: Zfile.extractall (pwd=password)Print("Found Passwd:", password)Print('password=', password) self._result=Passwordexcept: Pass defGetpass (self):returnSelf._resultdefcheckfile (PATH): Flag=Falseif notos.path.isfile (PATH): Flag=FalsePrint('[-]%s file does not exist', Path)returnFlagdefMain (): CZ=Crackzip ()ifLen (SYS.ARGV) >=3: Zippath=sys.argv[1] Dictionarypath=sys.argv[2] Flag= (len (sys.argv) >3 andsys.argv[3]=='- T') TypeName=Noneif notcheckfile (dictionarypath):ifdictionarypath[-3:]!='txt': Print('dictionary is not a txt file') return if notcheckfile (zippath):ifzippath[-3:]!='Zip': Print('can only blast zip files') returnZfile=zipfile. ZipFile ('Test.zip','R') Passfile=open (Dictionarypath,'R') forLineinchpassfile.readlines (): Password=line.strip ('\ n'). Encode ('Utf-8') ifFlag:false T=threading. Thread (target=cz.run,args=(Zfile,password)) T.start ()Else: Cz.run (zfile,password) password=Cz.getpass () typeName='Singlethread' ifPassword:return iftypename=='Singlethread': Print("I can't find the password in the dictionary.") Else: Print('the command is not correct in the format: Python zip.py zippath dictionarypath') returnif __name__=='__main__': Main ()
The following issues were encountered:
1. The characters obtained in the dictionary need to be encoded (UTF-8) to be recognized by Extractall
2. How do I detect all threads after the thread burst is turned on? (indicates that the blasting failed)
Python zip file password blasting