cryptosploit_modules.hashes.cracker
View Source
0from cryptosploit_modules import BaseModule 1from cryptosploit.exceptions import ModuleError, ArgError 2from os.path import exists 3from sys import path 4 5from .hash_identifier import identify_hash, prettify_hash_info 6 7 8class Cracker(BaseModule): 9 allowed_crackers: tuple[str, str] = ("hashcat", "john") 10 11 def __init__(self): 12 super().__init__() 13 self.env.check_var = self.check_var 14 self.last_hash_file: str | None = None 15 self.hash_types: dict | None = None 16 17 @staticmethod 18 def check_var(name, value): 19 match name: 20 case "default_cracker": 21 if value in Cracker.allowed_crackers: 22 return True, "" 23 return False, f"Possible values: hashcat/john" 24 25 case "hash_file" | "wordlist": 26 return BaseModule.check_file(value) 27 28 case "mode": 29 for i in ("crack", "help", "advanced"): 30 if value == i: 31 return True, "" 32 return False, f"Possible values: crack/help/advanced" 33 34 case "path_to_binary": 35 if exists(value): 36 for i in Cracker.allowed_crackers: 37 if i in value: 38 return True, "" 39 return False, "Must contain hashcat/john" 40 return False, "No such path!" 41 42 case "identify_hash_type": 43 if value.lower() in ("true", "false"): 44 return True, "" 45 return False, "Possible values: true/false" 46 47 case _: 48 return True, "" 49 50 def command_generator(self): 51 """Generate path to binary""" 52 return ( 53 self.env.get_var("path_to_binary").value 54 or self.env.get_var("default_cracker").value 55 ) 56 57 def help_command(self): 58 return self.command_generator() + " --help" 59 60 def crack_command(self): 61 hash_mode = self.env.get_var("hash_mode").value 62 hash_file = self.env.get_var("hash_file").value 63 wordlist = self.env.get_var("wordlist").value 64 extra_flags = self.env.get_var("extra_flags").value.strip() 65 identify_mode = self.env.get_var("identify_hash_type").value 66 67 if hash_file and wordlist: 68 command = self.command_generator() 69 70 if identify_mode.lower() == "true": 71 72 if self.last_hash_file != hash_file: 73 self.last_hash_file = hash_file 74 self.hash_types = identify_hash(hash_file) 75 print(*prettify_hash_info(self.hash_types)) 76 key = next(iter(self.hash_types)) 77 hash_mode = ( 78 self.hash_types[key][0]["hashcat"] 79 if "hashcat" in command 80 else self.hash_types[key][0]["john"] 81 ) 82 del self.hash_types[key][0] 83 if hash_mode != "": 84 if "hashcat" in command: 85 command += f" -a 0 -m {hash_mode} {hash_file} {wordlist}" 86 else: 87 command += ( 88 f" --format={hash_mode} --wordlist={wordlist} {hash_file}" 89 ) 90 return command + " " + extra_flags 91 92 raise ArgError("Not enough variables to crack.") 93 94 def advanced_command(self): 95 flags = " " + self.env.get_var("extra_flags").value 96 if flags: 97 return self.command_generator() + flags 98 else: 99 raise ArgError("Variable 'extra_flags' must be set") 100 101 def run(self): 102 func = getattr(self, self.env.get_var("mode").value + "_command") 103 command = func() 104 self.command_exec( 105 command, 106 {"PYTHONPATH": ":".join(path)} 107 ) 108 109 110module = Cracker
View Source
9class Cracker(BaseModule): 10 allowed_crackers: tuple[str, str] = ("hashcat", "john") 11 12 def __init__(self): 13 super().__init__() 14 self.env.check_var = self.check_var 15 self.last_hash_file: str | None = None 16 self.hash_types: dict | None = None 17 18 @staticmethod 19 def check_var(name, value): 20 match name: 21 case "default_cracker": 22 if value in Cracker.allowed_crackers: 23 return True, "" 24 return False, f"Possible values: hashcat/john" 25 26 case "hash_file" | "wordlist": 27 return BaseModule.check_file(value) 28 29 case "mode": 30 for i in ("crack", "help", "advanced"): 31 if value == i: 32 return True, "" 33 return False, f"Possible values: crack/help/advanced" 34 35 case "path_to_binary": 36 if exists(value): 37 for i in Cracker.allowed_crackers: 38 if i in value: 39 return True, "" 40 return False, "Must contain hashcat/john" 41 return False, "No such path!" 42 43 case "identify_hash_type": 44 if value.lower() in ("true", "false"): 45 return True, "" 46 return False, "Possible values: true/false" 47 48 case _: 49 return True, "" 50 51 def command_generator(self): 52 """Generate path to binary""" 53 return ( 54 self.env.get_var("path_to_binary").value 55 or self.env.get_var("default_cracker").value 56 ) 57 58 def help_command(self): 59 return self.command_generator() + " --help" 60 61 def crack_command(self): 62 hash_mode = self.env.get_var("hash_mode").value 63 hash_file = self.env.get_var("hash_file").value 64 wordlist = self.env.get_var("wordlist").value 65 extra_flags = self.env.get_var("extra_flags").value.strip() 66 identify_mode = self.env.get_var("identify_hash_type").value 67 68 if hash_file and wordlist: 69 command = self.command_generator() 70 71 if identify_mode.lower() == "true": 72 73 if self.last_hash_file != hash_file: 74 self.last_hash_file = hash_file 75 self.hash_types = identify_hash(hash_file) 76 print(*prettify_hash_info(self.hash_types)) 77 key = next(iter(self.hash_types)) 78 hash_mode = ( 79 self.hash_types[key][0]["hashcat"] 80 if "hashcat" in command 81 else self.hash_types[key][0]["john"] 82 ) 83 del self.hash_types[key][0] 84 if hash_mode != "": 85 if "hashcat" in command: 86 command += f" -a 0 -m {hash_mode} {hash_file} {wordlist}" 87 else: 88 command += ( 89 f" --format={hash_mode} --wordlist={wordlist} {hash_file}" 90 ) 91 return command + " " + extra_flags 92 93 raise ArgError("Not enough variables to crack.") 94 95 def advanced_command(self): 96 flags = " " + self.env.get_var("extra_flags").value 97 if flags: 98 return self.command_generator() + flags 99 else: 100 raise ArgError("Variable 'extra_flags' must be set") 101 102 def run(self): 103 func = getattr(self, self.env.get_var("mode").value + "_command") 104 command = func() 105 self.command_exec( 106 command, 107 {"PYTHONPATH": ":".join(path)} 108 )
View Source
18 @staticmethod 19 def check_var(name, value): 20 match name: 21 case "default_cracker": 22 if value in Cracker.allowed_crackers: 23 return True, "" 24 return False, f"Possible values: hashcat/john" 25 26 case "hash_file" | "wordlist": 27 return BaseModule.check_file(value) 28 29 case "mode": 30 for i in ("crack", "help", "advanced"): 31 if value == i: 32 return True, "" 33 return False, f"Possible values: crack/help/advanced" 34 35 case "path_to_binary": 36 if exists(value): 37 for i in Cracker.allowed_crackers: 38 if i in value: 39 return True, "" 40 return False, "Must contain hashcat/john" 41 return False, "No such path!" 42 43 case "identify_hash_type": 44 if value.lower() in ("true", "false"): 45 return True, "" 46 return False, "Possible values: true/false" 47 48 case _: 49 return True, ""
View Source
Generate path to binary
View Source
61 def crack_command(self): 62 hash_mode = self.env.get_var("hash_mode").value 63 hash_file = self.env.get_var("hash_file").value 64 wordlist = self.env.get_var("wordlist").value 65 extra_flags = self.env.get_var("extra_flags").value.strip() 66 identify_mode = self.env.get_var("identify_hash_type").value 67 68 if hash_file and wordlist: 69 command = self.command_generator() 70 71 if identify_mode.lower() == "true": 72 73 if self.last_hash_file != hash_file: 74 self.last_hash_file = hash_file 75 self.hash_types = identify_hash(hash_file) 76 print(*prettify_hash_info(self.hash_types)) 77 key = next(iter(self.hash_types)) 78 hash_mode = ( 79 self.hash_types[key][0]["hashcat"] 80 if "hashcat" in command 81 else self.hash_types[key][0]["john"] 82 ) 83 del self.hash_types[key][0] 84 if hash_mode != "": 85 if "hashcat" in command: 86 command += f" -a 0 -m {hash_mode} {hash_file} {wordlist}" 87 else: 88 command += ( 89 f" --format={hash_mode} --wordlist={wordlist} {hash_file}" 90 ) 91 return command + " " + extra_flags 92 93 raise ArgError("Not enough variables to crack.")
View Source
Required to be overridden in the child class. Function called by the user
Inherited Members
View Source
9class Cracker(BaseModule): 10 allowed_crackers: tuple[str, str] = ("hashcat", "john") 11 12 def __init__(self): 13 super().__init__() 14 self.env.check_var = self.check_var 15 self.last_hash_file: str | None = None 16 self.hash_types: dict | None = None 17 18 @staticmethod 19 def check_var(name, value): 20 match name: 21 case "default_cracker": 22 if value in Cracker.allowed_crackers: 23 return True, "" 24 return False, f"Possible values: hashcat/john" 25 26 case "hash_file" | "wordlist": 27 return BaseModule.check_file(value) 28 29 case "mode": 30 for i in ("crack", "help", "advanced"): 31 if value == i: 32 return True, "" 33 return False, f"Possible values: crack/help/advanced" 34 35 case "path_to_binary": 36 if exists(value): 37 for i in Cracker.allowed_crackers: 38 if i in value: 39 return True, "" 40 return False, "Must contain hashcat/john" 41 return False, "No such path!" 42 43 case "identify_hash_type": 44 if value.lower() in ("true", "false"): 45 return True, "" 46 return False, "Possible values: true/false" 47 48 case _: 49 return True, "" 50 51 def command_generator(self): 52 """Generate path to binary""" 53 return ( 54 self.env.get_var("path_to_binary").value 55 or self.env.get_var("default_cracker").value 56 ) 57 58 def help_command(self): 59 return self.command_generator() + " --help" 60 61 def crack_command(self): 62 hash_mode = self.env.get_var("hash_mode").value 63 hash_file = self.env.get_var("hash_file").value 64 wordlist = self.env.get_var("wordlist").value 65 extra_flags = self.env.get_var("extra_flags").value.strip() 66 identify_mode = self.env.get_var("identify_hash_type").value 67 68 if hash_file and wordlist: 69 command = self.command_generator() 70 71 if identify_mode.lower() == "true": 72 73 if self.last_hash_file != hash_file: 74 self.last_hash_file = hash_file 75 self.hash_types = identify_hash(hash_file) 76 print(*prettify_hash_info(self.hash_types)) 77 key = next(iter(self.hash_types)) 78 hash_mode = ( 79 self.hash_types[key][0]["hashcat"] 80 if "hashcat" in command 81 else self.hash_types[key][0]["john"] 82 ) 83 del self.hash_types[key][0] 84 if hash_mode != "": 85 if "hashcat" in command: 86 command += f" -a 0 -m {hash_mode} {hash_file} {wordlist}" 87 else: 88 command += ( 89 f" --format={hash_mode} --wordlist={wordlist} {hash_file}" 90 ) 91 return command + " " + extra_flags 92 93 raise ArgError("Not enough variables to crack.") 94 95 def advanced_command(self): 96 flags = " " + self.env.get_var("extra_flags").value 97 if flags: 98 return self.command_generator() + flags 99 else: 100 raise ArgError("Variable 'extra_flags' must be set") 101 102 def run(self): 103 func = getattr(self, self.env.get_var("mode").value + "_command") 104 command = func() 105 self.command_exec( 106 command, 107 {"PYTHONPATH": ":".join(path)} 108 )
View Source
18 @staticmethod 19 def check_var(name, value): 20 match name: 21 case "default_cracker": 22 if value in Cracker.allowed_crackers: 23 return True, "" 24 return False, f"Possible values: hashcat/john" 25 26 case "hash_file" | "wordlist": 27 return BaseModule.check_file(value) 28 29 case "mode": 30 for i in ("crack", "help", "advanced"): 31 if value == i: 32 return True, "" 33 return False, f"Possible values: crack/help/advanced" 34 35 case "path_to_binary": 36 if exists(value): 37 for i in Cracker.allowed_crackers: 38 if i in value: 39 return True, "" 40 return False, "Must contain hashcat/john" 41 return False, "No such path!" 42 43 case "identify_hash_type": 44 if value.lower() in ("true", "false"): 45 return True, "" 46 return False, "Possible values: true/false" 47 48 case _: 49 return True, ""
View Source
Generate path to binary
View Source
61 def crack_command(self): 62 hash_mode = self.env.get_var("hash_mode").value 63 hash_file = self.env.get_var("hash_file").value 64 wordlist = self.env.get_var("wordlist").value 65 extra_flags = self.env.get_var("extra_flags").value.strip() 66 identify_mode = self.env.get_var("identify_hash_type").value 67 68 if hash_file and wordlist: 69 command = self.command_generator() 70 71 if identify_mode.lower() == "true": 72 73 if self.last_hash_file != hash_file: 74 self.last_hash_file = hash_file 75 self.hash_types = identify_hash(hash_file) 76 print(*prettify_hash_info(self.hash_types)) 77 key = next(iter(self.hash_types)) 78 hash_mode = ( 79 self.hash_types[key][0]["hashcat"] 80 if "hashcat" in command 81 else self.hash_types[key][0]["john"] 82 ) 83 del self.hash_types[key][0] 84 if hash_mode != "": 85 if "hashcat" in command: 86 command += f" -a 0 -m {hash_mode} {hash_file} {wordlist}" 87 else: 88 command += ( 89 f" --format={hash_mode} --wordlist={wordlist} {hash_file}" 90 ) 91 return command + " " + extra_flags 92 93 raise ArgError("Not enough variables to crack.")
View Source
Required to be overridden in the child class. Function called by the user