-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_correlator.py
More file actions
51 lines (41 loc) · 2.18 KB
/
hash_correlator.py
File metadata and controls
51 lines (41 loc) · 2.18 KB
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
# Usage
# python hash_correlator.py -n /path/to/ntds.txt -c /path/to/cracked.txt -o /path/to/output.txt
import argparse
import os
# Function to parse command-line arguments
def parse_args():
parser = argparse.ArgumentParser(description="Correlate cracked hashes with user accounts from an NTDS dump.")
parser.add_argument("-n", "--ntds", required=True, help="Path to the NTDS file containing user accounts and hashes.")
parser.add_argument("-c", "--cracked", default="", help="Path to the file containing cracked hashes. Defaults to Hashcat's potfile if not specified.")
parser.add_argument("-o", "--output", help="Output file path to write the results. Defaults to <ntds_filename>_passwords.txt.")
return parser.parse_args()
# Function to process files and extract passwords
def process_files(ntds_file, cracked_file, output_file):
# Use Hashcat's potfile as default if no cracked file path is provided
if not cracked_file:
cracked_file = os.path.expanduser("~/.local/share/hashcat/hashcat.potfile")
# Set default output file name if not specified
if not output_file:
output_file = f"{ntds_file}_passwords.txt"
try:
with open(cracked_file, 'r') as cracked:
with open(output_file, 'a') as output:
for line in cracked:
hash, password = line.strip().split(':', 1)
if len(password) > 0:
with open(ntds_file, 'r') as ntds:
for line2 in ntds:
user, ntds_hash = line2.strip().split(':', 1)
if hash == ntds_hash:
print(f"{user}:{password}")
output.write(f"{user}:{password}\n")
except FileNotFoundError as e:
print(f"Error: {e.strerror} - {e.filename}")
exit(1)
print(f"All done. Results written to {output_file}.")
# Main function
if __name__ == "__main__":
# Parse command-line arguments
args = parse_args()
# Process the files with provided arguments
process_files(args.ntds, args.cracked, args.output)