def openTerminal(cls, default_target=""): if cls.settings.isTrapCommand(): comm = "bash --rcfile " + os.path.join( Utils.getMainDir(), "setupTerminalForPentest.sh") else: comm = "bash" env = { "POLLENISATOR_DEFAULT_TARGET": default_target, } res = Utils.executeInExternalTerm(comm, with_bash=False, env=env)
def start_docker(dialog, force_reinstall): worker_subdir = os.path.join(Utils.getMainDir(), "PollenisatorWorker") if os.path.isdir(worker_subdir) and force_reinstall: shutil.rmtree(worker_subdir) if not os.path.isdir(worker_subdir): git.Git(Utils.getMainDir()).clone( "https://github.com/fbarre96/PollenisatorWorker.git") shutil.copyfile( os.path.join(Utils.getConfigFolder(), "client.cfg"), os.path.join(Utils.getMainDir(), "PollenisatorWorker/config/client.cfg")) dialog.update( 1, msg= "Building worker docker could take a while (1~10 minutes depending on internet connection speed)..." ) try: client = docker.from_env() clientAPI = docker.APIClient() except Exception as e: dialog.destroy() tk.messagebox.showerror("Unable to launch docker", e) return image = client.images.list("pollenisatorworker") if len(image) > 0 and force_reinstall: force_reinstall = tk.messagebox.askyesno( "Force reinstall", "A pollenisator worker image has been found. Are you sure you want to rebuild it ?" ) if len(image) == 0 or force_reinstall: try: log_generator = clientAPI.build(path=os.path.join( Utils.getMainDir(), "PollenisatorWorker/"), rm=True, tag="pollenisatorworker", nocache=force_reinstall) change_max = None for byte_log in log_generator: updated_dialog = False log_line = byte_log.decode("utf-8").strip() if log_line.startswith("{\"stream\":\""): log_line = log_line[len("{\"stream\":\""):-4] matches = re.search(r"Step (\d+)/(\d+)", log_line) if matches is not None: if change_max is None: change_max = int(matches.group(2)) dialog.progressbar["maximum"] = change_max dialog.update(int(matches.group(1)), log=log_line + "\n") updated_dialog = True except docker.errors.BuildError as e: dialog.destroy() tk.messagebox.showerror("Build docker error", "Building error:\n" + str(e)) return image = client.images.list("pollenisatorworker") if len(image) == 0: tk.messagebox.showerror( "Building docker failed", "The docker build command failed, try to install manually...") return dialog.update(2, msg="Starting worker docker ...") clientCfg = Utils.loadClientConfig() if clientCfg["host"] == "localhost" or clientCfg["host"] == "127.0.0.1": network_mode = "host" else: network_mode = None container = client.containers.run( image=image[0], network_mode=network_mode, volumes={ os.path.join(Utils.getMainDir(), "PollenisatorWorker"): { 'bind': '/home/Pollenisator', 'mode': 'rw' } }, detach=True) dialog.update(3, msg="Checking if worker is running") print(container.id) if container.logs() != b"": print(container.logs()) dialog.destroy()
def getScriptsDir(self): return os.path.join(Utils.getMainDir(), "scripts/")