Skip to content

Instantly share code, notes, and snippets.

@llouislu
Created December 17, 2018 07:29
Show Gist options
  • Select an option

  • Save llouislu/a76548ee0c2143e8ea8dc136e16f18a9 to your computer and use it in GitHub Desktop.

Select an option

Save llouislu/a76548ee0c2143e8ea8dc136e16f18a9 to your computer and use it in GitHub Desktop.
Zte configuration file decrypt tool
#!/usr/bin/env python3
import re
import zlib
import struct
import sys
def extract_config_xml(config_bin):
'''
https://reverseengineering.stackexchange.com/a/9246
'''
config_xml = b''
for zlib_chunk in re.finditer(b'\x78\xda', config_bin):
zlib_chunk_start = zlib_chunk.start()
zlib_chunk_header = config_bin[zlib_chunk_start - 12: zlib_chunk_start]
xml_chunk_length, zlib_chunk_length, config_bin_length = \
struct.unpack('>LLL', zlib_chunk_header)
if xml_chunk_length == 0x10000 or config_bin_length == 0:
zlib_chunk_end = zlib_chunk_start + zlib_chunk_length
zlib_chunk = config_bin[zlib_chunk_start: zlib_chunk_end]
xml_chunk = zlib.decompress(zlib_chunk)
assert xml_chunk_length == len(xml_chunk)
config_xml += xml_chunk
return config_xml
if __name__ == '__main__':
if len(sys.argv) < 2:
print('{} <zte_config> <xml_output>'.format(__file__))
exit()
in_file = sys.argv[1]
out_file = in_file + '.xml'
with open(in_file, 'rb') as f:
xml = extract_config_xml(f.read())
with open(out_file, 'wb') as fo:
fo.write(xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment