def check_files(self, files, task_id): for file in files: if os.path.isfile("files/" + file) or os.path.isfile( "files/" + file.replace(".7z", ".txt")): continue query = copyAndSetToken(ditc_getFile, self.config.get_value('token')) query['taskId'] = task_id query['file'] = file req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to get file!") sleep(5) return False elif ans['response'] != 'SUCCESS': logging.error("Getting of file failed: " + str(ans)) sleep(5) return False else: Download.download( self.config.get_value('url').replace("api/server.php", "") + ans['url'], "files/" + file) if os.path.splitext("files/" + file)[1] == '.7z' and not os.path.isfile( "files/" + file.replace(".7z", ".txt")): # extract if needed if Initialize.get_os() != 1: os.system("./7zr" + Initialize.get_os_extension() + " x -aoa -ofiles/ -y files/" + file) else: os.system("7zr" + Initialize.get_os_extension() + " x -aoa -ofiles/ -y files/" + file) return True
def __check_utils(self): path = '7zr' + Initialize.get_os_extension() if not os.path.isfile(path): query = copy_and_set_token(dict_downloadBinary, self.config.get_value('token')) query['type'] = '7zr' req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to get 7zr!") sleep(5) self.__check_utils() elif ans['response'] != 'SUCCESS' or not ans['executable']: logging.error("Getting 7zr failed: " + str(ans)) sleep(5) self.__check_utils() else: 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'): query = copy_and_set_token(dict_downloadBinary, self.config.get_value('token')) query['type'] = 'uftpd' req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to get uftpd!") sleep(5) self.__check_utils() elif ans['response'] != 'SUCCESS' or not ans['executable']: logging.error("Getting uftpd failed: " + str(ans)) sleep(5) self.__check_utils() else: Download.download(ans['executable'], path) os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC)
def check_client_version(self): if self.args.disable_update: return if os.path.isfile("old.zip"): os.unlink("old.zip") # cleanup old version query = copy_and_set_token(dict_checkVersion, self.config.get_value('token')) query['version'] = Initialize.get_version_number() req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Agent version check failed!") elif ans['response'] != 'SUCCESS': logging.error("Error from server: " + str(ans['message'])) else: if ans['version'] == 'OK': logging.info("Client is up-to-date!") else: url = ans['url'] if not url: logging.warning("Got empty URL for client update!") else: logging.info("New client version available!") if os.path.isfile("update.zip"): os.unlink("update.zip") Download.download(url, "update.zip") if os.path.isfile("update.zip") and os.path.getsize("update.zip"): if os.path.isfile("old.zip"): os.unlink("old.zip") os.rename("hashtopolis.zip", "old.zip") os.rename("update.zip", "hashtopolis.zip") logging.info("Update received, restarting client...") if os.path.exists("lock.pid"): os.unlink("lock.pid") os.execl(sys.executable, sys.executable, "hashtopolis.zip") exit(0)
def check_files(self, files, task_id): for file in files: file_localpath = "files/" + file query = copy_and_set_token(dict_getFile, self.config.get_value('token')) query['taskId'] = task_id query['file'] = file req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to get file!") sleep(5) return False elif ans['response'] != 'SUCCESS': logging.error("Getting of file failed: " + str(ans)) sleep(5) return False else: file_size = int(ans['filesize']) if os.path.isfile(file_localpath) and os.stat( file_localpath).st_size == file_size: continue elif self.config.get_value('multicast'): sleep( 5 ) # in case the file is not there yet (or not completely), we just wait some time and then try again return False # TODO: we might need a better check for this if os.path.isfile(file_localpath.replace(".7z", ".txt")): continue if self.config.get_value('rsync') and Initialize.get_os() != 1: Download.rsync( self.config.get_value('rsync-path') + '/' + file, file_localpath) else: Download.download( self.config.get_value('url').replace( "api/server.php", "") + ans['url'], file_localpath) if os.path.isfile(file_localpath) and os.stat( file_localpath).st_size != file_size: logging.error("file size mismatch on file: %s" % file) sleep(5) return False if os.path.splitext("files/" + file)[1] == '.7z' and not os.path.isfile( "files/" + file.replace(".7z", ".txt")): # extract if needed if Initialize.get_os() != 1: os.system("./7zr" + Initialize.get_os_extension() + " x -aoa -ofiles/ -y files/" + file) else: os.system("7zr" + Initialize.get_os_extension() + " x -aoa -ofiles/ -y files/" + file) return True
def check_version(self, cracker_id): path = "crackers/" + str(cracker_id) + "/" query = copy_and_set_token(dict_downloadBinary, self.config.get_value('token')) query['type'] = 'cracker' query['binaryVersionId'] = cracker_id req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to load cracker!") sleep(5) return False elif ans['response'] != 'SUCCESS' or not ans['url']: logging.error("Getting cracker failed: " + str(ans)) sleep(5) return False else: self.last_version = ans if not os.path.isdir(path): # we need to download the 7zip if not Download.download(ans['url'], "crackers/" + str(cracker_id) + ".7z"): logging.error("Download of cracker binary failed!") sleep(5) return False if Initialize.get_os() == 1: os.system("7zr" + Initialize.get_os_extension() + " x -ocrackers/temp crackers/" + str(cracker_id) + ".7z") else: os.system("./7zr" + Initialize.get_os_extension() + " x -ocrackers/temp crackers/" + str(cracker_id) + ".7z") os.unlink("crackers/" + str(cracker_id) + ".7z") for name in os.listdir("crackers/temp"): if os.path.isdir("crackers/temp/" + name): os.rename("crackers/temp/" + name, "crackers/" + str(cracker_id)) else: os.rename("crackers/temp", "crackers/" + str(cracker_id)) break return True
def load_hashlist(self, hashlist_id): query = copy_and_set_token(dict_getHashlist, self.config.get_value('token')) query['hashlistId'] = hashlist_id req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to get hashlist!") sleep(5) return False elif ans['response'] != 'SUCCESS': logging.error("Getting of hashlist failed: " + str(ans)) sleep(5) return False else: Download.download( self.config.get_value('url').replace("api/server.php", "") + ans['url'], "hashlists/" + str(hashlist_id), True) return True
def load_found(self, hashlist_id, cracker_id): query = copy_and_set_token(dict_getFound, self.config.get_value('token')) query['hashlistId'] = hashlist_id req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to get found of hashlist!") sleep(5) return False elif ans['response'] != 'SUCCESS': logging.error("Getting of hashlist founds failed: " + str(ans)) sleep(5) return False else: logging.info("Saving found hashes to hashcat potfile...") Download.download( self.config.get_value('url').replace("api/server.php", "") + ans['url'], "crackers/" + str(cracker_id) + "/hashcat.potfile", True) return True
def check_prince(self): logging.debug("Checking if PRINCE is present...") path = "prince/" if os.path.isdir( path): # if it already exists, we don't need to download it logging.debug("PRINCE is already downloaded") return True logging.debug("PRINCE not found, download...") query = copy_and_set_token(dict_downloadBinary, self.config.get_value('token')) query['type'] = 'prince' req = JsonRequest(query) ans = req.execute() if ans is None: logging.error("Failed to load prince!") sleep(5) return False elif ans['response'] != 'SUCCESS' or not ans['url']: logging.error("Getting prince failed: " + str(ans)) sleep(5) return False else: if not Download.download(ans['url'], "prince.7z"): 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") 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") break os.unlink("prince.7z") os.rmdir("temp") logging.debug("PRINCE downloaded and extracted") return True