Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from Crypto.Cipher import AES
- import hashlib
- import zlib
- import binascii
- def sercomm_hexdigest(s):
- # Replicates a really odd behaviour in the Sercomm libfwutil implementation of hex-digest to hex-string
- # Hexadecimal digits starting prefixed with a '0' have their leading zero removed and are followed by a trailing null byte.
- hex_s = ''
- for c in s:
- c_hex = c.encode('hex')
- if c_hex.startswith('0'):
- hex_s += c_hex[1:]
- hex_s += '\x00'
- else:
- hex_s += c_hex
- return hex_s
- def keyPermutator(key):
- perm_tbl = '26aejsw37bfktx48chmuy59dipvz'
- key = bytearray(key)
- for i in xrange(len(key)):
- key[i] = perm_tbl[key[i] % len(perm_tbl)]
- return str(key)
- def getKeyPair(a0="",a1="",a2="",kf=""):
- digest_1 = hashlib.new('md5')
- digest_1.update(a0)
- digest_1.update(a1)
- digest_2 = hashlib.new('md5')
- digest_2.update(a0)
- digest_2.update(a2)
- digest_3 = hashlib.new('md5')
- digest_3.update(a1)
- digest_3.update(a2)
- digest_fin = hashlib.new('md5')
- digest_fin.update(digest_1.digest())
- digest_fin.update(digest_2.digest())
- digest_fin.update(digest_3.digest())
- key = keyPermutator(sercomm_hexdigest(digest_fin.digest()))
- return dict(key=key, iv='\x00' * 32)
- if __name__ == "__main__":
- binfile=''
- k=getKeyPair(a0='sErCoMm',a1='vD625',a2='AGCOMBO')
- print "KEY: %s" % (k['key'])
- #decrypt file
- with open(sys.argv[1]) as f:
- while True:
- c = f.read(2)
- if not c:
- break
- r=int(c,16)
- binfile+=chr(r)
- decrypted=open(sys.argv[1]+".decrypted","wb")
- aes = AES.new(key=k['key'], mode=AES.MODE_CBC, IV=k['iv'][16:])
- plaintext_body = aes.decrypt(binfile)
- print "HEADER: %s" % (binascii.hexlify(plaintext_body[:32]))
- decrypted.write(zlib.decompress(plaintext_body[32:]))
- decrypted.close()
- print "Output file: %s.decrypted" % (sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement