示例#1
0
def verify_hash_type(hash_to_verify, least_likely=False, verbose=False):
    """
      Attempt to verify a given hash by type (md5, sha1, etc..)

      >  :param hash_to_verify: hash string
      >  :param least_likely: show least likely options as well
      >  :return: likely options, least likely options, or none

      Example:
        >>> verify_hash_type("098f6bcd4621d373cade4e832627b4f6", least_likely=True)
        [('md5', 'md4', 'md2'), ('double md5', 'lm', ... )]
    """
    for regex, hash_types in HASH_TYPE_REGEX.items(
    ):  # iter is not available in Python 3.x
        if verbose:
            LOGGER.debug("Testing: {}".format(hash_types))
        if regex.match(hash_to_verify):
            return hash_types if least_likely else hash_types[0]
    error_msg = (
        "Unable to find any algorithms to match the given hash. If you "
        "feel this algorithm should be implemented make an issue here: {}")
    LOGGER.fatal(error_msg.format(DAGON_ISSUE_LINK))
    # hash_guarantee(hash_to_verify)
    LOGGER.warning("`hash_guarantee` has been turned off for the time being")
    shutdown(1)
示例#2
0
def create_wordlist(warning=True, verbose=False, add=False):
    """
      Create a bruteforcing wordlist

      > :param max_length: max amount of words to have
      > :param max_word_length: how long the words should be
      > :param warning: output the warning message to say that BF'ing sucks
      > :return: a wordlist
    """
    max_length, max_word_length, dirname = 10000000, 10, "bf-dicts"
    if add:
        max_word_length += 2

    warn_msg = (
        "It is highly advised to use a dictionary attack over bruteforce. "
        "Bruteforce requires extreme amounts of memory to accomplish and "
        "it is possible that it could take a lifetime to successfully "
        "crack your hash. To run a dictionary attack all you need to do is"
        " pass the wordlist switch ('-w/--wordlist PATH') with the path to "
        "your wordlist. (IE: --bruteforce -w ~/dicts/dict.txt)")

    if warning:
        LOGGER.warning(warn_msg)

    if verbose:
        LOGGER.debug(
            "Creating {} words with a max length of {} characters".format(
                max_length, max_word_length))

    create_dir(dirname, verbose=verbose)
    with open(dirname + "/" + WORDLIST_NAME, "a+") as lib:
        word = Generators().word_generator(length_max=max_word_length)
        lib.seek(0, 0)
        line_count = len(lib.readlines())
        try:
            for _ in range(line_count, max_length):
                lib.write(next(word) + "\n")
        except StopIteration:  # SHOULD NEVER GET HERE
            # if we run out of mutations we'll retry with a different word length
            lib.seek(0, 0)
            err_msg = (
                "Ran out of mutations at {} mutations. You can try upping "
                "the max length or just use what was processed. If you "
                "make the choice not to continue the program will add +2 "
                "to the max length and try to create the wordlist again.."
            ).format(len(lib.readlines()))
            LOGGER.error(err_msg)
            q = prompt("Would you like to continue", "y/N")
            if not q.startswith(("y", "Y")):
                lib.truncate(0)
                create_wordlist(warning=False, add=True)
    LOGGER.info(
        "Wordlist generated, words saved to: {}. Please re-run the application, exiting.."
        .format(WORDLIST_NAME))
    shutdown()
示例#3
0
def create_wordlist(max_length=10000000,
                    max_word_length=10,
                    warning=True,
                    perms=""):
    """
      Create a bruteforcing wordlist

      > :param max_length: max amount of words to have
      > :param max_word_length: how long the words should be
      > :param warning: output the warning message to say that BF'ing sucks
      > :return: a wordlist
    """
    warn_msg = "It is highly advised to use a dictionary attack over bruteforce. "
    warn_msg += "Bruteforce requires extreme amounts of memory to accomplish and "
    warn_msg += "it is possible that it could take a lifetime to successfully crack "
    warn_msg += "your hash. To run a dictionary attack all you need to do is pass "
    warn_msg += "the wordlist switch ('--wordlist PATH') with the path to your wordlist. "
    warn_msg += "(IE: --bruteforce --wordlist ~/dicts/dict.txt)"
    if warning is True:
        LOGGER.warning(warn_msg)

    with open(WORDLIST_NAME, "a+") as lib:
        word = word_generator(length_max=max_word_length, perms=perms)
        lib.seek(0, 0)
        line_count = len(lib.readlines())
        try:
            for _ in range(line_count, max_length):
                lib.write(next(word) + "\n")
        except StopIteration:
            # if we run out of mutations we'll retry with a different word length
            lib.seek(0, 0)
            err_msg = "Ran out of mutations at {} mutations. You can try upping the max length ".format(
                len(lib.readlines()))
            err_msg += "or just use what was processed. If you make the choice not to continue "
            err_msg += "the program will add +2 to the max length and try to create the wordlist again.."
            LOGGER.error(err_msg)
            q = prompt("Would you like to continue", "y/N")
            if q.lower().startswith("y"):
                pass
            else:
                lib.truncate(0)
                create_wordlist(max_word_length=max_length + 2, warning=False)
    LOGGER.info(
        "Wordlist generated, words saved to: {}. Please re-run the application, exiting.."
        .format(WORDLIST_NAME))
    shutdown()
示例#4
0
def bruteforce_main(verf_hash, algorithm=None, wordlist=None, salt=None, placement=None, all_algs=False):
    """
      Main function to be used for bruteforcing a hash
    """
    wordlist_created = False
    if wordlist is None:
        for item in os.listdir(os.getcwd()):
            if WORDLIST_RE.match(item):
                wordlist_created = True
                wordlist = item
        if wordlist_created is True:
            pass
        else:
            LOGGER.info("Creating wordlist..")
            create_wordlist()
    else:
        LOGGER.info("Reading from, {}..".format(wordlist))

    if algorithm is None:
        hash_type = verify_hash_type(verf_hash, least_likely=all_algs)
        LOGGER.info("Found {} possible hash types to run against {} ".format(len(hash_type),
                                                                             hash_type))
        for alg in hash_type:
            LOGGER.info("Starting bruteforce with {}..".format(alg.upper()))
            bruteforcing = hash_words(verf_hash, wordlist, alg, salt=salt, placement=placement)
            if bruteforcing is None:
                LOGGER.warning("Unable to find a match for '{}', using {}..".format(verf_hash, alg.upper()))
            else:
                match_found(bruteforcing)
                break
    else:
        LOGGER.info("Using algorithm, {}..".format(algorithm.upper()))
        results = hash_words(verf_hash, wordlist, algorithm, salt=salt, placement=placement)
        if results is None:
            LOGGER.warning("Unable to find a match using {}..".format(algorithm.upper()))
            verifiy = prompt("Would you like to attempt to verify the hash type automatically and crack it", "y/N")
            if verifiy.lower().startswith("y"):
                bruteforce_main(verf_hash, wordlist=wordlist, salt=salt, placement=placement)
            else:
                LOGGER.warning("Unable to produce a result for given hash '{}' using {}.. Exiting..".format(
                    verf_hash, algorithm.upper()))
        else:
            match_found(results)
示例#5
0
文件: dagon.py 项目: hbxc0re/Dagon
                           verbose=opt.runInVerbose)
                full_hash_path = "{}/{}/{}".format(os.getcwd(), "hash_files",
                                                   hash_file_name)
                with open(full_hash_path, "a+") as filename:
                    if len(files_to_process.split(",")) > 1:
                        LOGGER.info(
                            "Found multiple files to process: '{}'..".format(
                                files_to_process))
                        for f in files_to_process.split(","):
                            try:
                                for item in Generators(
                                        f.strip()).hash_file_generator():
                                    filename.write(item.strip() + "\n")
                            except IOError:
                                LOGGER.warning(
                                    "Provided file '{}' does not exist, skipping.."
                                    .format(f.strip()))
                                continue
                    else:
                        LOGGER.info(
                            "Reading from singular file '{}'...".format(
                                files_to_process))
                        for item in Generators(
                                opt.createHashFile).hash_file_generator():
                            filename.write(item.strip() + "\n")

                if not open(full_hash_path).readlines():
                    LOGGER.warning(
                        "No processable hashes found in '{}'..".format(
                            files_to_process))
                else:
示例#6
0
def bruteforce_main(verf_hash,
                    algorithm=None,
                    wordlist=None,
                    salt=None,
                    placement=None,
                    all_algs=False,
                    posx="",
                    use_hex=False,
                    verbose=False,
                    batch=False,
                    rounds=10):
    """
      Main function to be used for bruteforcing a hash
    """
    wordlist_created = False
    if wordlist is None:
        create_dir("bf-dicts", verbose=verbose)
        for item in os.listdir(os.getcwd() + "/bf-dicts"):
            if WORDLIST_RE.match(item):
                wordlist_created = True
                wordlist = "{}/bf-dicts/{}".format(os.getcwd(), item)
        if not wordlist_created:
            LOGGER.info("Creating wordlist..")
            create_wordlist(verbose=verbose)
    else:
        LOGGER.info("Reading from, {}..".format(wordlist))

    if algorithm is None:
        hash_type = verify_hash_type(verf_hash, least_likely=all_algs)
        LOGGER.info(
            "Found {} possible hash type(s) to run against: {} ".format(
                len(hash_type) - 1 if hash_type[1] is None else len(hash_type),
                hash_type[0] if hash_type[1] is None else hash_type))
        for alg in hash_type:
            if alg is None:
                err_msg = (
                    "Ran out of algorithms to try. There are no more "
                    "algorithms currently available that match this hashes "
                    "length, and complexity.")
                LOGGER.fatal(err_msg.format(DAGON_ISSUE_LINK))
                break
            else:
                if ":::" in verf_hash:
                    LOGGER.debug(
                        "It appears that you are trying to crack an '{}' hash, "
                        "these hashes have a certain sequence to them that looks "
                        "like this 'USERNAME:SID:LM_HASH:NTLM_HASH:::'. What you're "
                        "wanting is the NTLM part, of the hash, fix your hash and try "
                        "again..".format(alg.upper()))
                    shutdown(1)
                LOGGER.info("Starting bruteforce with {}..".format(
                    alg.upper()))
                bruteforcing = hash_words(verf_hash,
                                          wordlist,
                                          alg,
                                          salt=salt,
                                          placement=placement,
                                          posx=posx,
                                          use_hex=use_hex,
                                          verbose=verbose,
                                          rounds=rounds)
                if bruteforcing is None:
                    LOGGER.warning(
                        "Unable to find a match for '{}', using {}..".format(
                            verf_hash, alg.upper()))
                else:
                    match_found(bruteforcing)
                    break
    else:
        LOGGER.info("Using algorithm, {}..".format(algorithm.upper()))
        results = hash_words(verf_hash,
                             wordlist,
                             algorithm,
                             salt=salt,
                             placement=placement,
                             posx=posx,
                             verbose=verbose)
        if results is None:
            LOGGER.warning("Unable to find a match using {}..".format(
                algorithm.upper()))
            if not batch:
                verify = prompt(
                    "Would you like to attempt to verify the hash type automatically and crack it",
                    "y/N")
            else:
                verify = "n"
            if verify.startswith(("y", "Y")):
                bruteforce_main(verf_hash,
                                wordlist=wordlist,
                                salt=salt,
                                placement=placement,
                                posx=posx,
                                use_hex=use_hex,
                                verbose=verbose)
            else:
                LOGGER.warning(
                    "Unable to produce a result for given hash '{}' using {}.."
                    .format(verf_hash, algorithm.upper()))
        else:
            match_found(results)
示例#7
0
文件: dagon.py 项目: x90x90x90/Dagon
                           verbose=opt.runInVerbose)
                full_hash_path = "{}/{}/{}".format(os.getcwd(), "hash_files",
                                                   hash_file_name)
                with open(full_hash_path, "a+") as filename:
                    if len(files_to_process.split(",")) > 1:
                        LOGGER.info(
                            "Found multiple files to process: '{}'..".format(
                                files_to_process))
                        for f in files_to_process.split(","):
                            try:
                                for item in Generators(
                                        f.strip()).hash_file_generator():
                                    filename.write(item.strip() + "\n")
                            except IOError:
                                LOGGER.warning(
                                    "Provided file '{}' does not exist, skipping.."
                                    .format(f.strip()))
                                continue
                    else:
                        LOGGER.info(
                            "Reading from singular file '{}'...".format(
                                files_to_process))
                        for item in Generators(
                                opt.createHashFile).hash_file_generator():
                            filename.write(item.strip() + "\n")

                if not open(full_hash_path).readlines():
                    LOGGER.warning(
                        "No processable hashes found in '{}'..".format(
                            files_to_process))
                else:
示例#8
0
def bruteforce_main(verf_hash,
                    algorithm=None,
                    wordlist=None,
                    salt=None,
                    placement=None,
                    all_algs=False,
                    perms="",
                    posx="",
                    use_hex=False):
    """
      Main function to be used for bruteforcing a hash
    """
    wordlist_created = False
    if wordlist is None:
        for item in os.listdir(os.getcwd()):
            if WORDLIST_RE.match(item):
                wordlist_created = True
                wordlist = item
        if wordlist_created is True:
            pass
        else:
            LOGGER.info("Creating wordlist..")
            create_wordlist(perms=perms)
    else:
        LOGGER.info("Reading from, {}..".format(wordlist))

    if algorithm is None:
        hash_type = verify_hash_type(verf_hash, least_likely=all_algs)
        LOGGER.info("Found {} possible hash types to run against: {} ".format(
            len(hash_type) - 1 if hash_type[1] is None else len(hash_type),
            hash_type[0] if hash_type[1] is None else hash_type))
        for alg in hash_type:
            if alg is None:
                err_msg = "Ran out of algorithms to try. There are no more algorithms "
                err_msg += "currently available that match this hashes length, and complexity. "
                err_msg += "Please attempt to use your own wordlist (switch '--wordlist'), "
                err_msg += "download one (switch '--download'), use salt (switch '-S SALT'), "
                err_msg += "or find the algorithm type and create a issue here {}.. "
                LOGGER.fatal(err_msg.format(DAGON_ISSUE_LINK))
                break
            else:
                if ":" in verf_hash:
                    LOGGER.debug(
                        "It appears that you are trying to crack an '{}' hash, "
                        "these hashes have a certain sequence to them that looks "
                        "like this 'USERNAME:SID:LM_HASH:NTLM_HASH:::'. What you're "
                        "wanting is the NTLM part, of the hash, fix your hash and try "
                        "again..".format(alg.upper()))
                    shutdown(1)
                LOGGER.info("Starting bruteforce with {}..".format(
                    alg.upper()))
                bruteforcing = hash_words(verf_hash,
                                          wordlist,
                                          alg,
                                          salt=salt,
                                          placement=placement,
                                          posx=posx,
                                          use_hex=use_hex)
                if bruteforcing is None:
                    LOGGER.warning(
                        "Unable to find a match for '{}', using {}..".format(
                            verf_hash, alg.upper()))
                else:
                    match_found(bruteforcing)
                    break
    else:
        LOGGER.info("Using algorithm, {}..".format(algorithm.upper()))
        results = hash_words(verf_hash,
                             wordlist,
                             algorithm,
                             salt=salt,
                             placement=placement,
                             posx=posx)
        if results is None:
            LOGGER.warning("Unable to find a match using {}..".format(
                algorithm.upper()))
            verifiy = prompt(
                "Would you like to attempt to verify the hash type automatically and crack it",
                "y/N")
            if verifiy.lower().startswith("y"):
                bruteforce_main(verf_hash,
                                wordlist=wordlist,
                                salt=salt,
                                placement=placement,
                                posx=posx,
                                use_hex=use_hex)
            else:
                LOGGER.warning(
                    "Unable to produce a result for given hash '{}' using {}.. Exiting.."
                    .format(verf_hash, algorithm.upper()))
        else:
            match_found(results)