Skip to content

Instantly share code, notes, and snippets.

@jimywork
Last active December 19, 2018 20:22
Show Gist options
  • Save jimywork/b4ece478f14910faba05ba44ae735988 to your computer and use it in GitHub Desktop.
Save jimywork/b4ece478f14910faba05ba44ae735988 to your computer and use it in GitHub Desktop.
Does an analysis of the data and checks if the site was pwned
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import json
def pwned(date=2018, limit=999):
"""Does an analysis of the data and checks if the site was pwned"""
retval = []
headers = {
'User-Agent': "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36"
}
try:
request = requests.get('https://breachlevelindex.com/data-breach-database.php?range={}'.format(date),
headers=headers, timeout=1)
soup = BeautifulSoup(request.text, 'html.parser')
for row in soup.findAll('tr', limit=10)[1:]:
elements = [element.text.strip() for element in row.findAll('td')]
#elements = [column for column in columns if column]
if len(elements) != 9:
print("")
data = {
"rank": elements[0],
"org": elements[1],
"records": elements[2],
"date": elements[3],
"type": elements[4],
"source": elements[5],
"location": elements[6],
"industry": elements[7],
"risk": elements[8]
}
organization = data['org']
try:
data["haveibeenpwned"] = requests.get('https://haveibeenpwned.com/api/v2/breach/{}'.format(organization.lower()),headers=headers, timeout=1).json()
except Exception as e:
data["haveibeenpwned"] = None
retval.append(data)
except requests.exceptions.RequestException as error:
print("{}".format(error))
return retval
if __name__ == '__main__':
pwneds = pwned(date=2018, limit=10)
for i, pwned in enumerate(pwneds) :
if pwned['haveibeenpwned'] != None:
print(json.dumps(pwned, indent=4, sort_keys=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment