コード例 #1
0
 def handle(self, *args, **options):
     bf = BloomFilter(n=options.get("n") * 2, p=options.get("p"))
     with open(options.get("input"), "r") as inp:
         for i in trange(options.get("n")):
             line = inp.readline()
             if not line:
                 break
             bf.add(line.strip().upper().encode("ascii"))
     filename = settings.BASE_PASSWORD_STRENGTH_BLOOM_FILE
     tmpfile = f"{filename}.tmp"
     logger.info(f"Writing new password bloom filter: {tmpfile}")
     with open(tmpfile, "wb") as outp:
         bf.write(outp)
     logger.info(f"Replacing old password bloom filter: {filename}")
     os.rename(tmpfile, filename)
コード例 #2
0
            # insert domain into bloomfilter
            if not domain.lower().encode("utf8") in bloom:
                bloom.add(domain.lower().encode("utf8"))

            # insert into family/domain lookup table
            dga_lookup_dict[domain] = family

    # test with first DGA domain/family pair that should be present in the bloomfilter and the dga_dict
    if not (first_entry and test_domain and test_family):
        logging.error("Unknown error while creating bloomfilter and DGA dict")
        sys.exit(-1)
    if test_domain.lower().encode("utf8") in bloom and dga_lookup_dict.get(
            test_domain.lower(), "") == test_family:
        logging.info("%s (%s)", test_domain, test_family)
        logging.info("Bloomfilter and DGA dict successfully created")
    else:
        logging.error("Unknown error while creating bloomfilter and DGA dict")
        sys.exit(-1)

    # 5. write bloomfilter and dga dict to a file so that the sandbox can use it in the python signature
    logging.info("Write bloomfilter and dga dict to files")
    bloom_path = os.path.join(CUCKOO_ROOT, "data", "dga.bloom")
    with open(bloom_path, "wb") as f:
        bloom.write(f)

    lookup_path = os.path.join(CUCKOO_ROOT, "data", "dga_lookup_dict.json.gz")
    with gzip.GzipFile(lookup_path, "w") as fout:
        fout.write(json.dumps(dga_lookup_dict).encode("utf8"))

    logging.info("Successfully generated bloomfilter and dga dict file")