Inital Commit für pwned-handler
parent
cc9b7be85a
commit
54d195724f
@ -1,9 +1,24 @@
|
||||
MIT License
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
For more information, please refer to <http://unlicense.org>
|
||||
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("pwned_search")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("pwned_search")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("16bc2ac9-dcda-44b2-aa3c-3537ce769319")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -0,0 +1 @@
|
||||
C# version
|
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
namespace pwned_search {
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
Console.Write("Enter the password to check: ");
|
||||
string plaintext = Console.ReadLine();
|
||||
|
||||
SHA1 sha = new SHA1CryptoServiceProvider();
|
||||
byte[] data = sha.ComputeHash(Encoding.ASCII.GetBytes(plaintext));
|
||||
|
||||
// Loop through each byte of the hashed data
|
||||
// and format each one as a hexadecimal string.
|
||||
var sBuilder = new StringBuilder();
|
||||
for (int i = 0; i < data.Length; i++) {
|
||||
sBuilder.Append(data[i].ToString("x2"));
|
||||
}
|
||||
string result = sBuilder.ToString().ToUpper();
|
||||
Console.WriteLine($"The SHA-1 hash of {plaintext} is: {result}");
|
||||
|
||||
// get a list of all the possible passwords where the first 5 digits of the hash are the same
|
||||
string url = "https://api.pwnedpasswords.com/range/" + result.Substring(0, 5);
|
||||
WebRequest request= WebRequest.Create(url);
|
||||
Stream response = request.GetResponse().GetResponseStream();
|
||||
StreamReader reader = new StreamReader(response);
|
||||
|
||||
// look at each possibility and compare the rest of the hash to see if there is a match
|
||||
string hashToCheck = result.Substring(5);
|
||||
while (true) {
|
||||
string line = reader.ReadLine();
|
||||
if (line == null) {
|
||||
Console.WriteLine("That password was not found.");
|
||||
break;
|
||||
}
|
||||
string[] parts = line.Split(':');
|
||||
if (parts[0] == hashToCheck) {
|
||||
Console.WriteLine("Password has been compromised -- DO NOT USE!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Console.ReadKey(); // pause until key press
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
try:
|
||||
import requests
|
||||
except ModuleNotFoundError:
|
||||
print("### pip install requests ###")
|
||||
raise
|
||||
|
||||
|
||||
def lookup_pwned_api(pwd):
|
||||
"""Returns hash and number of times password was seen in pwned database.
|
||||
|
||||
Args:
|
||||
pwd: password to check
|
||||
|
||||
Returns:
|
||||
A (sha1, count) tuple where sha1 is SHA-1 hash of pwd and count is number
|
||||
of times the password was seen in the pwned database. count equal zero
|
||||
indicates that password has not been found.
|
||||
|
||||
Raises:
|
||||
RuntimeError: if there was an error trying to fetch data from pwned
|
||||
database.
|
||||
UnicodeError: if there was an error UTF_encoding the password.
|
||||
"""
|
||||
sha1pwd = hashlib.sha1(pwd.encode('utf-8')).hexdigest().upper()
|
||||
head, tail = sha1pwd[:5], sha1pwd[5:]
|
||||
url = 'https://api.pwnedpasswords.com/range/' + head
|
||||
res = requests.get(url)
|
||||
if res.status_code != 200:
|
||||
raise RuntimeError('Error fetching "{}": {}'.format(
|
||||
url, res.status_code))
|
||||
hashes = (line.split(':') for line in res.text.splitlines())
|
||||
count = next((int(count) for t, count in hashes if t == tail), 0)
|
||||
return sha1pwd, count
|
||||
|
||||
|
||||
def main(args):
|
||||
ec = 0
|
||||
for pwd in args or sys.stdin:
|
||||
pwd = pwd.strip()
|
||||
try:
|
||||
sha1pwd, count = lookup_pwned_api(pwd)
|
||||
|
||||
if count:
|
||||
foundmsg = "{0} was found with {1} occurrences (hash: {2})"
|
||||
print(foundmsg.format(pwd, count, sha1pwd))
|
||||
ec = 1
|
||||
else:
|
||||
print("{} was not found".format(pwd))
|
||||
except UnicodeError:
|
||||
errormsg = sys.exc_info()[1]
|
||||
print("{0} could not be checked: {1}".format(pwd, errormsg))
|
||||
ec = 1
|
||||
continue
|
||||
return ec
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
Loading…
Reference in New Issue