-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcx-info
executable file
·114 lines (97 loc) · 4.06 KB
/
hcx-info
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
108
109
110
111
112
113
#!/usr/bin/env python
import os
import subprocess
from colorama import Fore, Style
from operator import itemgetter
from tabulate import tabulate
import argparse
# Argument parsing
parser = argparse.ArgumentParser(description='Print a table for WPA-PBKDF2-PMKID+EAPOL hashes in file')
parser.add_argument('-s', '--sort', metavar='clm_num', type=int, help="sort output by column")
parser.add_argument('-v', '--vendor', action='store_true', help="fetch vendor information for all MACs")
parser.add_argument('-n', '--nohashcat', action='store_true', help="dont't fetch passwords from hashcat")
parser.add_argument('-c', '--nocolor', action='store_true', help="dont't use colors when printing")
parser.add_argument('-g', '--search', metavar='search_str', type=str, help="search hash by (ESSID, BSSID, MAC, ...) and print line")
parser.add_argument('filename', type=argparse.FileType('r'))
args = parser.parse_args()
# Convert hex string to UTF-8
def hex2str(hex_string):
try:
return bytes.fromhex(hex_string).decode('utf-8')
except ValueError:
if args.nocolor:
return "HEX ERROR"
else:
return f"{Style.NORMAL}{Fore.RED}HEX ERROR{Style.RESET_ALL}"
# Read the hashes file
with args.filename as file:
hashes_file_lines = file.read().splitlines()
# Vendor lookup setup
mac2ven_cache = {}
if args.vendor:
ouifile_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "mac2ven.lst")
try:
with open(ouifile_path, 'r') as ouifile:
for line in ouifile:
oui_mac, *oui_ven = line.strip().split("\t")
if oui_mac:
mac2ven_cache[oui_mac] = ' '.join(oui_ven)
except FileNotFoundError:
pass
def mac2ven(mac):
if not args.vendor:
return ""
mac_prefix = mac.replace(":", "").replace("-", "").upper()[:6]
return mac2ven_cache.get(mac_prefix, "")
# Hashcat processing
hashcat_items = {}
if not args.nohashcat:
try:
result = subprocess.run(['hashcat', '-m', '22000', '--show', args.filename.name],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
for line in result.stdout.splitlines():
if line:
parts = line.split(":")
if len(parts) >= 5:
hashcat_items[parts[0]] = parts[4]
except subprocess.SubprocessError as e:
print(f"Error running hashcat: {e}")
# Process hash lines
items = []
num = 0
for line in hashes_file_lines:
if not line:
continue
split = line.split("*")
if len(split) < 6:
print("Invalid format")
exit()
num += 1
type_str = "PMKID" if split[1] == "01" else "EAPOL" if split[1] == "02" else ""
hashid, bssid, mac, essid = split[2], split[3], split[4], hex2str(split[5])
passwd = hashcat_items.get(line.split("*")[2], "")
vendor_ap = mac2ven(bssid)
vendor_client = mac2ven(mac)
item = [num, type_str, hashid, bssid, mac, essid, passwd, vendor_ap, vendor_client]
if args.search:
search_term = args.search.lower()
if any(search_term in str(clm).lower() for clm in item):
print(line)
else:
if args.nocolor:
items.append(item)
else:
items.append([
f"{Style.NORMAL}{Fore.YELLOW}{num}{Style.RESET_ALL}",
f"{Style.NORMAL}{Fore.GREEN}{type_str}{Style.RESET_ALL}",
f"{Style.NORMAL}{Fore.GREEN}{hashid}{Style.RESET_ALL}",
f"{Style.NORMAL}{Fore.MAGENTA}{bssid}{Style.RESET_ALL}",
f"{Style.NORMAL}{Fore.BLUE}{mac}{Style.RESET_ALL}",
f"{essid}",
f"{Style.NORMAL}{Fore.RED}{passwd}{Style.RESET_ALL}",
f"{Style.NORMAL}{Fore.MAGENTA}{vendor_ap}{Style.RESET_ALL}",
f"{Style.NORMAL}{Fore.BLUE}{vendor_client}{Style.RESET_ALL}"
])
if args.search: quit()
if args.sort is not None: items = sorted(items, key=itemgetter(args.sort))
print(tabulate(items, headers=["#", "TYPE", "HASH", "MAC AP", "MAC CLIENT", "ESSID", "PASSWORD", "VENDOR AP", "VENDOR CLIENT"]))