Skip to content

Instantly share code, notes, and snippets.

@Stricted
Created February 16, 2017 00:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stricted/274d6986f094f377bdda4be980267a91 to your computer and use it in GitHub Desktop.
Save Stricted/274d6986f094f377bdda4be980267a91 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# hg658c.wordpress.com
# Version 1
# Deutsche Telekom Speedport Hybrid configuration file decoder
import sys
import os
from binascii import hexlify, unhexlify
from Crypto.Cipher import AES
import zlib
AES256CBC_KEY = "DD1FBB7596D0D58BBF336ABA391366ED3ED7460849BB9EFAB9649C999863BF25"
AES256CBC_IV = "B380E17A0C476E8A480B55253ABAE666"
XML_VERSION_STRING = b'<?xml version="1.0" ?>'
def print_usage():
print("Usage : " + sys.argv[0] + " {encrypt | decrypt} input_file output_file")
sys.exit(1)
def load_config(config_file):
if os.path.isfile(config_file):
cf = open(config_file, "rb")
config = cf.read()
cf.close()
else:
print("Config file not found..exiting")
sys.exit(1)
return config
def save_to_file(dest_file, data):
wfile = open(dest_file,"wb")
wfile.write(data)
wfile.close()
def decrypt_config(input_file, output_file):
enc_config=load_config(input_file)
print("Decrypting...")
iv = unhexlify(AES256CBC_IV)
key= unhexlify(AES256CBC_KEY)
cipher = AES.new(key, AES.MODE_CBC, iv)
try:
decrypted_data = cipher.decrypt(enc_config)
decompressed_data=""
decompressed_data = zlib.decompress(decrypted_data)
except:
print("Bad config file...exiting")
sys.exit(1)
decompressed_data = decompressed_data[:-1]
check_config(decompressed_data)
print("Saving decrypted config to " + output_file + "...")
save_to_file(output_file, decompressed_data)
def check_config(new_config_file):
head = new_config_file[0:len(XML_VERSION_STRING)]
if head != XML_VERSION_STRING:
print("Not a valid config file...exiting")
sys.exit(1)
def encrypt_config(input_file, output_file):
new_config_data=load_config(input_file)
check_config(new_config_data)
new_config_data += b'\0'
print("Compressing config...")
compressed_data = zlib.compress(new_config_data, 9)
padding_amount = len(compressed_data) % 16
print("" + str(padding_amount) + " bytes padding needed")
print("Adding padding...")
compressed_data=compressed_data + b'\0'*(16-padding_amount)
print("Encrypting config...")
iv = unhexlify(AES256CBC_IV)
key= unhexlify(AES256CBC_KEY)
aes = AES.new(key, AES.MODE_CBC, iv)
enc_new_config = aes.encrypt(compressed_data)
print("Saving encrypted config to " + output_file + "...")
save_to_file(output_file, enc_new_config)
def main():
if len(sys.argv) < 4:
print_usage()
input_file = sys.argv[2]
output_file = sys.argv[3]
command = sys.argv[1]
if (command == "encrypt"):
encrypt_config(input_file, output_file)
elif (command == "decrypt"):
decrypt_config(input_file, output_file)
else:
print_usage()
if __name__ == "__main__":
main()
@Stefan-1982
Copy link

hallo ich bekomme die Fehlermeldung Traceback (most recent call last):
File "....../speedport_hybrid_configtool.py", line 9, in
from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'

an was kann das liegen ?

sorry bin neuling und nutze einen mac und habe mir deshalb Python geladen weil ich für den Speedport Hybrid diese .config Decoden wollte.

@Lubastos
Copy link

Probiere mal "pip install pycrypto" in der Kommandozeile auszuführen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment