forked from shaba/openuds
Removed execution of "reg", using "winreg" instead (_winreg on 2.7)
This commit is contained in:
parent
8120ae5c92
commit
9451889bb3
@ -4,10 +4,14 @@ from __future__ import unicode_literals
|
||||
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
import win32crypt # @UnresolvedImport
|
||||
try:
|
||||
import winreg as wreg
|
||||
except ImportError: # Python 2.7 fallback
|
||||
import _winreg as wreg # @UnresolvedImport, pylint: disable=import-error
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from uds.log import logger # @UnresolvedImport
|
||||
|
||||
from uds import tools # @UnresolvedImport
|
||||
|
||||
import six
|
||||
@ -19,17 +23,19 @@ except Exception:
|
||||
logger.info('Cannot encrypt for user, trying for machine')
|
||||
password = win32crypt.CryptProtectData(thePass, None, None, None, None, 0x05).encode('hex')
|
||||
|
||||
try:
|
||||
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, 'Software\Microsoft\Terminal Server Client\LocalDevices', 0, wreg.KEY_SET_VALUE) # @UndefinedVariable
|
||||
wreg.SetValueEx(key, '{m.ip}', 0, wreg.REG_DWORD, 255) # @UndefinedVariable
|
||||
wreg.CloseKey(key) # @UndefinedVariable
|
||||
except Exception as e:
|
||||
logger.warn('Exception fixing redirection dialog: %s', e)
|
||||
|
||||
# The password must be encoded, to be included in a .rdp file, as 'UTF-16LE' before protecting (CtrpyProtectData) it in order to work with mstsc
|
||||
theFile = '''{m.r.as_file}'''.format(password=password)
|
||||
|
||||
filename = tools.saveTempFile(theFile)
|
||||
executable = tools.findApp('mstsc.exe')
|
||||
|
||||
try:
|
||||
subprocess.call([r'c:\windows\system32\reg.exe', 'ADD', r'HKCU\Software\Microsoft\Terminal Server Client\LocalDevices', '/v', '{m.ip}', '/t', 'REG_DWORD', '/d', '255', '/f'])
|
||||
except Exception as e:
|
||||
logger.warn('Exception invoking reg.exe : %s', e)
|
||||
|
||||
subprocess.Popen([executable, filename])
|
||||
tools.addFileToUnlink(filename)
|
||||
|
||||
|
@ -5,6 +5,10 @@ from __future__ import unicode_literals
|
||||
# pylint: disable=import-error, no-name-in-module, too-many-format-args, undefined-variable
|
||||
|
||||
import win32crypt # @UnresolvedImport
|
||||
try:
|
||||
import winreg as wreg
|
||||
except ImportError: # Python 2.7 fallback
|
||||
import _winreg as wreg # @UnresolvedImport, pylint: disable=import-error
|
||||
import os
|
||||
import subprocess
|
||||
from uds.forward import forward # @UnresolvedImport
|
||||
@ -40,9 +44,11 @@ if executable is None:
|
||||
raise Exception('Unable to find mstsc.exe')
|
||||
|
||||
try:
|
||||
subprocess.call([r'c:\windows\system32\reg.exe', 'ADD', r'HKCU\Software\Microsoft\Terminal Server Client\LocalDevices', '/v', '127.0.0.1', '/t', 'REG_DWORD', '/d', '255', '/f'])
|
||||
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, 'Software\Microsoft\Terminal Server Client\LocalDevices', 0, wreg.KEY_SET_VALUE) # @UndefinedVariable
|
||||
wreg.SetValueEx(key, '127.0.0.1', 0, wreg.REG_DWORD, 255) # @UndefinedVariable
|
||||
wreg.CloseKey(key) # @UndefinedVariable
|
||||
except Exception as e:
|
||||
logger.warn('Exception invoking reg.exe : %s', e)
|
||||
logger.warn('Exception fixing redirection dialog: %s', e)
|
||||
|
||||
subprocess.Popen([executable, filename])
|
||||
tools.addFileToUnlink(filename)
|
||||
|
Loading…
x
Reference in New Issue
Block a user