Skip to content

Commit 6dc8b96

Browse files
authored
Merge pull request #2 from haseebT/master
Add Python script
2 parents 59ea58e + 4b3c521 commit 6dc8b96

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ org.apache.commons.codec
1212

1313
org.bouncycastle
1414

15-
## PR welcome
15+
## Python Script
1616

17-
I tried so hard to make a version in Python 3, but failed. If someone can do that, please open a PR. thanks.
17+
Usage: `python3 mremoteng_decrypt.py [-f FILE | -s STRING] [-p CUSTOM_PASSWORD]`
1818

1919
## Where's the file?
2020

mremoteng_decrypt.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)