Ejemplo n.º 1
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)
Ejemplo n.º 2
0
                                    print("\n")
                    except Exception as e:
                        LOGGER.fatal(
                            "Failed with error code: '{}'. Check the file and try again.."
                            .format(e.message))

                # TODO:/ create rainbow attacks

                # Verify a given hash to see what type of algorithm might have been used
                elif opt.verifyHashType is not None:
                    LOGGER.info("Analyzing given hash: '{}'...".format(
                        opt.verifyHashType))
                    match_found(verify_hash_type(
                        opt.verifyHashType,
                        least_likely=opt.displayLeastLikely),
                                kind="else",
                                all_types=opt.displayLeastLikely)

                # Verify a file of hashes, one per line
                elif opt.verifyHashList is not None:
                    with open(opt.verifyHashList) as hashes:
                        hashes.seek(0, 0)
                        total_hahes = hashes.readlines()
                        LOGGER.info(
                            "Found a total of {} hashes to verify..".format(
                                len(total_hahes)))
                        for h in total_hahes:
                            print
                            LOGGER.info("Analyzing hash: '{}'".format(
                                h.strip()))
Ejemplo n.º 3
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)