-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhibpcheck.py
executable file
·107 lines (92 loc) · 3.1 KB
/
hibpcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /usr/bin/python3
from hibpapikey import apikey
import argparse
import requests
import time
argp = argparse.ArgumentParser(description='Check email addresses against havibeenpwned.')
argp.add_argument('-a', dest='account', help='Check a single address')
argp.add_argument('-l', dest='accountloc', help='Check against provided newline separated list')
args = argp.parse_args()
RED = '\033[91m'
BLU = '\033[94m'
GRE = '\033[92m'
END = '\033[0m'
headers = {'User-Agent': 'Python HaveIBeenPwned Checker', 'hibp-api-key': apikey}
breach = 'https://haveibeenpwned.com/api/v3/breachedaccount/'
paste = 'https://haveibeenpwned.com/api/v3/pasteaccount/'
untrunc = '?truncateResponse=false'
account = args.account
accountloc = args.accountloc
rlimit = 1.6
def breachCheck(account):
breachr = requests.get(
breach + account + untrunc,
headers=headers
)
brcode = str(breachr.status_code)
if brcode == '200':
bjson = breachr.json()
print('{0}{1}'.format(BLU, account))
return bjson
elif brcode == '404':
print('{0}{1}\n\t{2}No breaches found.'.format(BLU, account, RED))
return False
elif brcode == '400':
print('{0}{1} {2}- Bad account'.format(BLU, account, END))
elif brcode == '429':
print('Hit rate limit, increasing sleep time by .3s')
rlimit = rlimit + .3
time.sleep(rlimit)
breachCheck(account)
else:
print('Something went wrong:\n{0}'.format(breachr.content))
quit()
def pasteCheck(account):
paster = requests.get(
paste + account,
headers=headers
)
prcode = str(paster.status_code)
if prcode == '200':
pjson = paster.json()
return pjson
elif prcode == '404':
print('{0}Paste Name:\n\t{1}No pastes found.\n\n'.format(BLU, RED))
return False
elif prcode == '400':
print('\n\t{0}Bad account'.format(RED))
elif prcode == '429':
print('Hit rate limit, increasing sleep time by .3s')
rlimit += .3
time.sleep(rlimit)
pasteCheck(account)
else:
print('Something went wrong:\n{0}'.format(paster.content))
quit()
def breachParse(bjson):
print('{0}Breach Name:'.format(BLU))
for i in range(len(bjson)):
print('{0}\t{1}\n\t\t{2}{3}'.format(RED, bjson[i]['Name'], GRE, ', '.join(bjson[i]['DataClasses'])))
def pasteParse(pjson):
print('{0}Paste name:'.format(BLU))
for i in range(len(pjson)):
print('{0}\t{1}\n\t\t{2}{3}{4}\n\n'.format(RED, pjson[i]['Title'], GRE, pjson[i]['Source'][8:-1], pjson[i]['Id']))
if account != None:
bjson = breachCheck(account)
if bjson:
breachParse(bjson)
pjson = pasteCheck(account)
if pjson:
pasteParse(pjson)
elif accountloc != None:
with open(accountloc) as f:
actlist = f.read().splitlines()
for account in actlist:
bjson = breachCheck(account)
if bjson:
breachParse(bjson)
time.sleep(rlimit)
pjson = pasteCheck(account)
if pjson:
pasteParse(pjson)
time.sleep(rlimit)