예제 #1
0
def api_return_hashes_as_json(chash: [str], args: dict = {}):
    """
    Using name-that-hash as an API? Call this function!

    Given a list of hashes of strings
    return a list of json of all hashes in the same order as the input
    """
    logger.remove()
    # nth = the object which names the hash types
    nth = hash_namer.Name_That_Hash(hashes.prototypes)
    # prettifier print things :)
    pretty_printer = prettifier.Prettifier(args, api=True)
    # for most popular hashes etc
    hash_info = hash_information()

    output = []
    for i in chash:
        output.append(HashObj(i, nth, hash_info))

    return pretty_printer.greppable_output(output)
예제 #2
0
def main(**kwargs):
    """Name That Hash - Instantly name the type of any hash!

    Github:\n
    https://github.com/hashpals/name-that-hash

    From the creator of RustScan and Ciphey. Follow me on Twitter!\n
    https://twitter.com/bee_sec_san

    Example usage:\n
        nth --text '5f4dcc3b5aa765d61d8327deb882cf99'\n
        nth --file hash\n
        nth --text '5f4dcc3b5aa765d61d8327deb882cf99' --grepable\n
        Note: Use single quotes ' as double quotes " do not work well on Linux.\n
    """
    no_args = True
    for i in kwargs.values():
        if i:
            no_args = False
            break
    if no_args:
        with click.Context(main) as ctx:
            click.echo(main.get_help(ctx))
            exit(0)

    # Load the verbosity, so that we can start logging
    set_logger(kwargs)
    logger.debug(kwargs)

    # Banner handling
    if not kwargs["accessible"] and not kwargs["no_banner"] and not kwargs["grepable"]:
        logger.info("Running the banner.")
        banner()

    hash_info = hash_information()
    # nth = the object which names the hash types
    nth = hash_namer.Name_That_Hash(hashes.prototypes)
    # prettifier print things :)
    pretty_printer = prettifier.Prettifier(kwargs)

    logger.trace("Initialised the hash_info, nth, and pretty_printer objects.")

    output = []

    if kwargs["text"]:
        if kwargs["base64"]:
            kwargs["text"] = base64.b64decode(kwargs["text"]).decode("utf-8")
        output.append(HashObj(kwargs["text"], nth, hash_info))
    elif kwargs["file"]:
        logger.trace("performing file opening")
        # else it must be a file
        for i in kwargs["file"].read().splitlines():
            logger.trace(i)
            if kwargs["base64"]:
                logger.trace("decoding as base64")
                i = base64.b64decode(i)
                logger.trace(f"hash is now {i}")
                logger.trace(f"b64 decoded i is {i}")
            
            output.append(HashObj(i.decode("utf-8"), nth, hash_info))

            logger.trace(output)

    if kwargs["grepable"]:
        print(pretty_printer.grepable_output(output))
    else:
        pretty_printer.pretty_print(output)