cryptosploit_modules
All the modules are made for encryption/decryption/attacking various cryptographic algorithms or encodings.
You can find here any other modules with additional functionality related to cryptography.
In fact, it is a big library of cryptograhic tools, you don't need in a big folder with gigabytes of cryptographic tools. Everything you need can be found here.
Cryptosploit aims to be a tool to automate a lot of routine work with various scripts.
View Source
0from abc import ABCMeta, abstractmethod 1from dataclasses import dataclass 2from json import load 3from os import environ 4from os.path import dirname, join, exists, isfile 5from subprocess import Popen, PIPE 6from sys import modules, stdin 7from tabulate import tabulate 8 9from cryptosploit.cprint import Printer, colorize_strings, SGR 10from cryptosploit.exceptions import ModuleError, ArgError 11 12 13@dataclass() 14class Variable: 15 value: str = "" 16 description: str = "" 17 18 19class Environment: 20 """Class for working with module variables.""" 21 22 def __init__(self, config_path): 23 self.__vars = dict() 24 self.__load_config(config_path) 25 26 def __str__(self): 27 headers = [ 28 colorize_strings( 29 "Name", fg=SGR.COLOR.FOREGROUND.CYAN, styles=[SGR.STYLES.BOLD] 30 ), 31 colorize_strings( 32 "Value", fg=SGR.COLOR.FOREGROUND.CYAN, styles=[SGR.STYLES.BOLD] 33 ), 34 colorize_strings( 35 "Description", fg=SGR.COLOR.FOREGROUND.CYAN, styles=[SGR.STYLES.BOLD] 36 ), 37 ] 38 items = [ 39 [ 40 colorize_strings(name, fg=SGR.COLOR.FOREGROUND.YELLOW), 41 colorize_strings( 42 "' '" 43 if var.value == " " 44 else var.value 45 if len(var.value) <= 30 46 else var.value[:30] + "...", 47 fg=SGR.COLOR.FOREGROUND.YELLOW, 48 ), 49 colorize_strings( 50 *var.description.split("\n"), 51 fg=SGR.COLOR.FOREGROUND.YELLOW, 52 sep="\n", 53 ), 54 ] 55 for name, var in self.__vars.items() 56 ] 57 return tabulate(items, headers, tablefmt="fancy_grid") 58 59 def __contains__(self, item): 60 return item in self.__vars 61 62 def __iter__(self): 63 return iter(self.__vars.keys()) 64 65 @staticmethod 66 def check_var(name: str, value: str) -> tuple[bool, str]: 67 isvalid_var: bool = True 68 error_message: str = "" 69 return isvalid_var, error_message 70 71 def get_var(self, name) -> Variable: 72 """Getting a module-defined variable""" 73 if name in self.__vars: 74 return self.__vars[name] 75 raise ArgError("No such variable") 76 77 def set_var(self, name: str, value: str) -> None: 78 """Setting a module-defined variable""" 79 if name in self.__vars: 80 isvalid, error_msg = self.check_var(name, value) 81 if isvalid: 82 self.__vars[name].value = value 83 else: 84 raise ArgError(error_msg) 85 else: 86 raise ArgError("No such variable") 87 88 def __load_config(self, config_path): 89 with open(config_path) as f: 90 for name, params in load(f).items(): 91 self.__vars[name] = Variable(**params) 92 93 94class BaseModule(metaclass=ABCMeta): 95 def __init__(self): 96 self.path = modules[self.__class__.__module__].__file__ 97 self.env = self.__load() 98 self.proc: Popen | None = None 99 100 @staticmethod 101 def check_file(filename) -> tuple[bool, str]: 102 """Check existence of file""" 103 if isfile(filename): 104 return True, "" 105 return False, "Not a file" 106 107 def kill_proc(self): 108 if self.proc: 109 self.proc.terminate() 110 self.proc.kill() 111 self.proc = None 112 113 def command_exec(self, command, env=dict()) -> None: 114 """Print output of executed shell command to console""" 115 Printer.exec(f"Executing '{command}'") 116 self.proc = Popen( 117 command, 118 stderr=PIPE, 119 stdin=stdin, 120 shell=True, 121 universal_newlines=True, 122 env=dict(**environ, **env), 123 ) 124 for line in iter(self.proc.stderr.readline, ""): 125 print(line, "\n") 126 self.proc.stderr.close() 127 128 def __load(self) -> Environment: 129 """Load config with module variables""" 130 directory = dirname(self.path) 131 config_path = join(directory, "config.json") 132 if exists(config_path): 133 env = Environment(config_path) 134 return env 135 raise ModuleError(f"No such file: {config_path}") 136 137 @abstractmethod 138 def run(self) -> None: 139 """ 140 Required to be overridden in the child class. 141 Function called by the user 142 """
Variable(value: str = '', description: str = '')
View Source
20class Environment: 21 """Class for working with module variables.""" 22 23 def __init__(self, config_path): 24 self.__vars = dict() 25 self.__load_config(config_path) 26 27 def __str__(self): 28 headers = [ 29 colorize_strings( 30 "Name", fg=SGR.COLOR.FOREGROUND.CYAN, styles=[SGR.STYLES.BOLD] 31 ), 32 colorize_strings( 33 "Value", fg=SGR.COLOR.FOREGROUND.CYAN, styles=[SGR.STYLES.BOLD] 34 ), 35 colorize_strings( 36 "Description", fg=SGR.COLOR.FOREGROUND.CYAN, styles=[SGR.STYLES.BOLD] 37 ), 38 ] 39 items = [ 40 [ 41 colorize_strings(name, fg=SGR.COLOR.FOREGROUND.YELLOW), 42 colorize_strings( 43 "' '" 44 if var.value == " " 45 else var.value 46 if len(var.value) <= 30 47 else var.value[:30] + "...", 48 fg=SGR.COLOR.FOREGROUND.YELLOW, 49 ), 50 colorize_strings( 51 *var.description.split("\n"), 52 fg=SGR.COLOR.FOREGROUND.YELLOW, 53 sep="\n", 54 ), 55 ] 56 for name, var in self.__vars.items() 57 ] 58 return tabulate(items, headers, tablefmt="fancy_grid") 59 60 def __contains__(self, item): 61 return item in self.__vars 62 63 def __iter__(self): 64 return iter(self.__vars.keys()) 65 66 @staticmethod 67 def check_var(name: str, value: str) -> tuple[bool, str]: 68 isvalid_var: bool = True 69 error_message: str = "" 70 return isvalid_var, error_message 71 72 def get_var(self, name) -> Variable: 73 """Getting a module-defined variable""" 74 if name in self.__vars: 75 return self.__vars[name] 76 raise ArgError("No such variable") 77 78 def set_var(self, name: str, value: str) -> None: 79 """Setting a module-defined variable""" 80 if name in self.__vars: 81 isvalid, error_msg = self.check_var(name, value) 82 if isvalid: 83 self.__vars[name].value = value 84 else: 85 raise ArgError(error_msg) 86 else: 87 raise ArgError("No such variable") 88 89 def __load_config(self, config_path): 90 with open(config_path) as f: 91 for name, params in load(f).items(): 92 self.__vars[name] = Variable(**params)
Class for working with module variables.
View Source
Getting a module-defined variable
View Source
78 def set_var(self, name: str, value: str) -> None: 79 """Setting a module-defined variable""" 80 if name in self.__vars: 81 isvalid, error_msg = self.check_var(name, value) 82 if isvalid: 83 self.__vars[name].value = value 84 else: 85 raise ArgError(error_msg) 86 else: 87 raise ArgError("No such variable")
Setting a module-defined variable
View Source
95class BaseModule(metaclass=ABCMeta): 96 def __init__(self): 97 self.path = modules[self.__class__.__module__].__file__ 98 self.env = self.__load() 99 self.proc: Popen | None = None 100 101 @staticmethod 102 def check_file(filename) -> tuple[bool, str]: 103 """Check existence of file""" 104 if isfile(filename): 105 return True, "" 106 return False, "Not a file" 107 108 def kill_proc(self): 109 if self.proc: 110 self.proc.terminate() 111 self.proc.kill() 112 self.proc = None 113 114 def command_exec(self, command, env=dict()) -> None: 115 """Print output of executed shell command to console""" 116 Printer.exec(f"Executing '{command}'") 117 self.proc = Popen( 118 command, 119 stderr=PIPE, 120 stdin=stdin, 121 shell=True, 122 universal_newlines=True, 123 env=dict(**environ, **env), 124 ) 125 for line in iter(self.proc.stderr.readline, ""): 126 print(line, "\n") 127 self.proc.stderr.close() 128 129 def __load(self) -> Environment: 130 """Load config with module variables""" 131 directory = dirname(self.path) 132 config_path = join(directory, "config.json") 133 if exists(config_path): 134 env = Environment(config_path) 135 return env 136 raise ModuleError(f"No such file: {config_path}") 137 138 @abstractmethod 139 def run(self) -> None: 140 """ 141 Required to be overridden in the child class. 142 Function called by the user 143 """
View Source
Check existence of file
View Source
114 def command_exec(self, command, env=dict()) -> None: 115 """Print output of executed shell command to console""" 116 Printer.exec(f"Executing '{command}'") 117 self.proc = Popen( 118 command, 119 stderr=PIPE, 120 stdin=stdin, 121 shell=True, 122 universal_newlines=True, 123 env=dict(**environ, **env), 124 ) 125 for line in iter(self.proc.stderr.readline, ""): 126 print(line, "\n") 127 self.proc.stderr.close()
Print output of executed shell command to console