From a763586f07cdceb234cd1da8f64f94ba244aeef3 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Fri, 26 Jan 2018 14:11:53 +0100 Subject: [PATCH 1/6] added saving of zaps for generic crackers --- python/htpclient/generic_cracker.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/htpclient/generic_cracker.py b/python/htpclient/generic_cracker.py index 0f4a3fe..c48517f 100644 --- a/python/htpclient/generic_cracker.py +++ b/python/htpclient/generic_cracker.py @@ -88,8 +88,12 @@ def run_loop(self, proc, chunk, task): elif ans['response'] != 'SUCCESS': logging.error("Error from server on solve: " + str(ans)) else: + if len(ans['zaps']) > 0: + with open("files/zap", "wb") as file: # need to check if we are in the main dir here + file.write('\n'.join(ans['zaps']).encode()) + file.close() cracks = cracks_backup - logging.info("Progress: " + str(progress/100) + "% Cracks: " + str(len(cracks)) + " Accepted: " + str(ans['cracked']) + " Skips: " + str(ans['skipped'])) + logging.info("Progress: " + str(progress/100) + "% Cracks: " + str(len(cracks)) + " Accepted: " + str(ans['cracked']) + " Skips: " + str(ans['skipped']) + " Zaps: " + str(len(ans['zaps']))) else: line = line.decode() if ":" in line: From a69222fcaa5b51f434bf7e23bf3af4ac56595ee2 Mon Sep 17 00:00:00 2001 From: Michael Sprecher Date: Sat, 27 Jan 2018 09:53:42 +0100 Subject: [PATCH 2/6] save config file in pretty-printed format --- python/htpclient/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/htpclient/config.py b/python/htpclient/config.py index d43393d..2aab847 100644 --- a/python/htpclient/config.py +++ b/python/htpclient/config.py @@ -29,4 +29,4 @@ def set_value(self, key, val): def __save(self): with open(self.CONFIG_FILE, 'w') as f: - json.dump(self.config, f, ensure_ascii=False) + json.dump(self.config, f, indent=2, ensure_ascii=False) From a5c7d078e338da7e9ea955d803dd08e93b10e644 Mon Sep 17 00:00:00 2001 From: Michael Sprecher Date: Sat, 27 Jan 2018 09:59:45 +0100 Subject: [PATCH 3/6] gracefully exit if OS is not supported --- python/htpclient/helpers.py | 6 ++++++ python/htpclient/initialize.py | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 python/htpclient/helpers.py diff --git a/python/htpclient/helpers.py b/python/htpclient/helpers.py new file mode 100644 index 0000000..3dc98da --- /dev/null +++ b/python/htpclient/helpers.py @@ -0,0 +1,6 @@ +import sys +import logging + +def logErrorAndExit(message): + logging.error(message) + sys.exit(1) diff --git a/python/htpclient/initialize.py b/python/htpclient/initialize.py index da24343..69431e7 100644 --- a/python/htpclient/initialize.py +++ b/python/htpclient/initialize.py @@ -4,6 +4,7 @@ import subprocess +from htpclient.helpers import * from htpclient.jsonRequest import * @@ -28,7 +29,11 @@ def get_os(): "Windows": 1, "Darwin": 2} os = platform.system() - return osdict[os] + try: + return osdict[os] + except: + logging.debug("OS: %s" % os) + logErrorAndExit("It seems your operating system is not supported.") @staticmethod def get_os_extension(): From ebd73d5e1ada2ebb3950ddbe1d49ad8ed73a4ae6 Mon Sep 17 00:00:00 2001 From: Michael Sprecher Date: Sat, 27 Jan 2018 10:07:39 +0100 Subject: [PATCH 4/6] strip whitespaces from url and voucher --- python/htpclient/initialize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/htpclient/initialize.py b/python/htpclient/initialize.py index 69431e7..cdadf20 100644 --- a/python/htpclient/initialize.py +++ b/python/htpclient/initialize.py @@ -118,7 +118,7 @@ def __update_information(self): def __check_token(self): if len(self.config.get_value('token')) == 0: - voucher = input("No token found! Please enter a voucher to register your agent:\n") + voucher = input("No token found! Please enter a voucher to register your agent:\n").strip() name = platform.node() req = JsonRequest({'action': 'register', 'voucher': voucher, 'name': name}) ans = req.execute() @@ -136,7 +136,7 @@ def __check_token(self): def __check_url(self): if len(self.config.get_value('url')) == 0: # ask for url - url = input("Please enter the url to the API of your Hashtopussy installation:\n") + url = input("Please enter the url to the API of your Hashtopussy installation:\n").strip() logging.debug("Setting url to: " + url) self.config.set_value('url', url) else: From a095464dbb82f9b87f4afdd73c93c0169cad5e3b Mon Sep 17 00:00:00 2001 From: Michael Sprecher Date: Sat, 27 Jan 2018 10:21:25 +0100 Subject: [PATCH 5/6] add __pycache__ to gitignore --- python/.gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/.gitignore b/python/.gitignore index 2e4099e..f465c1e 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -4,4 +4,5 @@ *.json crackers files -hashlists \ No newline at end of file +hashlists +__pycache__ From 779e3fb982ac059b80de9131b022236cbc72818c Mon Sep 17 00:00:00 2001 From: Michael Sprecher Date: Sat, 27 Jan 2018 12:31:52 +0100 Subject: [PATCH 6/6] first attempt to store the dictionaries in a central place --- python/__main__.py | 7 ++++++- python/htpclient/dicts.py | 25 +++++++++++++++++++++++++ python/htpclient/initialize.py | 11 +++-------- 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 python/htpclient/dicts.py diff --git a/python/__main__.py b/python/__main__.py index 25f6a8a..a8681c9 100644 --- a/python/__main__.py +++ b/python/__main__.py @@ -8,6 +8,7 @@ from htpclient.hashlist import Hashlist from htpclient.initialize import Initialize from htpclient.jsonRequest import * +from htpclient.dicts import * import logging from htpclient.task import Task @@ -92,7 +93,11 @@ def loop(): # some error must have occurred on benchmarking continue # send result of benchmark - req = JsonRequest({'action': 'sendBenchmark', 'token': CONFIG.get_value('token'), 'taskId': task.get_task()['taskId'], 'type': 'run', 'result': result}) + query = dict_sendBenchmark.copy() + query['token'] = CONFIG.get_value('token') + query['taskId'] = task.get_task()['taskId'] + query['result'] = result + req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to send benchmark!") diff --git a/python/htpclient/dicts.py b/python/htpclient/dicts.py new file mode 100644 index 0000000..420dd8b --- /dev/null +++ b/python/htpclient/dicts.py @@ -0,0 +1,25 @@ +from types import MappingProxyType + +""" +These dictionaries are defined using MappingProxyType() which makes them read-only. +If you need to change a value you must create a copy of it. E.g. +foo = dict_foo.copy() +foo["key"] = "value" +""" + +dict_os = MappingProxyType( + {"Linux": 0, + "Windows": 1, + "Darwin": 2}) + +dict_ext = MappingProxyType( + {0: "", # Linux + 1: ".exe", # Windows + 2: ""}) # Mac OS + +dict_sendBenchmark = MappingProxyType( + {"action": "sendBenchmark", + "token": "", + "taskId": "", + "type": "run", + "result": ""}) diff --git a/python/htpclient/initialize.py b/python/htpclient/initialize.py index cdadf20..064cc0b 100644 --- a/python/htpclient/initialize.py +++ b/python/htpclient/initialize.py @@ -4,6 +4,7 @@ import subprocess +from htpclient.dicts import * from htpclient.helpers import * from htpclient.jsonRequest import * @@ -25,23 +26,17 @@ def run(self): @staticmethod def get_os(): - osdict = {"Linux": 0, - "Windows": 1, - "Darwin": 2} os = platform.system() try: - return osdict[os] + return dict_os[os] except: logging.debug("OS: %s" % os) logErrorAndExit("It seems your operating system is not supported.") @staticmethod def get_os_extension(): - extdict = {0: "", # Linux - 1: ".exe", # Windows - 2: ""} # Mac OS os = Initialize.get_os() - return extdict[os] + return dict_ext[os] def __login(self): req = JsonRequest({'action': 'login', 'token': self.config.get_value('token'), 'clientSignature': self.get_version()})