how to create python rar file cracker?

Namaste Friends,





                                          Today's Tutorial is about how to create rar/zip file cracker using python. or you can say how to create python script for brute force rar/zip file using rarfile/zipfile python module.



so friends,

here, I am going to show you both examples one by one.

1.  Zip File Cracker. (click here for zip file cracker example.)


2.  Rar File Cracker (keep reading).

so,  let's start with rar file cracker.

for rar file cracker,

first, you need to install rarfile python module. and

for installing python rarfile module through pip.

type below provided commands.

#
# For Python 2.X

sudo python -m pip install rarfile

#
# For Python 3.x

sudo python3 -m pip install rarfile

 
now,

let's move

ahead and talk about

how to extract rar file in python using rarfile.


here, I am showing a simple example.


# import module
import rarfile

# create file handling object
fileload=rarfile.RarFile("Type Your __filepath__ here")

# now extract password protected file

try:
    fileload.extractall(output_path_here,pwd=str(your_password_here))

except:
    print "You Input Password is wrong"


now,

 let's move a head

and

let's try to create a useful rarfile cracker that can work in high speed and

can also take password input directly from crunch.


Here, This is my Codes of  pyrarcrack.py script


1. pyrarcrack.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
143
144
145
146
147
148
149
150
#!/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
#
#
##################################################
######## Please Don't Remove Author Name #########
############### Thanks ###########################
##################################################
#
#
__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 rarfile,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 rarfile...  ",
  fileload=rarfile.RarFile(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 Rar File Path "
   sys.exit(0)
  print "[+] Checking Rar File Condition ...",
  if not rarfile.is_rarfile(self.filename):
   print "[ Error ] Bad Rar 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 Rar 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()


here, this is my codes.

but if you want latest updated example. then, check here my GitHub repository.

I know, these codes look very lengthy.

but my friends,

for useful features. this lengthy is important.

now,

let me show you some important functions of these codes.

Features :

  • This Script Supports Only Rar File in This Version
  • You Can Also Use This Script With crunch
  • Cross-platform Supported


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 Rar 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

Usages Examples:


- python pyrarcrack.py -f testfile.rar -d passwords.txt
- python pyrarcrack.py -f testfile.rar -d passwords.txt -o extractpath
- python pyrarcrack.py -f testfile.rar -d passwords.txt -r results.txt
- crucnh 1 5 abcde | python pyrarcrack.py -f testfile.rar -c True 

Screen Shot:





If You Like My Article,

Like, Comment, Share.

Written By:
                  S.S.B


More Update, Visit ours 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 »