ftp21

VD625 Config Decrypt

Mar 5th, 2020
452
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. from Crypto.Cipher import AES
  3. import hashlib
  4. import zlib
  5. import binascii
  6.  
  7. def sercomm_hexdigest(s):
  8.     # Replicates a really odd behaviour in the Sercomm libfwutil implementation of hex-digest to hex-string
  9.     # Hexadecimal digits starting prefixed with a '0' have their leading zero removed and are followed by a trailing null byte.
  10.     hex_s = ''
  11.     for c in s:
  12.         c_hex = c.encode('hex')
  13.         if c_hex.startswith('0'):
  14.             hex_s += c_hex[1:]
  15.             hex_s += '\x00'
  16.         else:
  17.             hex_s += c_hex
  18.     return hex_s
  19. def keyPermutator(key):
  20.     perm_tbl = '26aejsw37bfktx48chmuy59dipvz'
  21.     key = bytearray(key)
  22.     for i in xrange(len(key)):
  23.         key[i] = perm_tbl[key[i] % len(perm_tbl)]
  24.     return str(key)
  25.  
  26. def getKeyPair(a0="",a1="",a2="",kf=""):
  27.     digest_1 = hashlib.new('md5')
  28.     digest_1.update(a0)
  29.     digest_1.update(a1)
  30.     digest_2 = hashlib.new('md5')
  31.     digest_2.update(a0)
  32.     digest_2.update(a2)
  33.     digest_3 = hashlib.new('md5')
  34.     digest_3.update(a1)
  35.     digest_3.update(a2)
  36.     digest_fin = hashlib.new('md5')
  37.     digest_fin.update(digest_1.digest())
  38.     digest_fin.update(digest_2.digest())
  39.     digest_fin.update(digest_3.digest())
  40.     key = keyPermutator(sercomm_hexdigest(digest_fin.digest()))
  41.     return dict(key=key, iv='\x00' * 32)
  42. if __name__ == "__main__":
  43.     binfile=''
  44.     k=getKeyPair(a0='sErCoMm',a1='vD625',a2='AGCOMBO')
  45.     print "KEY: %s" % (k['key'])
  46.     #decrypt file
  47.     with open(sys.argv[1]) as f:
  48.         while True:
  49.             c = f.read(2)
  50.             if not c:
  51.                 break
  52.             r=int(c,16)
  53.             binfile+=chr(r)
  54.     decrypted=open(sys.argv[1]+".decrypted","wb")
  55.     aes = AES.new(key=k['key'], mode=AES.MODE_CBC, IV=k['iv'][16:])
  56.     plaintext_body = aes.decrypt(binfile)
  57.     print "HEADER: %s" % (binascii.hexlify(plaintext_body[:32]))
  58.     decrypted.write(zlib.decompress(plaintext_body[32:]))
  59.     decrypted.close()
  60.     print "Output file: %s.decrypted" % (sys.argv[1])
RAW Paste Data