Skip to content

Instantly share code, notes, and snippets.

@SciresM
Created January 3, 2018 09:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SciresM/c75f4b240f365cc05a690b77b9e51b08 to your computer and use it in GitHub Desktop.
Save SciresM/c75f4b240f365cc05a690b77b9e51b08 to your computer and use it in GitHub Desktop.
from struct import unpack as up, pack as pk
from binascii import unhexlify as uhx, hexlify as hx
from Crypto.Cipher import AES
from Crypto.Util import Counter
import sys
pk11key = uhx('') # Insert key here.
def string_to_ctr(ctr):
return Counter.new(128, initial_value=int(hx(ctr), 16))
def main(argc, argv):
if argc == 2:
out_fn = '%s.dec' % argv[1]
elif argc == 3:
out_fn = argv[2]
else:
print 'Usage: %s package1 out_fn' % argv[0]
sys.exit(1)
try:
with open(argv[1], 'rb') as f:
pk11 = f.read()
except IOError:
print 'Failed to read %s!' % argv[1]
sys.exit(1)
sz, padding, ctr = up('<I12s16s', pk11[0x3FE0:0x4000])
aes = AES.new(pk11key, AES.MODE_CTR, counter=string_to_ctr(ctr))
dec = aes.decrypt(pk11[0x4000:])
if not dec.startswith('PK11'):
print '%s is not a decryptable package1!' % argv[1]
sys.exit(1)
try:
with open(out_fn, 'wb') as f:
f.write(dec)
except IOError:
print 'Failed to write to %s' % out_fn
return 0
if __name__ == '__main__':
sys.exit(main(len(sys.argv), sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment