def test_get_entropy_zero(self): string = "aaa" info("Checked string - {}".format(string)) e = get_entropy(string) info("Calculated entropy: {}".format(e)) assert_equal(e, 0, "Check if calculated entropy is equal to predicted one")
def test_get_entropy(self): string = "ab" info("Checked string - {}".format(string)) e = get_entropy(string) info("Calculated entropy: {}".format(e)) assert_true(e > 0, "Check if calculated entropy is bigger than 0") assert_equal(e, 1, "Check if calculated entropy is equal to predicted one")
def get_entropy_details(url_body): try: jsonschema.validate(url_body, details_url_schema) except jsonschema.exceptions.ValidationError as exc: raise BadRequest(exc.message) calculated = entropy.get_entropy(url_body.get('url')) response_text = { "details": { "entropy": round(calculated, 2) } } return Response(json.dumps( response_text, default=_default_json_model ), 200, mimetype="application/json")
def create_baddie(domain): _, ip_id = add_ip(domain) _, crt_id = add_cert(domain) good_keywords = [k['good_keyword'] for k in Goodies.get_all_goodies()] domain_phrases = domain.split('.') _, _, lev_matched_keyword = lev.levenstein_check(good_keywords, domain_phrases) min_lev_distance = 0 lev_distance = 0 if lev_matched_keyword: for phrase in domain_phrases: lev_distance = lev.calculate_levenstein(lev_matched_keyword, phrase) if 3 > min_lev_distance > lev_distance: min_lev_distance = lev_distance if not lev_matched_keyword: lev_matched_keyword = '' _, contained_matched_keyword = match_keyword(domain) if not contained_matched_keyword: contained_matched_keyword = '' entropy = ent.get_entropy(domain) return add_baddie(domain, ip_id[1], crt_id[1], lev_distance, lev_matched_keyword, contained_matched_keyword, entropy)
def verify_entropy(URL): if get_entropy(URL) >= Const.ENTROPY_PHISHING_MIN: return True else: return False