Python is a great programming language & could it be used for many useful purposes & save a lot of hard work as well as time. Here is my one story: I once forgot the password of one my Winrar archive file (.RAR) as, I did not have the password, I was not able to extract my .RAR archive file. However, I did remember some parts of my password. It was a combination of word and some numbers.
I had to right click the .RAR archive file, click extract, then a password prompt would appear. I had to manually type the password and try them all. This was going to be a long night. Well, finally python came to my escape!
Fortunately, the Winrar software support command line interface. I decided to create a dictionary based password cracking tool using python.
The python code is provided below:
from subprocess import Popen, PIPE
import sys, time
Author: Prab 🙂
crack_rar.py fileName dictionary
fileName = Name of the .RAR file
dictionary = Password dictionary
if len(sys.argv) > 2:
fileName = sys.argv
dictionary = sys.argv
print “The filename you entered is: %s \n”%fileName
print “The dictionary you entered is: %s \n”%dictionary
dictFile = open(dictionary)
passwords = dictFile.read().splitlines()
for password in passwords:
cmd = “unrar.exe t %s -p%s” %(fileName, password)
print “Trying %s as password” %password
p = Popen(cmd , shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
if p.returncode == 0:
print “\n SUCCESS the pssword is -> %s \n”%password
print “Finished trying all the passwords.”
I shall demonstrate an example. I have created a .RAR archive named secret.rar and it is password protected. I have created a dictionary file with a list of some passwords. The python script will check each password in the dictionary file and then display the provide us the correct password! First of all you need the Urar.exe file from WinRar installation directory. Usually, it is located at C:\Program Files\WinRAR , as shown in the screenshot below.
I have created a dictionary.txt file that contains a list of the passwords. The content is shown:
Now, I shall execute my python script to find the correct password. I shall use the Windows CMD to execute my script. The script requires two parameters, the first one is the .RAR file name & second is the dictionary file name.
> crack_rar.py Parameter1 Parameter2
The result is shown in the image below, the python script tries each password in the list & at founded the correct password at last!
Python script in action
The script took 1-2 seconds to complete. If I had to do check each password manually, it would take approx. 5 minutes or more. What if the dictionary contained 100 passwords? 😉
For more articles from this author: https://trybe.one/members/prab636/blog/Your Remaining Votes (within 24hrs) : 10 of 10