async def _update_cmyui(self) -> None: """Check if cmyui_pkg has a newer release; update if available.""" module_ver = Version.from_str(pkg_version('cmyui')) latest_ver = await self._get_latest_cmyui() if module_ver < latest_ver: # package is not up to date; update it. log(f'Updating cmyui_pkg (v{module_ver!r} -> ' f'v{latest_ver!r}).', Ansi.MAGENTA) pip_main(['install', '-Uq', 'cmyui']) # Update quiet
def pip_install(path: PathType, package_name: str) -> ContextManagerFunctionReturnType[None]: """ Installs a package with pip located in the given path and with the given name. This method is intended to use with `with`, so after its usage, the package will be uninstalled. """ pip_main(["install", str(path)]) try: yield finally: pip_main(["uninstall", "-y", package_name])
def main(): global AURA_PATH if not check_version(): logger.warning("Unsupported pip version: '{}'".format(pip.__version__)) logger.warning("Use one of the supported versions: {}".format( ", ".join(SUPPORTED_PIP_VERSIONS))) if "AURA_PATH" in os.environ: AURA_PATH = os.environ["AURA_PATH"] elif hasattr(shutil, "which"): AURA_PATH = shutil.which("aura") if AURA_PATH is None: logger.error( "You need to set AURA_PATH environment variable that points to the AURA framework executable" ) logger.debug("Monkey patching pip...") monkey_patch() if callable(pip_main): ret_code = pip_main() else: ret_code = pip_main.main() sys.exit(ret_code)
def self_update(version: str) -> None: """Update projector-installer""" args = ['install', f'projector-installer=={version}', '--upgrade'] proxy = environ.get('http_proxy') if proxy: args.append('--proxy') args.append(proxy) if is_user_install(): args.append('--user') try: pip_main(args) except NameError: print_self_update_warning()
def exploit_prompt(self, cls): exploit_args_dict = {arg: None for arg in cls.args.keys()} exploit_menu_dict = { "help": None, "options": None, "info": None, "set": exploit_args_dict, "unset": exploit_args_dict, "sh": None, "check": None, "run": None, "depends": None, "get": None, "cls": None, "back": None, "exit": None } exploits_help_menu = { "help": "show this help message", "options": "show exploit options", "info": "show general exploit information", "set": "set value", "unset": "unset value", "sh": "run shell command on local system", "check": "check if target is vulnerable", "run": "run exploit", "depends": "shows the dependencies needed for this exploit", "get": "install exploit dependencies", "cls": "clear screen", "back": "go back to previous menu", "exit": "exit program" } exploit_menu = NestedCompleter.from_nested_dict(exploit_menu_dict) message = [("class:prompt", cls.prompt)] while True: try: selected = self.session.prompt( message, style=self.style, completer=exploit_menu, complete_while_typing=False ).strip() except KeyboardInterrupt: print("[!!]::press (CTRL+D) to exit") continue except EOFError: print("❌ Goodbye ❌") exit(1) if selected == "": continue elif selected == "help": table = tabulate( [[k, v] for k, v in exploits_help_menu.items()], headers=["Command", "Description"], tablefmt="fancy_grid") print(table) elif selected == "options": table = tabulate( [[arg, cls.__dict__[arg]] for arg in cls.args.keys()], headers=["Argument", "Value"], tablefmt="fancy_grid") print(table) elif selected == "info": table = tabulate([[k, v] for k, v in cls.info.items()], headers=["Key", "Value"], tablefmt="fancy_grid") print(table) elif selected.startswith("unset"): cls.__dict__[selected.split()[-1].strip()] = "N/a" elif selected.startswith("set"): selected = selected.split() if len(selected) < 2: print("[!!]::the `set` command must be proceeded with an argument and value") print("\nexample:\n\tset url http://localhost:8080") continue arg, val = selected[1].strip(), " ".join(selected[2:]) cls.__dict__[arg] = val elif selected == "check": try: cls.check() except NotImplementedError: print(f"[!!]::```{cls.__class__.__name__}``` exploit has no check function") elif selected == "run": all_set = True for arg, values in cls.args.items(): if values["required"] and ( not cls.__dict__[arg] or cls.__dict__[arg].lower() == "n/a"): print("!"*70) print(f"``{arg}`` must be set before running this exploit") all_set = False if all_set: try: cls.run() except NotImplementedError: print("[XX]::This exploits `run` function has not been implemented") except ImportError: print("[!!]::an import error occured. Run command, `depends`, to get script dependencies") print("[**]::then run the command, `get`, to install the required dependencies") except Exception as e: print(f"[ERROR]::{e}") elif selected == "depends": if cls.pip_dependencies: print("[************ Dependencies *************]") for dependency in cls.pip_dependencies: print(f"\t\u2022 {dependency}") else: print("[!!]::exploit has no dependencies") elif selected == "get": if cls.pip_dependencies: print("[**]::fetching pip dependencies") from pip._internal.cli.main import main as pip_main [pip_main(["install", pkg]) for pkg in cls.pip_dependencies] print("\n[**]::pip dependencies successfully installed") print("[!!]::try re-running the exploit!!!") else: print("[NOTE]::this module does not require any pip dependencies") elif selected.startswith("sh"): cmd = selected.split()[1:] if cmd: try: out = sh(cmd, capture_output=True).stdout except: cmd = ' '.join(cmd) print(f"[XX]::unable to run command: `{cmd}`") continue try: print(out.decode("utf8")) except UnicodeDecodeError: print("[XX]::unable to decode command output!") continue else: print("[!!]::`sh` command used but no shell command was specified") elif selected == "cls": print("\n"*75) elif selected == "back": break elif selected == "exit": print("❌ Goodbye ❌") exit(0) else: print(f"[XX]::`{selected}` is not a valid command! Type `help` for help menu")