2019-03-13 01:39:49 +01:00
|
|
|
import hashlib
|
2019-03-12 22:41:07 +01:00
|
|
|
import requests
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def lookup_pwned_api(pwd):
|
2019-03-13 01:39:49 +01:00
|
|
|
sha1pwd = hashlib.sha1(pwd.encode('ascii')).hexdigest().upper()
|
2019-03-12 22:41:07 +01:00
|
|
|
head = sha1pwd[:5]
|
|
|
|
tail = sha1pwd[5:]
|
|
|
|
|
|
|
|
r = requests.get('https://api.pwnedpasswords.com/range/{0}'.format(head))
|
|
|
|
if r.status_code == 200:
|
|
|
|
hashes = (s.split(':') for s in r.text.split('\r\n'))
|
|
|
|
pred = ((head + t,count) for t,count in hashes if t == tail)
|
|
|
|
|
|
|
|
password_hit = next(pred, None)
|
|
|
|
return password_hit
|
|
|
|
|
|
|
|
|
2019-03-13 02:26:20 +01:00
|
|
|
def main(args):
|
2019-03-13 02:32:18 +01:00
|
|
|
ec = 0
|
2019-03-13 02:31:23 +01:00
|
|
|
for pwd in args or sys.stdin:
|
|
|
|
pwd = pwd.strip()
|
2019-03-13 02:20:10 +01:00
|
|
|
api_return = lookup_pwned_api(pwd)
|
|
|
|
if (api_return):
|
|
|
|
print(pwd, "was found")
|
|
|
|
print("Hash {0}, {1} occurences".format(
|
|
|
|
api_return[0], api_return[1]))
|
2019-03-13 02:32:18 +01:00
|
|
|
ec = 1
|
2019-03-13 02:20:10 +01:00
|
|
|
else:
|
|
|
|
print(pwd, "was not found")
|
2019-03-13 02:32:18 +01:00
|
|
|
return ec
|
2019-03-13 02:26:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-03-13 02:32:18 +01:00
|
|
|
sys.exit(main(sys.argv[1:]))
|