Summery
Script to decrypt the password inside of the C:\Program Files (x86)\hMailServer\Bin\hMailServer.ini file.
Best run with uv.
Script
#!/usr/bin/env python3
# /// script
# dependencies = ["pycryptodome"]
# ///
import sys
import binascii
import struct
from Crypto.Cipher import Blowfish
def swap_endianness(data):
"""Swap endianness of each 4-byte word"""
result = b''
for i in range(0, len(data), 4):
word = data[i:i+4]
if len(word) == 4:
result += word[::-1]
else:
result += word
return result
if len(sys.argv) != 2:
print(f"usage: {sys.argv[0]} <enc>")
sys.exit()
key = b'THIS_KEY_IS_NOT_SECRET'
encrypted_hex = sys.argv[1]
encrypted = binascii.unhexlify(encrypted_hex)
encrypted_swapped = swap_endianness(encrypted)
cipher = Blowfish.new(key, Blowfish.MODE_ECB)
decrypted = cipher.decrypt(encrypted_swapped)
decrypted_swapped = swap_endianness(decrypted)
print(f"Decrypted: {decrypted_swapped.rstrip(b'\x00').decode('utf-8', errors='replace')}")References
Used in: JobTwo
Similar concepts: hMailServer