Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented May 20, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from godiam6969 May 20, 2023 19:29
if p.suffix == "":
if not p.suffix:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function File._setup refactored with the following changes:

Comment on lines -70 to +74
include_subfolders = target[1]
target_path = target[2]
if target_type == "File":
self._add_target_file(target_path=target_path)
else:
include_subfolders = target[1]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AttackTargets.add_target refactored with the following changes:

self.view.insert_text_message(
f"### INITIALISING ###",
update_idle=True
)
self.view.insert_text_message("### INITIALISING ###", update_idle=True)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DictionaryAttack.run refactored with the following changes:

Comment on lines -75 to +71
is_supported_type = self._is_supported_file(target_file)
if is_supported_type:
pw_required = self._attempt_open_file(target_file)
if pw_required:
if is_supported_type := self._is_supported_file(target_file):
if pw_required := self._attempt_open_file(target_file):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DictionaryAttack._attack_file refactored with the following changes:

Comment on lines -124 to -182
rar_obj = rarfile.RarFile(target_file.file_path, pwd=password)
found = True
found_password = password
last_attempt = attempt
rar_obj.extractall(self.save_destination)
break
except RuntimeError as err:
if str(err).startswith("Bad password"):
update_idle = (attempt % 5 == 0)
self.view.insert_text_message(
f"Attempt {attempt}: '{password}' failed.",
update_idle=update_idle
)
if attempt % 250 == 0:
self.view.clear_text_output()
continue
else:
self.view.display_messagebox(err, "showerror")
with open(self.password_file, "r", encoding="latin1") as pws:
for attempt, password in enumerate(pws, 1):
password = password.strip()
if target_file.file_type == ".rar":
try:
# issue rarfile doesnt handle latin1 characters
# so use a different password file or amend the rockyouone
rar_obj = rarfile.RarFile(target_file.file_path, pwd=password)
found = True
found_password = password
last_attempt = attempt
rar_obj.extractall(self.save_destination)
break

elif target_file.file_type == ".zip":
try:
password_byte = bytes(password, "latin1")
ZipFile(target_file.file_path).extractall(path=self.save_destination,
pwd=password_byte)
found = True
found_password = password_byte.decode("latin1")
last_attempt = attempt
break
except RuntimeError as err:
if str(err).startswith("Bad password"):
update_idle = (attempt % 5 == 0)
self.view.insert_text_message(
f"Attempt {attempt}: '{password}' failed.",
update_idle=update_idle
)
if attempt % 250 == 0:
self.view.clear_text_output()
else:
self.view.display_messagebox(err, "showerror")
except RuntimeError as err:
if str(err).startswith("Bad password"):
update_idle = (attempt % 5 == 0)
self.view.insert_text_message(
f"Attempt {attempt}: '{password}' failed.",
update_idle=update_idle
)
if attempt % 250 == 0:
self.view.clear_text_output()
continue
else:
self.view.display_messagebox(err, "showerror")
break

elif target_file.file_type == ".zip":
try:
password_byte = bytes(password, "latin1")
ZipFile(target_file.file_path).extractall(path=self.save_destination,
pwd=password_byte)
found = True
found_password = password_byte.decode("latin1")
last_attempt = attempt
break
except zlib.error as zerr:
if str(zerr).startswith("Error -3"):
# If there are compression errors then skip
continue
else:
except RuntimeError as err:
if str(err).startswith("Bad password"):
update_idle = (attempt % 5 == 0)
self.view.insert_text_message(
f"Attempt {attempt}: '{password}' failed.",
update_idle=update_idle
)
if attempt % 250 == 0:
self.view.clear_text_output()
else:
self.view.display_messagebox(err, "showerror")
break
except zlib.error as zerr:
if str(zerr).startswith("Error -3"):
# If there are compression errors then skip
continue
self.view.display_messagebox(zerr, "showerror")
break

pws.close()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DictionaryAttack._crack_file refactored with the following changes:

This removes the following comments ( why? ):

# just read line by line
# dont use readlines as it will store the whole file in memory..

Comment on lines -214 to +204
f = open(dest, "a+")
f.write(line)
f.close()
with open(dest, "a+") as f:
f.write(line)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DictionaryAttack._store_password refactored with the following changes:

Comment on lines -112 to +116
selection = filedialog.askdirectory()
else:
type1 = ("All Files", "*.*") if not only_text else ("Text Files", "*.txt")
selection = filedialog.askopenfilename(initialdir="/",
title="Select a File",
filetype=[type1])
return selection
return filedialog.askdirectory()
type1 = ("All Files", "*.*") if not only_text else ("Text Files", "*.txt")
return filedialog.askopenfilename(
initialdir="/", title="Select a File", filetype=[type1]
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MainPage._windows_dialog refactored with the following changes:

Comment on lines -144 to +142
row = self.tv_target.selection()
if row:
if row := self.tv_target.selection():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MainPage._delete_tv_row refactored with the following changes:

@@ -164,7 +161,6 @@ def set_current_target(self, current_target):
self.label_current_target["text"] = current_target

def _launch_dictionary_attack(self):
password_hash_type = "Plain Text" # self.hash.get()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MainPage._launch_dictionary_attack refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants