Skip to content

Instantly share code, notes, and snippets.

@gronono
Created June 14, 2020 23:50
Show Gist options
  • Save gronono/fdae56a2bd8806a307d4c1bf0228cc06 to your computer and use it in GitHub Desktop.
Save gronono/fdae56a2bd8806a307d4c1bf0228cc06 to your computer and use it in GitHub Desktop.
Python script to decode passwords stored by Remmina
#!/usr/bin/env python3
import base64
from Crypto.Cipher import DES3
import os
import pprint
REMMINA_PREF_FILE = os.getenv('HOME') + '/.config/remmina/remmina.pref'
REMMINA_FOLDER = os.getenv('HOME') + '/.local/share/remmina/'
def read_secret():
with open(REMMINA_PREF_FILE, 'rt') as pref:
for line in pref:
if line.startswith('secret='):
return line[len('secret='):-1]
sys.exit('Secret not found in file ' + REMMINA_PREF_FILE)
def create_cipher(secret):
decoded = base64.b64decode(secret)
return DES3.new(decoded[:24], DES3.MODE_CBC, decoded[24:])
def lookup():
files = []
for file in os.listdir(REMMINA_FOLDER):
fullPath = REMMINA_FOLDER + '/' + file
if os.path.isfile(fullPath) and file.endswith('.remmina'):
files.append(fullPath)
return files
def read_file(file):
KEYS = ['name', 'username', 'password']
entries = dict()
with open(file, 'rt') as lines:
for line in lines:
for key in KEYS:
if line.startswith(key + '='):
entries[key] = line[len(key + '='):-1]
return entries
def decrypt(password, secret):
decoded = base64.b64decode(password)
cipher = create_cipher(secret)
decrypted = cipher.decrypt(decoded)
return decrypted.decode('utf-8').rstrip('\x00')
def main():
secret = read_secret()
print('Name;Username;Password')
for file in lookup():
entries = read_file(file)
entries['password'] = decrypt(entries['password'], secret)
print(entries['name'] + ';' + entries['username'] + ';' + entries['password'])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment