Skip to content

Instantly share code, notes, and snippets.

@RealEnder
Last active July 1, 2025 12:07
Show Gist options
  • Save RealEnder/f2e79f12e4f5c83d148a58b9827c067d to your computer and use it in GitHub Desktop.
Save RealEnder/f2e79f12e4f5c83d148a58b9827c067d to your computer and use it in GitHub Desktop.
Converts john output file for wpapsk formats to hashcat -o and potfile
#!/usr/bin/python3
# Converts john output file for wpapsk formats to hashcat -o and potfile
# The source code is distributed under MIT license
# author: Alex Stanev, alex at stanev dot org
# web: http://wpa-sec.stanev.org
import sys
import os
from binascii import a2b_base64
from hashlib import pbkdf2_hmac, md5
if len(sys.argv) != 2 or not os.path.exists(sys.argv[1]):
print(f"Usage: {sys.argv[0]} [john.pot]")
exit(1)
c = 0
with open(sys.argv[1], 'r', encoding='utf-8') as jpot, \
open(f"{sys.argv[1]}.pot", 'w', encoding='ascii') as hpot, \
open(f"{sys.argv[1]}.mac", 'w', encoding='utf-8') as hmac:
for line in jpot:
line = line.rstrip('\r\n')
pmk = None
# process handshake
if line.startswith('$WPAPSK$'):
arr = line.split(':', 1)
if len(arr) != 2:
continue
key = arr[1]
arr = arr[0].rsplit('#', 1)
if len(arr) != 2:
continue
ssid = arr[0][8:]
b64 = arr[1].translate(bytearray.maketrans('./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.encode(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.encode())) + '='
#print(b64)
phccap = a2b_base64(b64)
bssid = bytes(phccap[:6]).hex()
mac_sta = bytes(phccap[6:12]).hex()
pmk = pbkdf2_hmac("sha1", key.encode(), ssid.encode(), 4096, 32).hex()
# process PMKID
if line[:59].count('*') == 3:
arr = line.rsplit(':', 1)
if len(arr) != 2:
continue
key = arr[1]
arr = arr[0].split('*')
if len(arr) != 4:
continue
bssid = arr[1]
mac_sta = arr[2]
ssid = bytearray.fromhex(arr[3]).decode()
pmk = pbkdf2_hmac("sha1", key.encode(), ssid.encode(), 4096, 32).hex()
if pmk:
# In -o output hashcat uses partial md5(). This scrript will NOT produce the same value in the first -o field
hpot.write(f"{pmk}*{ssid.encode().hex()}:{key.encode().hex()}\n")
hmac.write(f"{md5(line.encode()).hexdigest()}:{bssid}:{mac_sta}:{ssid}:{key}\n")
c += 1
print(f"{c} lines converted")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment