How to crack zip file passwords using pyzipcrack with crunch directly

Namaste Friends,




                                                      Friends,  Today's Tutorials Is About How to create Zip File Cracker Using Python Or You Can Says, How To Crack Zip File Password Through Brute Force using python.


So, let's discuss about topic with practical codes

here,

in this code,

i am creating a function,

that can test passwords on zip files.

and return true if password is correct.

let's see the codes


1
2
3
4
5
6
7
8
 def extracting_engine(self,file,pwd):
  try:
   file.extractall(output_path,pwd=str(pwd))
   print "Password Found"
                        return True
  except Exception as e:
                       pass
  return 


So,

now let's move a head

and

create a useful zipfile cracker that can work in high speed and

can also take password input directly from crunch.

Here, My Codes  pyzipcrack.py


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/python

# ---------------- READ ME ---------------------------------------------
# This Script is Created Only For Practise And Educational Purpose Only
# This Script Is Created For http://bitforestinfo.blogspot.in
# This Script is Written By
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.in/

    Note: We Feel Proud To Be Indian
######################################################
'''
# =================Other Configuration================ 
# Usages :
usage = "usage: %prog [options] "
# Version
Version="%prog 0.0.1"
# ====================================================
print __author__
 
# Import Modules
import zipfile,optparse,sys,fileinput,time

class main:
 def __init__(self):
  self.extract_input_data()
  self.check_input_conditions()
  self.start_cracking_engine()

 def time_management(self):
  print "[*] Starting Time ",self.starttime
  print "[*] Closing  Time ",self.closetime
  print "[*] Password Try  ",self.pwdtries
  print "[*] Average Speed ",self.pwdtries/(self.closetime-self.starttime)
  return

 def start_cracking_engine(self):
  print "[+] Loading Zipfile...  ",
  fileload=zipfile.ZipFile(self.filename)
  print "OK"
  if self.dictionery:
   print "[+] Using Dictonery Option.... OK"
   print "[+] Loading Dictonery File...  OK"
   print "[+] Brute Force Started ..."
   for i in fileinput.input(self.dictionery):
    pwd=i.strip('\n')
    self.extracting_engine(fileload,pwd)
  if self.crunch:
   print "[+] Connection Stablished as Pipe... OK"
   print "[+] Brute Force Started ..."
   for i in sys.stdin:
    pwd=i.strip('\n')
    self.extracting_engine(fileload,pwd)
  self.show_info_message()

  return

 def check_input_conditions(self):
  if not self.filename:
   print "[ Error ] Please Provide Zip File Path "
   sys.exit(0)
  print "[+] Checking Zip File Condition ...",
  if not zipfile.is_zipfile(self.filename):
   print "[ Error ] Bad Zip file"
   sys.exit(0)
  print " Ok"

  if not self.dictionery and not self.crunch:
   print "[ Error ] Please Provide Dictonery Or Crunch Or Password Option"
   sys.exit(0)
  if self.dictionery and self.crunch:
   print "[ Error ] Please Choose Any One Option From Dict or Crunch"
   sys.exit(0)
  return

 def extracting_engine(self,file,pwd):
  self.pwdresult=None
  try:
   file.extractall(self.output,pwd=str(pwd))
   self.show_info_message(pwd=pwd)
   self.pwdresult=True
  except Exception as e:
   if str(e).find('Permission')!=-1:
    self.show_info_message(pwd=pwd)
    self.pwdresult=True
   else:
    self.pwdresult=None
  self.pwdtries=self.pwdtries+1

  return 

  

 def show_info_message(self,pwd=None):
  if pwd:
   data="\n\t !-Congratulation-! \n\t\tPassword Found = "+pwd+'\n'
  else:
   data="\n\t Sorry! Password Not Found \n\n"
  print data
  if self.result:
   print "[+] Saving Output in ",self.result
   f=open(self.result,'a')
   f.write(data)
   f.close()
  self.closetime=time.time()
  self.time_management()
  if pwd:
   print "[+] Exiting..."
   sys.exit(0)
  return

 def extract_input_data(self):
  self.starttime=time.time()
  self.pwdtries=0
  # Extracting Function
  parser = optparse.OptionParser(usage, version=Version)
  parser.add_option("-f", "--file", action="store", type="string", dest="filename",help="Please Specify Path of Zip File", default=None)
  parser.add_option("-d", "--dict", action="store", type="string", dest="dictionery", help="Please Specify Path of Dictionery.", default=None)
  parser.add_option("-o", "--output", action="store", type="string", dest="output", help="Please Specify Path for Extracting", default='.')
  parser.add_option("-r", "--result", action="store", type="string", dest="result", help="Please Specify Path if You Want to Save Result", default=None)
  parser.add_option("-c", "--crunch", action="store", type="string", dest="crunch", help="For Using Passwords Directly from crunch use this arguments: -c True or --crunch True", default=None)
  (option, args)=parser.parse_args()
  # Record Inputs Data
  print "[+] Extracting Input Data..."
  self.filename=option.filename
  self.dictionery=option.dictionery
  self.output=option.output
  self.result=option.result
  self.crunch=option.crunch
  return

if __name__ == '__main__':
 main()

If You Like My Example And Updated Script.

then click here for my github repository.


now,

let's take about features of our example

Features




1
2
3
4
5
6
7
8
9
******************* Features ************************

This Script Supports Only Zip File in This Verson

You Can Also Use This Script With crunch

Cross-platform Supported

*****************************************************

Usages : 



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Usage: pyzipcrack.py [options] 

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f FILENAME, --file=FILENAME
                        Please Specify Path of Zip File
  -d DICTIONERY, --dict=DICTIONERY
                        Please Specify Path of Dictionery.
  -o OUTPUT, --output=OUTPUT
                        Please Specify Path for Extracting
  -r RESULT, --result=RESULT
                        Please Specify Path if You Want to Save Result
  -c CRUNCH, --crunch=CRUNCH
                        For Using Passwords Directly from crunch use this
                        arguments: -c True or --crunch True

Examples



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
examples 1:
 python pyzipcrack.py -f testfile.zip -d passwords.txt

examples 2:
 python pyzipcrack.py -f testfile.zip -d passwords.txt -o extractpath

examples 3:
 python pyzipcrack.py -f testfile.zip -d passwords.txt -r results.txt

examples 4:
 crucnh 1 5 abcde | python pyzipcrack.py -f testfile.zip -c True 


and you want live example. then check this video




If You Like My Article,

Like, Comment, Share.

Written By :
                  S.S.B


More Update, Visit Our Regularly. 
And Subscribe Our Blog, 

Follow Us and share it.
For Any Type of Suggestion Or Help
Contact me:
S.S.B
surajsinghbisht054@gmail.com

Share this

Related Posts

Previous
Next Post »