Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions htpclient/binarydownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from htpclient.config import Config
from htpclient.download import Download
from htpclient.helpers import retrieveBinary
from htpclient.initialize import Initialize
from htpclient.jsonRequest import JsonRequest
from htpclient.dicts import *
Expand Down Expand Up @@ -63,7 +64,7 @@ def check_client_version(self):

def __check_utils(self):
path = '7zr' + Initialize.get_os_extension()
if not os.path.isfile(path):
if not retrieveBinary(path):
query = copy_and_set_token(dict_downloadBinary, self.config.get_value('token'))
query['type'] = '7zr'
req = JsonRequest(query)
Expand All @@ -80,7 +81,7 @@ def __check_utils(self):
Download.download(ans['executable'], path)
os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC)
path = 'uftpd' + Initialize.get_os_extension()
if not os.path.isfile(path) and self.config.get_value('multicast'):
if not retrieveBinary(path) and self.config.get_value('multicast'):
query = copy_and_set_token(dict_downloadBinary, self.config.get_value('token'))
query['type'] = 'uftpd'
req = JsonRequest(query)
Expand Down Expand Up @@ -121,10 +122,8 @@ def check_prince(self):
logging.error("Download of prince failed!")
sleep(5)
return False
if Initialize.get_os() == 1:
os.system("7zr" + Initialize.get_os_extension() + " x -otemp prince.7z")
else:
os.system("./7zr" + Initialize.get_os_extension() + " x -otemp prince.7z")
zr_bin = retrieveBinary("7zr" + Initialize.get_os_extension())
os.system(zr_bin + " x -otemp prince.7z")
Comment thread
jessevz marked this conversation as resolved.
Outdated
for name in os.listdir("temp"): # this part needs to be done because it is compressed with the main subfolder of prince
if os.path.isdir("temp/" + name):
os.rename("temp/" + name, "prince")
Expand Down Expand Up @@ -160,10 +159,8 @@ def check_preprocessor(self, task):
logging.error("Download of preprocessor failed!")
sleep(5)
return False
if Initialize.get_os() == 1:
os.system(f"7zr{Initialize.get_os_extension()} x -otemp temp.7z")
else:
os.system(f"./7zr{Initialize.get_os_extension()} x -otemp temp.7z")
zr_bin = retrieveBinary("7zr" + Initialize.get_os_extension())
os.system(f"{zr_bin} x -otemp temp.7z")
Comment thread
jessevz marked this conversation as resolved.
Outdated
for name in os.listdir("temp"): # this part needs to be done because it is compressed with the main subfolder of prince
if os.path.isdir(Path('temp', name)):
os.rename(Path('temp', name), path)
Expand Down Expand Up @@ -200,13 +197,8 @@ def check_version(self, cracker_id):
# we need to extract the 7zip
temp_folder = Path(self.config.get_value('crackers-path'), 'temp')
zip_file = Path(self.config.get_value('crackers-path'), f'{cracker_id}.7z')

if Initialize.get_os() == 1:
# Windows
cmd = f'7zr{Initialize.get_os_extension()} x -o"{temp_folder}" "{zip_file}"'
else:
# Linux
cmd = f"./7zr{Initialize.get_os_extension()} x -o'{temp_folder}' '{zip_file}'"
zrbinary = retrieveBinary("7zr" + Initialize.get_os_extension())
Comment thread
jessevz marked this conversation as resolved.
Outdated
Comment thread
s3inlc marked this conversation as resolved.
Outdated
cmd = f'{zrbinary} x -o"{temp_folder}" "{zip_file}"'
os.system(cmd)

# Clean up 7zip
Expand Down
9 changes: 3 additions & 6 deletions htpclient/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from htpclient.config import Config
from htpclient.download import Download
from htpclient.helpers import retrieveBinary
from htpclient.initialize import Initialize
from htpclient.jsonRequest import JsonRequest
from htpclient.dicts import *
Expand Down Expand Up @@ -106,11 +107,7 @@ def check_files(self, files, task_id):
if os.path.splitext(file_localpath)[1] == '.7z' and not os.path.isfile(txt_file):
# extract if needed
files_path = Path(self.config.get_value('files-path'))
if Initialize.get_os() == 1:
# Windows
cmd = f'7zr{Initialize.get_os_extension()} x -aoa -o"{files_path}" -y "{file_localpath}"'
else:
# Linux
cmd = f"./7zr{Initialize.get_os_extension()} x -aoa -o'{files_path}' -y '{file_localpath}'"
zr_bin = retrieveBinary("7zr" + Initialize.get_os_extension())
Comment thread
jessevz marked this conversation as resolved.
Outdated
cmd = f'{zr_bin} x -aoa -o"{files_path}" -y "{file_localpath}"'
os.system(cmd)
return True
20 changes: 19 additions & 1 deletion htpclient/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

import os
import shutil
import subprocess

from htpclient.dicts import copy_and_set_token, dict_clientError
Expand Down Expand Up @@ -66,7 +67,7 @@ def start_uftpd(os_extension, config):
subprocess.check_output("killall -s 9 uftpd", shell=True) # stop running service to make sure we can start it again
except subprocess.CalledProcessError:
pass # ignore in case uftpd was not running
path = './uftpd' + os_extension
path = retrieveBinary('uftpd' + os_extension)
Comment thread
jessevz marked this conversation as resolved.
Outdated
cmd = path + ' '
if config.get_value('multicast-device'):
cmd += "-I " + config.get_value('multicast-device') + ' '
Expand Down Expand Up @@ -132,3 +133,20 @@ def update_files(command, prince=False):
def escape_ansi(line):
ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
return ansi_escape.sub('', line)

# function to retrieve a system or local binary.
def retrieveBinary(binary):
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

Function name uses camelCase instead of snake_case. The established naming convention in this codebase is snake_case for functions (e.g., log_error_and_exit, print_speed, get_bit, kill_hashcat at lines 19, 24, 38, 44). This function should be renamed to retrieve_binary for consistency.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with this, we use snake case in almost all other function names.

cwd = Path.cwd()
# use full path so that it works on Windows and Linux
local_binary = cwd / binary

# First check if there is a local binary and use that if it is there
if local_binary.exists() and local_binary.is_file() and os.access(local_binary, os.X_OK):
return str(local_binary)
Comment thread
jessevz marked this conversation as resolved.
Outdated

# Fall back on sytem binary
Comment thread
jessevz marked this conversation as resolved.
Outdated
systemBinary = shutil.which(binary)

if systemBinary:
return systemBinary
Comment thread
jessevz marked this conversation as resolved.
Outdated
return None
Comment thread
jessevz marked this conversation as resolved.
Outdated
Comment thread
jessevz marked this conversation as resolved.
Outdated