Skip to content

Instantly share code, notes, and snippets.

@silverairedale
Created April 19, 2021 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silverairedale/e560eebcace43e95da7c74aa82dd824c to your computer and use it in GitHub Desktop.
Save silverairedale/e560eebcace43e95da7c74aa82dd824c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from base64 import standard_b64decode
from pathlib import Path
import sys
try:
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
except ImportError:
sys.exit("Install pycryptodome: pip install pycryptodome")
if len(sys.argv) != 2:
sys.exit("Usage: unhec.py file.hec")
path = Path(sys.argv[1])
data = path.read_bytes()
if not data.startswith(b"HSENC2"):
sys.exit("Input does not appear to be HECed")
data = standard_b64decode(data[6:])
KEY = b"\xd7\xa6\x8d\xef\x0fJ\x12A\x94\x0fl\xb8\x01q!\xd1_\x0e&\x82\xe2X\xc9\xf7U>pn\x83I#\xb7"
IV = b"\x0ee\x19)u0X7\x08a*(#f8D"
cipher = AES.new(KEY, AES.MODE_CBC, IV)
data = unpad(cipher.decrypt(data), 16)
data = data.replace(b" ", b"\n")
out_path = path.with_suffix(".hex")
out_path.write_bytes(data)
print(f"Wrote {out_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment