Exemplo n.º 1
0
def main():
    parser = ArgumentParser(
        prog='VirusShare Lookups',
        description=
        'Bulk lookups against the VirusShare website using a personal api key',
        usage='%(prog)s [options]',
        epilog='Version: {}'.format(__version__))
    parser.add_argument('-f',
                        help='Path to file containing the hashes (Required')
    parser.add_argument(
        '-t',
        help='Lookup Type, file or quick, Default is "quick" (Optional)',
        choices=['quick', 'file'],
        default="quick")
    parser.add_argument('-o',
                        help='Output Type (Optional)',
                        choices=['json'],
                        default="json")
    parser.add_argument('-v', help='Show version and exit')

    args = parser.parse_args()

    if args.v:
        print('Version: {}'.format(__version__))
        sys.exit(0)

    lookup_type = args.t
    output_type = args.o

    script_start_time = time.time()

    api_key_file = os.path.abspath(
        os.path.join(os.path.dirname(sys.argv[0]), 'apikey.txt'))

    apikey = ''
    if os.path.isfile(api_key_file):

        config = ConfigParser()
        config.read([api_key_file])
        config.apikey_config = dict(config.items("APIKEYS"))
        apikey = config.apikey_config['vs']

    else:
        print('ERROR: No {} was not found, exiting'.format(api_key_file))
        sys.exit(-1)

    hash_file = args.f

    if hash_file:
        if os.path.isfile:
            hashlookup = VirusShare(apikey, lookup_type, output_type)
            data = hashlookup.get_hashes_from_file(hash_file)
            results = hashlookup.bulk_search(data)
            hashlookup.write_output(results)

        else:
            print('ERROR: {} was not a valid file')
            sys.exit(-1)
    else:
        print('ERROR: -f is required')