|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import hashlib |
| 4 | +import base64 |
| 5 | +from Cryptodome.Cipher import AES |
| 6 | +import argparse |
| 7 | +import sys |
| 8 | + |
| 9 | +def main(): |
| 10 | + parser = argparse.ArgumentParser(description="Decrypt mRemoteNG passwords.") |
| 11 | + group = parser.add_mutually_exclusive_group() |
| 12 | + group.add_argument("-f", "--file", help="name of file containing mRemoteNG password") |
| 13 | + group.add_argument("-s", "--string", help="base64 string of mRemoteNG password") |
| 14 | + parser.add_argument("-p", "--password", help="Custom password", default="mR3m") |
| 15 | + |
| 16 | + if len(sys.argv) < 2: |
| 17 | + parser.print_help(sys.stderr) |
| 18 | + sys.exit(1) |
| 19 | + |
| 20 | + args = parser.parse_args() |
| 21 | + encrypted_data = "" |
| 22 | + if args.file != None: |
| 23 | + with open(args.file) as f: |
| 24 | + encrypted_data = f.read() |
| 25 | + encrypted_data = encrypted_data.strip() |
| 26 | + encrypted_data = base64.b64decode(encrypted_data) |
| 27 | + |
| 28 | + elif args.string != None: |
| 29 | + encrypted_data = args.string |
| 30 | + encrypted_data = base64.b64decode(encrypted_data) |
| 31 | + |
| 32 | + else: |
| 33 | + print("Please use either the file (-f, --file) or string (-s, --string) flag") |
| 34 | + sys.exit(1) |
| 35 | + |
| 36 | + salt = encrypted_data[:16] |
| 37 | + associated_data = encrypted_data[:16] |
| 38 | + nonce = encrypted_data[16:32] |
| 39 | + ciphertext = encrypted_data[32:-16] |
| 40 | + tag = encrypted_data[-16:] |
| 41 | + key = hashlib.pbkdf2_hmac("sha1", args.password.encode(), salt, 1000, dklen=32) |
| 42 | + |
| 43 | + cipher = AES.new(key, AES.MODE_GCM, nonce=nonce) |
| 44 | + cipher.update(associated_data) |
| 45 | + plaintext = cipher.decrypt_and_verify(ciphertext, tag) |
| 46 | + print("Password: {}".format(plaintext.decode("utf-8"))) |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + main() |
0 commit comments