Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,4 @@ dmypy.json

# Pyre type checker
.pyre/
Config/config.ini
4 changes: 0 additions & 4 deletions Config/config.ini

This file was deleted.

68 changes: 42 additions & 26 deletions Email/email_reputation_checker.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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 = {
Expand All @@ -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'])