PyRarCrack
Bruteforce attack for .rar using unrar
usage: [Link] [-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 [[Link]]
```
Example
$ python [Link] --start 10 --stop 10 --file example_path.rar --alphabet 1234567890
Password found: 1234567890
Time: 0.06715750694274902
```
[Link]
"""
Bruteforce attack for .rar using unrar.
Based on:
[Link]
[Link]
[Link]
"""
from argparse import ArgumentParser
from itertools import chain, product
from [Link] 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 [[Link]]', 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([Link]):
raise FileNotFoundError([Link])
if [Link] < [Link]:
raise Exception('Stop number is less than start')
start_time = time()
for combination in generate_combinations(
[Link], [Link], [Link]
):
formated_combination = format(combination)
if [Link]:
print(f'Trying: {combination}')
cmd = Popen(
f'unrar t -p{formated_combination} {[Link]}'.split(),
stdout=PIPE,
stderr=PIPE,
out, err = [Link]()
if 'All OK' in [Link]():
print(f'Password found: {combination}')
print(f'Time: {time() - start_time}')
exit()
[Link]
from unittest import TestCase, main
from [Link] import patch
from pyrarcrack import generate_combinations
class TestCombination(TestCase):
def test_should_generate_minimal_combination(self):
[Link](
list(generate_combinations('a', 1)),
['a']
if __name__ == '__main__':
main()
gitignore
__pycache__
*.rar