diff --git a/server/src/uds/core/transports/transport.py b/server/src/uds/core/transports/transport.py index 89a4081c..6e12aade 100644 --- a/server/src/uds/core/transports/transport.py +++ b/server/src/uds/core/transports/transport.py @@ -30,6 +30,8 @@ """ @author: Adolfo Gómez, dkmaster at dkmon dot com """ +import os +import sys import codecs import logging import json @@ -275,6 +277,33 @@ class Transport(Module): parameters=transport_script.parameters, ) + def getRelativeScript( + self, scriptName: str, params: typing.Mapping[str, typing.Any] + ) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]: + """Returns a script that will be executed on client, but will be downloaded from server + + Args: + scriptName: Name of the script to be downloaded, relative path (i.e. 'scripts/direct/transport.py') + params: Parameters for the return tuple + """ + # Reads script and signature + basePath = os.path.dirname(sys.modules[self.__module__].__file__ or 'not_found') # Will raise if not found + + script = open(os.path.join(basePath, scriptName), 'r').read() + signature = open(os.path.join(basePath, scriptName + '.signature'), 'r').read() + + return script, signature, params + + def getScript( + self, osName: str, type: typing.Literal['tunnel', 'direct'], params: typing.Mapping[str, typing.Any] + ) -> typing.Tuple[str, str, typing.Mapping[str, typing.Any]]: + """ + Returns a script for the given os and type + """ + return self.getRelativeScript( + 'scripts/{os}/{type}.py'.format(os=osName, type=type), params + ) + def getLink( self, userService: 'models.UserService', diff --git a/server/src/uds/core/util/tools.py b/server/src/uds/core/util/tools.py index f6de6b64..580a78cc 100644 --- a/server/src/uds/core/util/tools.py +++ b/server/src/uds/core/util/tools.py @@ -130,7 +130,7 @@ def packageRelativeFile(moduleName: str, fileName: str) -> str: This allows to keep images alongside report """ mod = sys.modules[moduleName] - if mod and mod.__file__: + if mod and hasattr(mod, '__file__') and mod.__file__: pkgpath = os.path.dirname(mod.__file__) return os.path.join(pkgpath, fileName) # Not found, return fileName diff --git a/server/src/uds/transports/RDP/rdp.py b/server/src/uds/transports/RDP/rdp.py index 9fdb2322..d57eff86 100644 --- a/server/src/uds/transports/RDP/rdp.py +++ b/server/src/uds/transports/RDP/rdp.py @@ -196,4 +196,4 @@ class RDPTransport(BaseRDPTransport): } ) - return self.getScript('scripts/{}/direct.py', osName, sp) + return self.getScript(osName, 'direct', sp) diff --git a/server/src/uds/transports/RDP/rdptunnel.py b/server/src/uds/transports/RDP/rdptunnel.py index 4c878f01..f2f9c82f 100644 --- a/server/src/uds/transports/RDP/rdptunnel.py +++ b/server/src/uds/transports/RDP/rdptunnel.py @@ -243,4 +243,4 @@ class TRDPTransport(BaseRDPTransport): } ) - return self.getScript('scripts/{}/tunnel.py', osName, sp) + return self.getScript(osName, 'tunnel', sp) diff --git a/server/src/uds/transports/SPICE/spice.py b/server/src/uds/transports/SPICE/spice.py index e0e144aa..8ddb4f79 100644 --- a/server/src/uds/transports/SPICE/spice.py +++ b/server/src/uds/transports/SPICE/spice.py @@ -97,6 +97,8 @@ class SPICETransport(BaseSpiceTransport): con['cert_subject'], fullscreen=self.fullScreen.isTrue(), ) + r.proxy = con.get('proxy', None) + r.usb_auto_share = self.usbShare.isTrue() r.new_usb_auto_share = self.autoNewUsbShare.isTrue() r.smartcard = self.smartCardRedirect.isTrue() @@ -119,4 +121,4 @@ class SPICETransport(BaseSpiceTransport): 'as_file': r.as_file, } - return self.getScript('scripts/{}/direct.py', osName, sp) + return self.getScript(osName, 'direct', sp) diff --git a/server/src/uds/transports/SPICE/spicetunnel.py b/server/src/uds/transports/SPICE/spicetunnel.py index 605fac0c..62c5ae44 100644 --- a/server/src/uds/transports/SPICE/spicetunnel.py +++ b/server/src/uds/transports/SPICE/spicetunnel.py @@ -201,4 +201,4 @@ class TSPICETransport(BaseSpiceTransport): 'ticket_secure': ticket_secure, } - return self.getScript('scripts/{}/tunnel.py', osName, sp) + return self.getScript(osName, 'tunnel', sp) diff --git a/server/src/uds/transports/X2GO/x2go.py b/server/src/uds/transports/X2GO/x2go.py index 3f2b54e0..7da9ef0c 100644 --- a/server/src/uds/transports/X2GO/x2go.py +++ b/server/src/uds/transports/X2GO/x2go.py @@ -120,4 +120,4 @@ class X2GOTransport(BaseX2GOTransport): sp = {'ip': ip, 'port': '22', 'key': priv, 'xf': xf} - return self.getScript('scripts/{}/direct.py', osName, sp) + return self.getScript(osName, 'direct', sp) diff --git a/server/src/uds/transports/X2GO/x2gotunnel.py b/server/src/uds/transports/X2GO/x2gotunnel.py index 3090da8a..eef09961 100644 --- a/server/src/uds/transports/X2GO/x2gotunnel.py +++ b/server/src/uds/transports/X2GO/x2gotunnel.py @@ -197,4 +197,4 @@ class TX2GOTransport(BaseX2GOTransport): 'xf': xf, } - return self.getScript('scripts/{}/tunnel.py', osName, sp) + return self.getScript(osName, 'tunnel', sp)