0% found this document useful (0 votes)
50 views

Py Rar Crack

PyRarCrack is a Python tool that uses brute force to crack RAR password protected files. It generates combinations of characters from a given alphabet between a start and stop length to use as passwords for the RAR file. When it finds the correct password, it prints the password and the time taken.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Py Rar Crack

PyRarCrack is a Python tool that uses brute force to crack RAR password protected files. It generates combinations of characters from a given alphabet between a start and stop length to use as passwords for the RAR file. When it finds the correct password, it prints the password and the time taken.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PyRarCrack

Bruteforce attack for .rar using unrar

usage: pyrarcrack.py [-h] [--start START] [--stop STOP] [--verbose VERBOSE]


[--alphabet ALPHABET] [--file FILE]

Python combination generator to unrar

optional arguments:
-h, --help show this help message and exit
--start START Number of characters of the initial string [1 -> "a", 2-> "aa"]
--stop STOP Number of characters of the final string [3 -> "ßßß"]
--verbose VERBOSE Show combintations
--alphabet ALPHABET alternative chars to combinations
--file FILE .rar file [file.rar]
```

Example
$ python pyrarcrack.py --start 10 --stop 10 --file example_path.rar --alphabet 1234567890

Password found: 1234567890

Time: 0.06715750694274902

```
Pyrarcrack.py
"""

Bruteforce attack for .rar using unrar.

Based on:

http://stackoverflow.com/questions/11747254/python-brute-force-algorithm

http://www.enigmagroup.org/code/view/python/168-Rar-password-cracker

http://rarcrack.sourceforge.net/

"""

from argparse import ArgumentParser

from itertools import chain, product

from os.path import exists

from string import printable

from subprocess import PIPE, Popen

from time import time

chars = (

printable

+ 'ÁáÂâàÀÃãÅåÄ䯿ÉéÊêÈèËëÐðÍíÎîÌìÏïÓóÒòÔôØøÕõÖöÚúÛûÙùÜüÇçÑñÝý®©Þþß'

special_chars = "();<>`|~\"&\'}]"

parser = ArgumentParser(description='Python combination generator to unrar')

parser.add_argument(

'--start',

help='Number of characters of the initial string [1 -> "a", 2 -> "aa"]',

type=int,

)
parser.add_argument(

'--stop',

help='Number of characters of the final string [3 -> "ßßß"]',

type=int,

parser.add_argument(

'--verbose', help='Show combintations', default=False, required=False

parser.add_argument(

'--alphabet',

help='alternative chars to combinations',

default=chars,

required=False,

parser.add_argument('--file', help='.rar file [file.rar]', type=str)

args = parser.parse_args()

def generate_combinations(alphabet, length, start=1):

"""Generate combinations using alphabet."""

yield from (

''.join(string)

for string in chain.from_iterable(

product(alphabet, repeat=x) for x in range(start, length + 1)


)

def format(string):

"""Format chars to write them in shell."""

formated = map(

lambda char: char if char not in special_chars else f'\\{char}', string

return ''.join(formated)

if __name__ == '__main__':

if not exists(args.file):

raise FileNotFoundError(args.file)

if args.stop < args.start:

raise Exception('Stop number is less than start')

start_time = time()

for combination in generate_combinations(

args.alphabet, args.stop, args.start

):

formated_combination = format(combination)

if args.verbose:

print(f'Trying: {combination}')

cmd = Popen(
f'unrar t -p{formated_combination} {args.file}'.split(),

stdout=PIPE,

stderr=PIPE,

out, err = cmd.communicate()

if 'All OK' in out.decode():

print(f'Password found: {combination}')

print(f'Time: {time() - start_time}')

exit()

Tests.py
from unittest import TestCase, main

from unittest.mock import patch

from pyrarcrack import generate_combinations

class TestCombination(TestCase):

def test_should_generate_minimal_combination(self):

self.assertEqual(

list(generate_combinations('a', 1)),

['a']

if __name__ == '__main__':

main()

gitignore
__pycache__

*.rar

You might also like