Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	python/.gitignore
  • Loading branch information
s3inlc committed Jan 27, 2018
2 parents 6c59ca1 + 779e3fb commit 0278062
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
crackers
files
hashlists
htpclient/__pycache__
__pycache__
7 changes: 6 additions & 1 deletion python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!")
Expand Down
2 changes: 1 addition & 1 deletion python/htpclient/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
25 changes: 25 additions & 0 deletions python/htpclient/dicts.py
Original file line number Diff line number Diff line change
@@ -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": ""})
6 changes: 5 additions & 1 deletion python/htpclient/generic_cracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions python/htpclient/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys
import logging

def logErrorAndExit(message):
logging.error(message)
sys.exit(1)
20 changes: 10 additions & 10 deletions python/htpclient/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import subprocess

from htpclient.dicts import *
from htpclient.helpers import *
from htpclient.jsonRequest import *


Expand All @@ -24,19 +26,17 @@ def run(self):

@staticmethod
def get_os():
osdict = {"Linux": 0,
"Windows": 1,
"Darwin": 2}
os = platform.system()
return osdict[os]
try:
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()})
Expand Down Expand Up @@ -113,7 +113,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()
Expand All @@ -131,7 +131,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:
Expand Down

0 comments on commit 0278062

Please sign in to comment.