diff --git a/.gitignore b/.gitignore index 5cc0423..37775fd 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,4 @@ dmypy.json # Pyre type checker .pyre/ +Config/config.ini diff --git a/Config/config.ini b/Config/config.ini deleted file mode 100644 index 3bc4554..0000000 --- a/Config/config.ini +++ /dev/null @@ -1,4 +0,0 @@ -[APIKeys] -VT_APIKey = -HIBP_APIKey = -OTX_APIKey = diff --git a/Email/email_reputation_checker.py b/Email/email_reputation_checker.py index 52f57b8..541eb87 100644 --- a/Email/email_reputation_checker.py +++ b/Email/email_reputation_checker.py @@ -1,16 +1,15 @@ import requests import json +from termcolor import colored from Common import utils as utils from Common.utils import KeyFetcher from Common.breach_checker import BreachChecker - -# EmailReputationChecker class inherits methods from BreachChecker super class class EmailBreachChecker: def __init__(self, email): self.email = email - # Function to periodically download full breach data from HIBP so it can be + # Method to periodically download full breach data from HIBP so it can be # used to lookup further details of a breach when an IP/Email is found in the breach data def periodicBreachDownloader(self): keyfetcher = KeyFetcher() @@ -24,19 +23,17 @@ def periodicBreachDownloader(self): } try: response = requests.get(url, headers=headers, data=payload).text - print(colored("Downloading full breach data from HIBP ...","grey")) print("Downloading full breach data from HIBP") breaches = json.loads(response) with open('all_breaches.json', 'w') as f: json.dump(breaches, f) except Exception as e: - utils.error_message("Downloading all breaches failed",e) + utils.error_message(e) # Function to check email for breaches from HIBP def checkEmailBreach(self, email): keyfetcher = KeyFetcher() hibp_key = keyfetcher.getHIBPAPIKey() - # Check Email breach from HIBP url = "https://haveibeenpwned.com/api/v3/breachedaccount/"+email payload={} headers = { @@ -45,25 +42,44 @@ def checkEmailBreach(self, email): 'Content-Type': 'application/json' } try: - response = requests.get(url, headers=headers, data=payload).text - data = json.loads(response) - except requests.exceptions.RequestException as e: - utils.error_message(e) - for breach_name in data: + response = requests.get(url, headers=headers, data=payload) + except Exception as e: + utils.error_message(e.text) + if response.status_code == 404: + print(colored("No breaches found for this email","green")) + exit() + data = json.loads(response.text) + # Validating the response during execution instead of wasting a call for validation + if 'statusCode' not in data: + print("Query successful") + for breach_name in data: # print("Breach name: ", breach_name['Name']) - with open('all_breaches.json', 'r') as f: - search_name = breach_name['Name'] - # print("Searching for breach name: ", search_name) - breaches = json.load(f) - for breach in breaches: - if breach['Name'] == search_name: - print("\n\n" + colored("Account name:", "blue"), colored(email, "red")) - print(colored("Breach name:", "blue"), colored(breach_name['Name'], "red")) - print(colored("Breach description:", "blue"), colored(breach['Description'], "red")) - print(colored("Data classes that were part of this breach:", "blue"), colored(breach['DataClasses'], "red")) - print(colored("Breach date:", "blue"), colored(breach['BreachDate'], "white")) - if breach['isVerified'] == True: - print(colored("Breach is verified:", "blue"), colored(breach['IsVerified'], "green")) + with open('all_breaches.json', 'r') as f: + search_name = breach_name['Name'] + # print("Searching for breach name: ", search_name) + breaches = json.load(f) + # print(breaches) + for breach in breaches: + if 'Name' in breach and breach['Name'] == search_name: + print("\n\n" + colored("Account name:", "blue"), colored(email, "red")) + if 'Name' in breach: + print(colored("Breach name:", "blue"), colored(breach_name['Name'], "red")) + if 'Description' in breach: + print(colored("Breach description:", "blue"), colored(breach['Description'], "red")) + if 'BreachDate' in breach: + print(colored("Breach date:", "blue"), colored(breach['BreachDate'], "white")) + if 'DataClasses' in breach: + print(colored("Data classes that were part of this breach:", "blue"), colored(breach['DataClasses'], "red")) + if 'IsSensitive' in breach and breach['IsSensitive'] == True: + print(colored("Breach is sensitive:", "blue"), colored(breach['IsSensitive'], "yellow")) + if 'IsSensitive' in breach and breach['IsSensitive'] == False: + print(colored("Breach is sensitive:", "blue"), colored(breach['IsSensitive'], "green")) + if 'IsVerified' in breach and breach['IsVerified'] == True: + print(colored("Breach is verified:", "blue"), colored(breach['IsVerified'], "green")) + if 'IsVerified' in breach and breach['IsVerified'] == False: + print(colored("Breach is verified:", "blue"), colored(breach['IsVerified'], "red")) + print(colored("Number of accounts compromised:", "blue"), colored(breach['PwnCount'], "white")) else: - print(colored("Breach is verified:", "blue"), colored(breach['IsVerified'], "red")) - print(colored("Number of accounts compromised:", "blue"), colored(breach['PwnCount'], "white")) + pass + else: + utils.error_message(data['message'])