Esempio n. 1
0
    def benchmark(self,  slurm=None):
        """
        Run john benchmark
        """
        #import pdb; pdb.set_trace()
        if self.enable:
            #cmd2.Cmd.poutput(f"Performing John Benchmark.")
            #print_status(f"Performing John Benchmark.")
            if slurm and slurm.partition:
                parallel_job_type = slurm.parallel_job_parser()
                if not  parallel_job_type in ["MPI", "OMP"]:
                    raise InvalidParallelJob(parallel_job_type)

                attack_cmd = f"{self.main_exec} --test"
                if parallel_job_type == "MPI":
                    attack_cmd = f"srun --mpi={slurm.pmix} "  + attack_cmd


                elif parallel_job_type == "OMP":
                    attack_cmd = f"srun "  + attack_cmd

                header_attack = f"echo -e \"\\n\\n[*] Running: {attack_cmd}\""

                parallel_work = [(header_attack, attack_cmd)]
                batch_script_name = slurm.gen_batch_script(parallel_work)

                Bash.exec(f"sbatch {batch_script_name}")

            else:
                attack_cmd = f"{self.main_exec} --test"
                print_status("Running: {ColorStr(attack_cmd).StyleBRIGHT}")
                Bash.exec(attack_cmd)
        else:
            print_failure(f"Cracker {ColorStr(self.main_name).StyleBRIGHT} is disable")
Esempio n. 2
0
    def exist(self, workspace=None):
        """
        Check if a workspace exist or not

        Return:
          return True if workspace exist otherwise return False
        """
        #import pdb; pdb.set_trace()
        if workspace:
            cur = None
            try:
                # checking if switch workspace exist
                cur = self._cmd.db_conn.cursor()
                cur.execute("SELECT name FROM workspaces")
                self._cmd.db_conn.commit()

                for workspaceName, *_ in cur.fetchall():
                    if workspaceName == workspace:
                        return True
                return False

            except (Exception, psycopg2.DatabaseError) as error:
                #cmd2.Cmd.pexcept(error)
                print_failure(error)
                return False #check if this return work or if it's useless

            finally:
                if cur is not None:
                    cur.close()
        else:
            #cmd2.Cmd.pwarning("No workspace selected")
            print_failure("No workspace selected")
            return False
Esempio n. 3
0
    def attack(self,
               local: bool = False,
               force: bool = False,
               pre_attack_output: Any = None,
               db_status: bool = False,
               workspace: str = None,
               db_credential_file: Path = None):
        """
        Wordlist attack using John the Ripper with HashId as pre attack module

        Args:
           local (bool): if local is True run attack localy otherwise
                         submiting parallel tasks in a cluster using slurm
        """
        #import pdb; pdb.set_trace()
        try:
            if not force:
                self.no_empty_required_options(local)

            jtr = John()

            hash_types = self.most_probably_hash_identities(pre_attack_output)

            jtr.single_attack(hash_types=hash_types,
                              hashes_file=self.options['hashes_file'].value,
                              slurm=self.slurm,
                              local=local,
                              db_status=db_status,
                              workspace=workspace,
                              db_credential_file=db_credential_file)

        except Exception as error:
            print_failure(error)
Esempio n. 4
0
    def run(self, quiet:bool = False):

        #import pdb; pdb.set_trace()
        try:

            self.no_empty_required_options()

            if self.options['charsets'].value:
                charsets = [charset for charset in self.options['charsets'].value.split(',')]
            else:
                charsets = None

            if self.options['simple_masks'].value:
                simple_masks = [simplemask for simplemask in self.options['simple_masks'].value.split(',')]
            else:
                simple_masks = None

            Pack.statsgen(wordlist = self.options['wordlist'].value,
                          min_length = self.options['min_length'].value,
                          max_length = self.options['max_length'].value,
                          charsets = charsets,
                          simple_masks = simple_masks,
                          output = self.options['output'].value,
                          hiderare = self.options['hiderare'].value,
                          quiet = quiet)

        except Exception as error:
            print_failure(error)
Esempio n. 5
0
    def search_hashes(self,
                      hashes_file: str,
                      *,
                      timeout: int,
                      greppable: bool = False):
        """
        search each hash in hashes_file in all the availables online cracking APIs
        """

        #import pdb; pdb.set_trace()

        try:
            if self.enable:
                permission = [os.R_OK]
                Path.access(permission, hashes_file)

                sth_cmd = f"{self.main_exec} --no-banner --accessible"

                if isinstance(timeout, int) and timeout > 0:
                    sth_cmd += f"--timeout {timeout}"

                sth_cmd += f" --file {hashes_file}"

                print_status(
                    f"Searching hashes in {hashes_file} file in availables online cracking APIs"
                )
                Bash.exec(sth_cmd)

            else:
                print_failure("Auxliary plugin {self.main_name} is disable")

        except Exception as error:
            print_failure(error)
Esempio n. 6
0
    def search_hash(self,
                    query_hash: str,
                    *,
                    timeout: int,
                    greppable: bool = False):
        """
        search an hash in all the availables online cracking APIs
        """

        #import pdb; pdb.set_trace()

        if self.enable:
            sth_cmd = f"{self.main_exec} --no-banner --accessible"

            if isinstance(timeout, int) and timeout > 0:
                sth_cmd += f"--timeout {timeout}"

            sth_cmd += f" --text {query_hash}"

            print_status(
                f"Searching {query_hash} hash in availables online cracking APIs"
            )
            Bash.exec(sth_cmd)

        else:
            print_failure("Auxliary plugin {self.main_name} is disable")
Esempio n. 7
0
    def statsgen(*, wordlist: str, output: str = None,
                 min_length:int = None, max_length: int = None,
                 simple_masks: List[str] = None, charsets: List[str] = None,
                 quiet: bool = True, hiderare: int = 0):

        #import pdb; pdb.set_trace()
        try:
            permission = [os.R_OK]
            Path.access(permission, wordlist)

            statsgen = StatsGen(wordlist = wordlist,
                                output = output,
                                minlength = min_length,
                                maxlength = max_length,
                                simplemasks = simple_masks,
                                charsets = charsets,
                                quiet = quiet,
                                hiderare = hiderare)


            if not quiet:
                print(Pack.STATSGEN_BANNER)

            print(f"[*] Analyzing passwords in {wordlist}")

            statsgen.generate_stats()
            statsgen.print_stats()

        except Exception as error:
            print_failure(error)
Esempio n. 8
0
    def attack(self,
               local: bool = False,
               force: bool = False,
               pre_attack_output: Any = None,
               db_status: bool = False,
               workspace: str = None,
               db_credential_file: Path = None,
               cracker_main_exec: Path = None):
        """
        John the Ripper benchmark

        Args:
           local (bool): if local is True run attack localy otherwise
                         submiting parallel tasks in a cluster using slurm
        """
        #import pdb; pdb.set_trace()
        try:
            if not force:
                self.no_empty_required_options(local)

            if cracker_main_exec:
                jtr = John(john_exec=cracker_main_exec)
            else:
                jtr = John()

            if local:
                jtr.benchmark(slurm=None)

            else:
                jtr.benchmark(slurm=self.slurm)

        except Exception as error:
            print_failure(error)
Esempio n. 9
0
    def attack(self,
               local=False,
               force: bool = False,
               pre_attack_output: Any = None):
        """
        Masks attack using John the Ripper
        Args:
          local (bool): try to perform the attack locally
        """
        #import pdb;pdb.set_trace()
        try:
            if not force:
                self.no_empty_required_options(local)

            jtr = John()

            hash_types = self.options['hash_type'].value.split(',')

            masks_file = pre_attack_output  # name of masks file

            jtr.masks_attack(
                hash_types=hash_types,
                hashes_file=self.options['hashes_file'].value,
                masks_file=masks_file,
                masks_attack_script=self.options['masks_attack'].value,
                slurm=self.slurm,
                local=local)

        except Exception as error:
            print_failure(error)
Esempio n. 10
0
    def attack(self, *, local:bool = False, force:bool = False, pre_attack_output: Any = None,
               db_status:bool = False, workspace:str = None, db_credential_file: Path = None,
               cracker_main_exec:Path = None):
        """
        Incremental attack using John the Ripper
        """

        #import pdb; pdb.set_trace()
        try:
            if not force:
                self.no_empty_required_options(local)

            if cracker_main_exec:
                jtr = John(john_exec=cracker_main_exec)
            else:
                jtr = John()

            hash_types = self.options['hash_type'].value.split(',')

            jtr.incremental_attack(hash_types = hash_types,
                                   hashes_file = self.options['hashes_file'].value,
                                   slurm = self.slurm,
                                   local = local,
                                   db_status= db_status,
                                   workspace= workspace,
                                   db_credential_file=db_credential_file)

        except Exception as error:
            print_failure(error)
Esempio n. 11
0
    def run(self, quiet: bool = False):
        """
        Execution of Cupp interactive mode
        """

        #import pdb; pdb.set_trace()
        try:
            self.no_empty_required_options()
            cewl = Cewlplugin()

            cewl.spider(
                self.options['url'].value,
                depth=self.options['depth'].value,
                min_length=self.options['min_length'].value,
                offsite=self.options['offsite'].value,
                exclude=self.options['exclude'].value,
                allowed=self.options['allowed'].value,
                write=self.options['write'].value,
                lowercase=self.options['lowercase'].value,
                with_numbers=self.options['with_numbers'].value,
                convert_umlauts=self.options['convert_umlauts'].value,
                meta=self.options['meta'].value,
                meta_file=self.options['meta_file'].value,
                email=self.options['email'].value,
                email_file=self.options['email_file'].value,
                count=self.options['count'].value,
                verbose=self.options['verbose'].value,
                debug=self.options['debug'].value,
            )

            return self.options['write'].value

        except Exception as error:
            print_failure(error)
Esempio n. 12
0
    def run(self, quiet=False):

        #import pdb; pdb.set_trace()

        try:
            self.no_empty_required_options()
            output = Pack.policygen(
                output=self.options['output'].value,
                min_length=self.options['min_length'].value,
                max_length=self.options['max_length'].value,
                min_digit=self.options['min_digit'].value,
                max_digit=self.options['max_digit'].value,
                min_upper=self.options['min_upper'].value,
                max_upper=self.options['max_upper'].value,
                min_lower=self.options['min_lower'].value,
                max_lower=self.options['max_lower'].value,
                min_special=self.options['min_special'].value,
                max_special=self.options['max_special'].value,
                show_masks=self.options['show_masks'].value,
                quietRun=quiet)

            return output

        except Exception as error:
            print_failure(error)
Esempio n. 13
0
def main():
    try:
        parser = amadb_parser()
        args = parser.parse_args()
        workspace = args.workspace
        credentials_file = Path(args.creds_file)
        cracker = args.cracker
        if args.insert_hashes and cracker in [John.MAINNAME, Hashcat.MAINNAME]:
            hashes_file = Path(args.insert_hashes)
            if cracker == John.MAINNAME:
                John.insert_hashes_to_db(hashes_file, workspace,
                                         credentials_file)
            elif cracker == Hashcat.MAINNAME:
                Hashcat.insert_hashes_to_db(hashes_file, workspace,
                                            credentials_file)

        elif args.insert_hashes and cracker not in [
                John.MAINNAME, Hashcat.MAINNAME
        ]:
            raise Exception(f"Cracker {args.cracker} doesn't crack hashes")

        if args.insert_services:
            print_status("Please, implement me")
            #services_file = Path(args.insert_hashes)

    except Exception as error:
        print_failure(error)
Esempio n. 14
0
    def attack(self, local:bool = False, force: bool = False, pre_attack_output: Any = None):
        """
        Wordlist attack using John the Ripper with cewl as pre attack module

        Args:
           local (bool): if local is True run attack localy otherwise
                         submiting parallel tasks in a cluster using slurm
        """
        #import pdb; pdb.set_trace()
        try:
            if not force:
                self.no_empty_required_options(local)

            jtr = John()

            wordlist = pre_attack_output
            hash_types = self.options['hash_type'].value.split(',')

            jtr.wordlist_attack(hash_types = hash_types,
                                hashes_file = self.options['hashes_file'].value,
                                wordlist = wordlist,
                                slurm = self.slurm,
                                local = local)

        except Exception as error:
            print_failure(error)
Esempio n. 15
0
    def benchmark(self, slurm, local: bool = False):
        """
        Hashcat benchmark
        """
        #import pdb; pdb.set_trace()
        if self.enable:
            if (not local) and slurm and slurm.partition:
                parallel_job_type = slurm.parallel_job_parser()
                if not parallel_job_type in ["GPU"]:
                    raise InvalidParallelJob(parallel_job_type)

                #core, extra = slurm.parameters()

                attack_cmd = f"srun {self.main_exec} -b"

                header_attack = f"echo -e '\\n\\n[*] Running: {attack_cmd}'"

                parallel_work = [(header_attack, attack_cmd)]
                batch_script_name = slurm.gen_batch_script(parallel_work)

                Bash.exec(f"sbatch {batch_script_name}")

            else:
                attack_cmd = f"{self.main_exec} -b"
                print_status(f"Running: {ColorStr(attack_cmd).StyleBRIGHT}")
                Bash.exec(attack_cmd)
        else:
            print_failure(
                f"Cracker {ColorStr(self.main_name).StyleBRIGHT} is disable")
Esempio n. 16
0
    def do_unsetg(self, args):
        """
        Unset global value of an option
        """
        selectedModule = self._cmd.selectedModule

        if selectedModule:
            option = args.option.lower()
            if selectedModule.isOption(option):
                if selectedModule.isModuleOption(option):
                    selectedModule.options[option].value = None
                else:  #is a valid slurm option
                    selectedModule.slurm.options[option].value = None
                    setattr(selectedModule.slurm, option, None)

                #delete option:value from global values
                if option in self._cmd.gvalues:
                    del self._cmd.gvalues[option]
                else:
                    print_status(
                        "{option.upper()} value is not a global value")

            else:
                print_failure(
                    f"No {option.upper()} option in {selectedModule.mname} module"
                )

        else:
            print_failure("No module selected")
Esempio n. 17
0
    def do_read(self, args):
        """
        Read a backup file and set options of a module
        """
        #import pdb; pdb.set_trace()
        try:
            selectedModule = self._cmd.selectedModule

            if not selectedModule:
                raise Exception("No module selected")

            backup_file = Path(args.backup)
            permission = [os.R_OK]
            Path.access(permission, backup_file)

            print_status(
                f"Reading {ColorStr(backup_file).StyleBRIGHT} backup file and setting {ColorStr(selectedModule.MNAME).StyleBRIGHT} options"
            )

            with open(backup_file, 'r') as backup:
                while setv_cmd := backup.readline():
                    setv_cmd = setv_cmd.rstrip()
                    split_setv_cmd = setv_cmd.split(' ')

                    if len(
                            split_setv_cmd
                    ) == 4:  # this options is of a pre/post attack module
                        setv, helper, option, value = split_setv_cmd
                        if helper in ["-pre", "--preattack"]:
                            if isinstance(selectedModule, Attack):
                                selectedModule.setv(option,
                                                    value,
                                                    pre_attack=True)
                            else:
                                print_failure(
                                    f"Unable to run {setv_cmd} command. Auxiliary modules have not PreAttack modules"
                                )

                        elif helper in ["-post", "--postattack"]:
                            if isinstance(selectedModule, Attack):
                                selectedModule.setv(option,
                                                    value,
                                                    post_attack=True)
                            else:
                                print_failure(
                                    f"Unable to run {setv_cmd} command. Auxiliary modules have not PostAttack modules"
                                )
                        else:
                            print_failure("Unknown helper module")

                    elif len(split_setv_cmd
                             ) == 3:  # this options is of the main module
                        setv, option, value = split_setv_cmd
                        selectedModule.setv(option, value)
                    else:
                        print_failure(f"Invalid command : {setv_cmd}")

        except Exception as error:
            print_failure(error)
Esempio n. 18
0
    def insert_hashes_to_db(hashes_file: Path, workspace: str, creds_file: Path, *, pretty:bool = False):
        cur = db_conn = None
        try:
            #import pdb;pdb.set_trace()
            hashes_status = John.hashes_file_status(hashes_file)
            cracked_hashes = hashes_status['cracked']

            db_credentials = Connection.dbCreds(creds_file)
            db_conn = psycopg2.connect(**db_credentials)

            cur = db_conn.cursor()

            cur.execute(f"SELECT hash from hashes_{workspace}")
            cracked_hashes_db = cur.fetchall()
            new_cracked_hashes = []  #only non-repeated cracked hashes
            for cracked_hash in cracked_hashes: # cracked_hash = (hash, type, cracked, password)
                repeated = False
                for cracked_hash_db in cracked_hashes_db: # cracked_hash_db = (cracked_hash)
                    if cracked_hash[0] == cracked_hash_db[0]:
                        repeated = True
                        break

                if not repeated:
                    new_cracked_hashes.append(cracked_hash)

            if new_cracked_hashes:

                insert_cracked_hash = (
                    f"""
                    INSERT INTO hashes_{workspace} (hash, type, cracker, password)
                    VALUES (%s, %s, %s, %s)
                    """
                )

                cur.executemany(insert_cracked_hash, new_cracked_hashes)
                if pretty:
                    print_status(f"Cracked hashes were saved to {ColorStr(workspace).StyleBRIGHT} workspace database")
                else:
                    print(f"\n[*] Cracked hashes were saved to {workspace} workspace database")

            else:
                if pretty:
                    print_status(f"No new cracked hashes to save to {ColorStr(workspace).StyleBRIGHT} workspace database")
                else:
                    print(f"\n[*] No new cracked hashes to save to {workspace} workspace database")

            db_conn.commit()
            cur.close()

        except Exception as error:
            print_failure(error)

        finally:
            if cur is not None:
                cur.close()

            if db_conn is not None:
                db_conn.close()
Esempio n. 19
0
    def __init__(self, mask):
        try:
            if Mask.isMask(mask):
                self.mask = mask
            else:
                raise InvalidMaskError(mask)

        except MaskError as error:
            print_failure(error)
Esempio n. 20
0
    def maskgen(*,
            statsgen_output: str, output: str,
            min_length: int = None, max_length: int = None,
            target_time: int = None, min_time:int = None, max_time:int = None,
            min_complexity: int = None, max_complexity: int = None,
            min_occurrence: int = None, max_occurrence: int = None,
            sorting:str = "optindex",
            check_masks: List[str] = None, check_masks_file: str = None,
            show_masks: bool = False, quiet: bool = True):

        #import pdb; pdb.set_trace()
        try:
            permission = [os.R_OK]
            Path.access(permission, statsgen_output)

            if not quiet:
                print(Pack.MASKGEN_BANNER)


            print(f"[*] Analyzing masks in {statsgen_output}")
            pps = 1000000000
            maskgen = MaskGen(
                target_time = target_time,
                output_file = output,
                minlength = min_length,
                maxlength = max_length,
                mintime = min_time,
                maxtime = max_time,
                mincomplexity = min_complexity,
                maxcomplexity = max_complexity,
                minoccurrence = min_occurrence,
                maxoccurrence = max_occurrence,
                showmasks = show_masks
            )

            print("[*] Using {:,d} keys/sec for calculations.".format(pps))

            # Load masks
            maskgen.loadmasks(statsgen_output)

            # Matching masks from the command-line
            if check_masks:
                print(f"[*] Checking coverage of the these masks [{', '.join(check_masks)}]")
                maskgen.getmaskscoverage(check_masks)

            # Matching masks from a file
            elif check_masks_file:
                checkmasksfile = open(check_masks_file, 'r')
                print("[*] Checking coverage of masks in [%s]" % check_masks_file)
                maskgen.getmaskscoverage(checkmasksfile)

            else:# Printing masks in a file
                print("[*] Sorting masks by their [%s]." % sorting)
                maskgen.generate_masks(sorting)

        except Exception as error:
            print_failure(error)
Esempio n. 21
0
    def attack(self,
               *,
               local: bool = False,
               force: bool = False,
               pre_attack_output: Any = None,
               db_status: bool = False,
               workspace: str = None,
               db_credential_file: Path = None,
               cracker_main_exec: Path = None):
        """
        Combination attack using Hashcat

        Args:
           local (bool): if local is True run attack localy otherwise
                         submiting parallel tasks in a cluster using slurm
        """

        #import pdb; pdb.set_trace()
        try:

            if not force:
                self.no_empty_required_options(local)

            if cracker_main_exec:
                hc = Hashcat(hashcat_exec=cracker_main_exec)
            else:
                hc = Hashcat()

            hash_type = None
            if isinstance(self.options['hash_type'].value, int):
                hash_types = [self.options['hash_type'].value]
            elif isinstance(self.options['hash_type'].value, str):
                hash_types = [
                    int(hash_type)
                    for hash_type in self.options['hash_type'].value.split(',')
                ]
            else:
                raise TypeError(f"Invalid type hash_type: {type(hash_type)}")

            wordlists = [
                wordlist.strip()
                for wordlist in self.options['wordlists'].value.split(',')
            ]

            hc.combination_attack(
                hash_types=hash_types,
                hashes_file=self.options['hashes_file'].value,
                wordlists=wordlists,
                slurm=self.slurm,
                sleep=self.options['sleep'].value,
                local=local,
                db_status=db_status,
                workspace=workspace,
                db_credential_file=db_credential_file)

        except Exception as error:
            print_failure(error)
Esempio n. 22
0
    def do_workspace(self, args):
        """
        Manager of workspaces
        """
        if self._cmd.db_conn is None:
            #cmd2.Cmd.pwarning("Database not connected")
            print_failure("Database not connected")
        else:
            if args.switch:
                switchWorkspace = args.switch
                self.switch(switchWorkspace)

            elif args.add or args.addswitch:
                newWorkspace = args.addswitch or args.add
                db_creds = Connection.dbCreds(self._cmd.config['db_credentials_file'])
                Workspace.init(newWorkspace, **db_creds)

                if args.addswitch:
                    self.switch(newWorkspace)

            elif args.delete:
                deleteWorkspce = args.delete
                db_creds = Connection.dbCreds(self._cmd.config['db_credentials_file'])
                self._cmd.workspace = Workspace.delete(deleteWorkspce, self._cmd.workspace,
                                                       **db_creds)

            elif args.deleteall:
                db_creds = Connection.dbCreds(self._cmd.config['db_credentials_file'])
                Workspace.deleteall(**db_creds)
                self._cmd.workspace = "default"

            elif args.rename:
                oldWorkspace = args.rename[0]
                newWorkspace = args.rename[1]
                db_creds = Connection.dbCreds(self._cmd.config['db_credentials_file'])
                Workspace.rename(oldWorkspace, newWorkspace, **db_creds)

            else: #show the availables workspaces
                try:
                    cur = self._cmd.db_conn.cursor()
                    cur.execute("SELECT name FROM workspaces")
                    self._cmd.db_conn.commit()

                    workspaces = []
                    for workspace, *_ in cur.fetchall():
                        if workspace == self._cmd.workspace:
                            selectedWorkspace = ColorStr(f"{workspace}*").ForeRED
                            workspaces.append([selectedWorkspace])
                        else:
                            workspaces.append([workspace])

                    print(tabulate(workspaces, headers=["Workspace"]))
                    cur.close()

                except Exception as error:
                    print_failure(error)
Esempio n. 23
0
    def deleteall(*, database="ama", user="******", host='localhost'):
        """
        Delete all workspaces from workspaces table
        """
        #import pdb; pdb.set_trace()

        delete = Answer.shortAnwser("Do you want to delete all your workspaces(y/n)? ")
        if delete:
            password = getpass(prompt=f"Password of {user} role: ")
            dbCredential = {'host': host, 'database': database, 'user': user, 'password': password}

            conn = None
            cur = None
            try:
                conn = psycopg2.connect(**dbCredential)
                cur = conn.cursor()

                cur.execute("SELECT name FROM workspaces")
                conn.commit()

                workspaces =  cur.fetchall()
                workspace_tables = ["hashes", "services"]
                for workspace, *_  in workspaces:
                    for table in workspace_tables:
                        cur.execute(f"DROP TABLE IF EXISTS {table}_{workspace}")

                    #delete workspace name from workspaces table
                    deleteWorkspace = (
                        f"""
                        DELETE FROM workspaces
                        WHERE name = '{workspace}'
                        """
                    )
                    cur.execute(deleteWorkspace, (workspace, ))
                    conn.commit()

                print_status(f"Workspaces were deleted")

                defaultWorkspace = "default"
                Workspace.init(defaultWorkspace, **dbCredential)

            except (Exception, psycopg2.DatabaseError) as error:
                #cmd2.Cmd.pexcept(error)
                print_failure(error)

            finally:
                if cur is not None:
                    cur.close()

                if conn is not None:
                    conn.close()

        else:
            #cmd2.Cmd.poutput("Be carefully you could lose all your data.")
            print_status("Be carefully you could lose all your data.")
Esempio n. 24
0
    def wholegen(*,
                 wordlist: str, output: str,
                 charsets: List[str] = None,
                 minlength: int      = None, maxlength: int    = None,
                 mindigit:int        = None, maxdigit:int      = None,
                 minupper:int        = None, maxupper:int      = None,
                 minlower:int        = None, maxlower:int      = None,
                 minspecial:int      = None, maxspecial:int    = None,
                 mincomplexity:int   = None, maxcomplexity:int = None,
                 minoccurrence:int   = None, maxoccurrence:int = None,
                 mintime:int         = None, maxtime:int       = None,
                 target_time:int     = None,
                 hiderare: int       = 0,
                 showmasks:bool = False, quiet: bool = False,
                 sorting = "optindex"):

        #import pdb; pdb.set_trace()

        try:
            permission = [os.R_OK]
            Path.access(permission, wordlist)


            print(f"[*] Analyzing passwords in {wordlist}")

            whole = WholeGen(
                wordlist = wordlist,
                output = output,
                charsets = charsets,
                minlength = minlength,
                maxlength = maxlength,
                mindigit = mindigit,
                maxdigit = maxdigit,
                minupper = minupper,
                maxupper = maxupper,
                minlower = minlower,
                maxlower = maxlower,
                minspecial = minspecial,
                maxspecial = maxspecial,
                mincomplexity = mincomplexity,
                maxcomplexity = maxcomplexity,
                minoccurrence = minoccurrence,
                maxoccurrence = maxoccurrence,
                mintime = mintime,
                maxtime = maxtime,
                target_time = target_time,
                hiderare = hiderare,
                showmasks = showmasks,
                quiet = quiet)

            whole.full_analysis(sorting)


        except Exception as error:
            print_failure(error)
Esempio n. 25
0
    def attack(self, local: bool = False, pre_attack_output: Any = None):
        """
        Wordlist attack using Hydra
        """

        #import pdb; pdb.set_trace()

        try:
            self.no_empty_required_options(local)

            users = self.options['users'].value
            if os.path.isfile(users) and os.access(users, os.R_OK):
                users_file = users
                user = None
            else:
                user = users
                users_file = None

            passwords = self.options['passwords'].value
            if os.path.isfile(passwords) and os.access(passwords, os.R_OK):
                passwd_file = passwords
                passwd = None
            else:
                passwd = passwords
                passwd_file = None

            targets = self.options['targets'].value
            if os.path.isfile(targets) and os.access(targets, os.R_OK):
                targets_file = targets
                target = None
            else:
                target = targets
                targets_file = None

            hydra = Hydra()
            hydra.wordlist_attack(
                user=user,
                users_file=users_file,
                passwd=passwd,
                passwd_file=passwd_file,
                port=self.options['port'].value,
                ip4=self.options['ip4'].value,
                output=self.options['output'].value,
                output_format=self.options['output_format'].value,
                verbose=self.options['verbose'].value,
                stopInSuccess=self.options['stop_in_success'].value,
                stopInSuccessPerTarget=self.
                options['stop_in_success_per_target'].value,
                targets_file=targets_file,
                target=target,
                service=self.options['service'].value,
                slurm=self.slurm)

        except Exception as error:
            print_failure(error)
Esempio n. 26
0
    def run(self):
        """
        Execution of Cupp interactive mode
        """
        try:
            self.no_empty_required_options()
            cupp = Cupp()
            cupp.download_wordlists(quiet=self.options['quiet'].value)

        except Exception as error:
            print_failure(error)
Esempio n. 27
0
    def init_slurm_config(self):
        #import pdb;pdb.set_trace()
        try:
            slurm_config_file = self.config.get("slurm_conf_file")
            if slurm_config_file is None:
                slurm_config_file = Slurm.find_slurm_config()

            return Slurm.parser_slurm_conf(slurm_config_file)

        except Exception as error:
            print_failure(error)
Esempio n. 28
0
    def rename(oldWorkspace, newWorkspace, *, database="ama", user="******", host='localhost'):
        """
        Rename a workspace
        """
        #import pdb; pdb.set_trace()
        password = getpass(prompt=f"Password of {user} role: ")
        dbCredential = {'host': host, 'database': database, 'user': user, 'password': password}
        if Workspace.existWorkspace(oldWorkspace, **dbCredential):
            conn = None
            cur = None
            try:
                conn = psycopg2.connect(**dbCredential)
                cur = conn.cursor()
                renameWorkspace = \
                    f"""
                    UPDATE workspaces
                    SET name = '{newWorkspace}'
                    WHERE name = '{oldWorkspace}'
                    """
                cur.execute(renameWorkspace, (newWorkspace, oldWorkspace, ))
                conn.commit()

                renameWorkspaceTables = (
                    f"""
                    ALTER TABLE hashes_{oldWorkspace}
                    RENAME TO hashes_{newWorkspace}
                    """,
                    f"""
                    ALTER TABLE services_{oldWorkspace}
                    RENAME TO services_{newWorkspace}
                    """
                )
                for renameTable in renameWorkspaceTables:
                    cur.execute(renameTable, (newWorkspace, oldWorkspace, ))
                    conn.commit()

                cur.close()
                #cmd2.Cmd.poutput(f"Workspace {oldWorkspace} rename to {newWorkspace}")
                print_status(f"Workspace {oldWorkspace} rename to {newWorkspace}")

            except (Exception, psycopg2.DatabaseError) as error:
                #cmd2.Cmd.pexcept(error)
                print_failure(error)

            finally:
                if cur is not None:
                    cur.close()

                if conn is not None:
                    conn.close()

        else:
            #cmd2.Cmd.pwarning(f"Workspace {oldWorkspace} doesn't exist")
            print_failure(f"Workspace {oldWorkspace} doesn't exist")
Esempio n. 29
0
    def run(self):
        """
        Execution of Cupp - alecto
        """
        try:
            self.no_empty_required_options()
            cupp = Cupp()
            cupp.alectodb(quiet=self.options['quiet'].value)

        except Exception as error:
            print_failure(error)
Esempio n. 30
0
 def download_wordlists(self, *, quiet=False):
     """
     Cupp - download huge wordlists from repository
     """
     if self.enable:
         CONFIG = self.CONFIG
         if not quiet:
             cupp.print_cow()
         cupp.download_wordlist()
     else:
         print_failure("Auxiliary application {self.main_name} is disable")