예제 #1
0
파일: UDSClient.py 프로젝트: dkmstr/openuds
def approveHost(host):
    from os.path import expanduser
    hostsFile = expanduser('~/.udsclient.hosts')

    try:
        with open(hostsFile, 'r') as f:
            approvedHosts = f.read().splitlines()
    except Exception:
        approvedHosts = []

    host = host.lower()

    if host in approvedHosts:
        return True

    errorString = 'The server {} must be approved:\n'.format(host)
    errorString += 'Only approve UDS servers that you trust to avoid security issues.'

    approved = ui.question("ACCESS Warning", errorString)

    if approved:
        approvedHosts.append(host)
        logger.debug('Host was approved, saving to approvedHosts file')
        try:
            with open(hostsFile, 'w') as f:
                f.write('\n'.join(approvedHosts))
        except Exception:
            logger.warn('Got exception writing to {}'.format(hostsFile))

    return approved
예제 #2
0
def approveHost(host):
    from os.path import expanduser
    hostsFile = expanduser('~/.udsclient.hosts')

    try:
        with open(hostsFile, 'r') as f:
            approvedHosts = f.read().splitlines()
    except Exception:
        approvedHosts = []

    host = host.lower()

    if host in approvedHosts:
        return True

    errorString = 'The server {} must be approved:\n'.format(host)
    errorString += 'Only approve UDS servers that you trust to avoid security issues.'

    approved = ui.question("ACCESS Warning", errorString)

    if approved:
        approvedHosts.append(host)
        logger.debug('Host was approved, saving to approvedHosts file')
        try:
            with open(hostsFile, 'w') as f:
                f.write('\n'.join(approvedHosts))
        except Exception:
            logger.warn('Got exception writing to {}'.format(hostsFile))

    return approved
예제 #3
0
import six

try:
    thePass = six.binary_type(
        sp['password'].encode('UTF-16LE'))  # @UndefinedVariable
    password = win32crypt.CryptProtectData(thePass, None, None, None, None,
                                           0x01).encode('hex')
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, sp['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 = sp['as_file'].format(  # @UndefinedVariable
    password=password)
filename = tools.saveTempFile(theFile)
executable = tools.findApp('mstsc.exe')
subprocess.Popen([executable, filename])
tools.addFileToUnlink(filename)
예제 #4
0
파일: tunnel.py 프로젝트: dkmstr/openuds
tools.addTaskToWait(forwardThread)

try:
    thePass = six.binary_type(sp['password'].encode('UTF-16LE'))  # @UndefinedVariable
    password = win32crypt.CryptProtectData(thePass, None, None, None, None, 0x01).encode('hex')
except Exception:
    # Cannot encrypt for user, trying for machine
    password = win32crypt.CryptProtectData(thePass, None, None, None, None, 0x05).encode('hex')

# 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 = sp['as_file'].format(# @UndefinedVariable
    password=password,
    address='127.0.0.1:{}'.format(port)
)

filename = tools.saveTempFile(theFile)
executable = tools.findApp('mstsc.exe')
if executable is None:
    raise Exception('Unable to find mstsc.exe')

try:
    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 fixing redirection dialog: %s', e)

subprocess.Popen([executable, filename])
tools.addFileToUnlink(filename)