Python: скрипт Bruteforce для защищенного паролем выпуска Excel - PullRequest
0 голосов
/ 10 апреля 2020

Я пытаюсь создать сценарий грубой силы для файлов Excel, защищенных паролем, используя мультиобработку, у меня есть приведенный ниже код .... однако функция "pwd_find", даже если через нее проходит правильный пароль, никогда не выдаст "print (" ** PW IS: "+ wordlist [word] .strip ())" ... Я не знаю, является ли структура открытия / закрытия файла Excel неправильной или что происходит

import tempfile, shutil, os
from multiprocessing import Pool
import math
import time
import random
from win32com.client import Dispatch



passwordList = open('wordlist.txt','r').read().splitlines()
file = 'ws.xlsx'
cores = 4  # Number of cores to use
wordlist = []


def pwd_find(start, stop):

    for word in range(start, stop):
        #print(wordlist[word])
        time.sleep(0.1)  # Slows things down so it's easier to see that your system is using more than one core.


        instance = Dispatch('Excel.Application')

        try:
            temp_file = create_temporary_copy(file)

            print(wordlist[word].strip())

            instance.Workbooks.Open(temp_file, False, True, None, wordlist[word].strip())
            print ("**PW IS: " + wordlist[word].strip())
            os.remove(temp_file)


        except:
            #instance.Quit()
            os.remove(temp_file)

        instance.Quit()




for pw in passwordList:
    wordlist.append(pw)

def create_temporary_copy(path):
    temp_dir = tempfile.gettempdir()
    temp_path = os.path.join(temp_dir, str(random.randint(1, 1000)) + 'temp_file_name.xlsx')
    shutil.copy2(path, temp_path)
    return temp_path

break_points = []  
for i in range(cores):  
    break_points.append({"start":math.ceil(len(wordlist)/cores * i), "stop":math.ceil(len(wordlist)/cores * (i + 1))})

if __name__ == '__main__':  

    p = Pool(cores)  # Number of processors to utilize.
    for i in break_points:  # Cycles though the breakpoints list created above.
        print(i)  # shows the start and stop points.
        a = p.apply_async(pwd_find, kwds=i, args=tuple())  # This will start the separate processes.
    print("Done!")
    p.close()
    p.join()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...