Last active
May 8, 2021 18:56
-
-
Save bhpayne/651d4206da8cf103e8c679d36698614c to your computer and use it in GitHub Desktop.
concurrent pathos password search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
concurrent distribution | |
""" | |
#import pathos # https://pypi.org/project/pathos/ | |
from pathos.multiprocessing import ProcessingPool | |
import itertools | |
import msoffcrypto # https://pypi.org/project/msoffcrypto-tool/ | |
import string | |
import time | |
#>>> len(string.ascii_letters + string.digits + string.punctuation) | |
#94 | |
# 94^2 = 8836 | |
# 94^3 = 830584 | |
# 94^4 = 78074896 | |
# 94^5 = 7339040224 | |
with open("encrypted.xlsx", "rb") as file_handle: | |
file = msoffcrypto.OfficeFile(file_handle) | |
start_time = time.time() | |
def count_list(my_list:list) -> int: | |
""" | |
a function to apply to the list | |
""" | |
for attempt in my_list: | |
try: | |
file.load_key(password=attempt) | |
print("success with " + attempt) | |
exit() | |
except: | |
pass | |
return | |
chars = string.ascii_letters + string.digits + string.punctuation | |
this_thousand = [] | |
to_distribute = [] | |
loop_index=0 | |
chunk_size_per_process = 10000 | |
number_of_processes = 2 | |
pool = ProcessingPool(number_of_processes) | |
for item in itertools.product(chars,repeat=3): | |
loop_index+=1 | |
this_thousand.append(''.join(item)) | |
if len(this_thousand)==chunk_size_per_process: | |
print(loop_index,len(this_thousand),str(round(time.time()-start_time,2))) | |
to_distribute.append(this_thousand) | |
if len(to_distribute)==number_of_processes: | |
res = pool.map(count_list, to_distribute) # https://stackoverflow.com/a/65174828/1164295 | |
print("res =",res) | |
del to_distribute | |
to_distribute = [] | |
del this_thousand | |
this_thousand=[] | |
print(str(round(time.time()-start_time,2))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM centos:7 | |
RUN yum install -y \ | |
python3-devel | |
RUN pip3 install setuptools_rust && \ | |
pip3 install cryptography==3.2 && \ | |
pip3 install msoffcrypto-tool | |
RUN pip3 install pathos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker: docker_build docker_run | |
docker_build: | |
docker build -t passd . | |
docker_run: | |
docker run -it --rm -v `pwd`:/scratch passd /bin/bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment