Python: Rar Brute Forcer

I am trying to overdo the RAR archive, which is password protected with three characters:

import os Alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for a in range(0,26): for b in range(0,26): for c in range(0,26): Brute = Alphabets[a] + Alphabets[b] + Alphabets[c] os.popen4("Rar.exe x -p" + Brute + " Protected.rar") # raw_input() raw_input("Done !") 

The code works fine, except: it is very slow!

I think it slows down, this is the repeated opening of "popen4". because I tried to save the generated words in a txt file and the program completed in less than 5 seconds.

Any ideas for better performance?

+4
source share
5 answers

You can use (or learn) rarcrack . It is written in C and compiles without problems in Linux (Windows with a lot of changes).

In general, opening a process for each password verified is very expensive. You must try and open the archive yourself, and then check all the passwords. In any case, you need to check the return value of rar.exe to find out if the extraction succeeded.

For best performance, you should write a program in C (or similar). There's a Linux package called "libunrar" that can help you open RAR files.

+7
source

you can use some stdlib modules:

 >>> import string >>> import itertools >>> from subprocess import Popen, PIPE >>> for i in itertools.product(string.ascii_uppercase, repeat=3): pr = Popen(['rar.exe', 'x', '-p', ''.join(i), 'protected.rar'], stdin=PIPE, stdout=PIPE) pr.communicate() 

This may not necessarily improve performance, but it makes your code cleaner.

+5
source

Password generation is trivial, so it takes only 5 seconds to create passwords 26 ^ 3 = 17576. What takes the most time is opening and trying to decrypt the archive - and you have no control over it.

You can't do it faster - the rar binary and the input file will be cached in memory after the first few attempts: just let it work overnight or on the weekend, as needed.

+3
source

How about generating passwords first and then parallelizing the rar.exe process call (which seems like a bottleneck)?

0
source

You may not be able to reduce the time required to decrypt the archive, but assuming that the password is not completely random (as it may be), you can get the correct password even faster if you order letters while reducing the likelihood of use .

For example, in the Linux Journal, a column of script analyzed several large texts to determine that e, t, a, o, n, i, s, r, h, and d are the most common letters in these texts (and, presumably, this is close to English in general). So, changing the second line: Alphabets = "ETAONIBSRHDCFGJKLMPQUVWXYZ" can cause your algorithm to reach a password with fewer iterations.

Edit: Second thoughts If the password, as indicated by someone, is "cat", the initial order will require 3 passes through the external loop, while the new version will require 11 passes, so in this case it will not solve it faster. Therefore, perhaps you need to optimize the list for the outer loop, trying to predict the most likely first letter.

0
source

Source: https://habr.com/ru/post/1299559/


All Articles