forked from AlessandroZ/LaZagne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e905721
commit 2295701
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from lazagne.config.write_output import print_debug | ||
from lazagne.config.moduleInfo import ModuleInfo | ||
from lazagne.config.WinStructure import * | ||
from lazagne.config.constant import * | ||
import xml.etree.cElementTree as ET | ||
import base64 | ||
import os | ||
|
||
class RDPManager(ModuleInfo): | ||
def __init__(self): | ||
options = {'command': '--rdp', 'action': 'store_true', 'dest': 'rdp_manager', 'help': 'RDP Connection Manager'} | ||
ModuleInfo.__init__(self, 'rdpmanager', 'sysadmin', options) | ||
|
||
def decrypt_password(self, encrypted_password): | ||
try: | ||
decoded = base64.b64decode(encrypted_password) | ||
password_decryped = Win32CryptUnprotectData(decoded) | ||
password_decryped = password_decryped.replace('\x00', '') | ||
except: | ||
password_decryped = encrypted_password.replace('\x00', '') | ||
return password_decryped | ||
|
||
def format_output_tag(self, tag): | ||
tag = tag.lower() | ||
if 'username' in tag: | ||
tag = 'Login' | ||
elif 'hostname' in tag: | ||
tag = 'URL' | ||
return tag.capitalize() | ||
|
||
def check_tag_content(self, values, c): | ||
# values = {} | ||
if 'password' in c.tag.lower(): | ||
values['Password'] = self.decrypt_password(c.text) | ||
else: | ||
tag = self.format_output_tag(c.tag) | ||
values[tag] = c.text | ||
return values | ||
|
||
def parse_element(self, root, element): | ||
pwdFound = [] | ||
try: | ||
for r in root.findall(element): | ||
values = {} | ||
for child in r.getchildren(): | ||
if child.tag == 'properties': | ||
for c in child.getchildren(): | ||
values = self.check_tag_content(values, c) | ||
elif child.tag == 'logonCredentials': | ||
for c in child.getchildren(): | ||
values = self.check_tag_content(values, c) | ||
else: | ||
values = self.check_tag_content(values, child) | ||
if values: | ||
pwdFound.append(values) | ||
except Exception, e: | ||
print_debug('DEBUG', str(e)) | ||
|
||
return pwdFound | ||
|
||
def parse_xml(self, setting): | ||
tree = ET.ElementTree(file=setting) | ||
root = tree.getroot() | ||
pwdFound = [] | ||
|
||
elements = [ | ||
'CredentialsProfiles/credentialsProfiles/credentialsProfile', | ||
'DefaultGroupSettings/defaultSettings/logonCredentials', | ||
'file/server', | ||
] | ||
|
||
for element in elements: | ||
pwdFound += self.parse_element(root, element) | ||
|
||
try: | ||
for r in root.find('FilesToOpen'): | ||
if os.path.exists(r.text): | ||
print_debug('INFO', 'New setting file found: %s' % r.text) | ||
pwdFound += self.parse_xml(r.text) | ||
except: | ||
pass | ||
|
||
return pwdFound | ||
|
||
def run(self, software_name = None): | ||
settings = [ | ||
'%s\\Microsoft Corporation\\Remote Desktop Connection Manager\\RDCMan.settings' % os.environ.get('LocalAppData', ''), | ||
'%s\\Microsoft\\Remote Desktop Connection Manager\\RDCMan.settings' % os.environ.get('LocalAppData', '') | ||
] | ||
|
||
for setting in settings: | ||
if os.path.exists(setting): | ||
print_debug('INFO', 'Setting file found: %s' % setting) | ||
return self.parse_xml(setting) |