Created
December 11, 2024 03:45
-
-
Save hadrian3689/471f0942588529a353c0020eaea5ddc2 to your computer and use it in GitHub Desktop.
A PwmConfiguration.xml decryptor in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import hashlib | |
from Crypto.Cipher import AES #pip install pycryptodome | |
def pwm_cipher(): | |
#Create a new AES cipher object using AES-128 in ECB mode. | |
return AES.new(key=b'0'*16, mode=AES.MODE_ECB) # Placeholder key, actual key will be set later | |
def pwm_make_key(key: str) -> bytes: | |
#Derive a 16-byte AES key from the given input key. | |
return hashlib.sha1(key.encode()).digest()[:16] | |
def pwm_decrypt(key: str, crypt: str) -> str: | |
#Decrypt the encrypted text using the given key and AES-128-ECB. | |
aes_key = pwm_make_key(key) | |
cipher = AES.new(aes_key, AES.MODE_ECB) | |
encrypted_bytes = base64.urlsafe_b64decode(crypt) | |
decrypted_bytes = cipher.decrypt(encrypted_bytes) | |
# Remove PKCS#7 padding | |
pad_length = decrypted_bytes[-1] | |
decrypted_text = decrypted_bytes[:-pad_length].decode('utf-8') | |
return decrypted_text | |
def main(): | |
#grep "<PwmConfiguration" PwmConfiguration.xml | sed 's/^.*createTime[^"]*"\([^"]*\)".*/\1StoredConfiguration/' | |
#The secret key consists of the 'createTime' attribute of the root element of the file, concatenated | |
key = "2022-08-11T01:46:23ZStoredConfiguration" | |
#cat PwmConfiguration.xml | grep ENC-PW | |
encrypted_text = "<base64 input without the ENC-PW>" | |
try: | |
decrypted_text = pwm_decrypt(key, encrypted_text) | |
print("Decrypted text:", decrypted_text) | |
except Exception as e: | |
print("An error occurred during decryption:", e) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment