From 4cf62de3fd5b40c4720905635a4526cba089ffbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Wed, 15 Nov 2017 14:21:45 +0100 Subject: [PATCH 1/2] Fixing up encoders --- server/src/uds/core/util/AutoAttributes.py | 4 ++-- server/src/uds/core/util/FileStorage.py | 6 ++++-- server/src/uds/core/util/encoders.py | 4 ++-- server/src/uds/models/DBFile.py | 11 ++++++++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/server/src/uds/core/util/AutoAttributes.py b/server/src/uds/core/util/AutoAttributes.py index 7e759db0b..af9deaf6b 100644 --- a/server/src/uds/core/util/AutoAttributes.py +++ b/server/src/uds/core/util/AutoAttributes.py @@ -96,9 +96,9 @@ class AutoAttributes(Serializable): return # We keep original data (maybe incomplete) try: - data = encoders.decode_bz2(data) + data = encoders.decode(data, 'bzip2') except Exception: # With old zip encoding - data = encoders.decode_zip(data) + data = encoders.decode(data, 'zip') for pair in data.split('\2'): k, v = pair.split('\1') self.dict[k] = pickle.loads(str(v)) diff --git a/server/src/uds/core/util/FileStorage.py b/server/src/uds/core/util/FileStorage.py index 38f3633da..5658f6bb2 100644 --- a/server/src/uds/core/util/FileStorage.py +++ b/server/src/uds/core/util/FileStorage.py @@ -50,6 +50,7 @@ logger = logging.getLogger(__name__) class FileStorage(Storage): + def __init__(self, *args, **kwargs): self._base_url = getattr(settings, 'FILE_STORAGE', '/files') if self._base_url[-1] != '/': @@ -60,6 +61,7 @@ class FileStorage(Storage): try: cache = caches[cacheName] except: + logger.info('No cache for FileStorage configured.') cache = None self.cache = cache @@ -73,7 +75,6 @@ class FileStorage(Storage): Storage.__init__(self, *args, **kwargs) - def get_valid_name(self, name): return name.replace('\\', os.path.sep) @@ -119,7 +120,6 @@ class FileStorage(Storage): return self.cache.delete(self._getKey(name)) - def _open(self, name, mode='rb'): f = six.BytesIO(self._dbFileForReadOnly(name).data) f.name = name @@ -173,7 +173,9 @@ class FileStorage(Storage): except DBFile.DoesNotExist: return None + class CompressorFileStorage(FileStorage): + def __init__(self, *args, **kwargs): FileStorage.__init__(self, *args, **dict(kwargs, owner='compressor')) diff --git a/server/src/uds/core/util/encoders.py b/server/src/uds/core/util/encoders.py index 391efea49..e6ebe8f5a 100644 --- a/server/src/uds/core/util/encoders.py +++ b/server/src/uds/core/util/encoders.py @@ -41,14 +41,14 @@ def __toBinary(data): return data -def encode(data, encoder, asText): +def encode(data, encoder, asText=False): res = codecs.encode(__toBinary(data), encoder) if asText: return res.decode('utf8') return res -def decode(data, encoder, asText): +def decode(data, encoder, asText=False): res = codecs.decode(__toBinary(data), encoder) if asText: return res.decode('utf8') diff --git a/server/src/uds/models/DBFile.py b/server/src/uds/models/DBFile.py index 4732ea021..e0df84750 100644 --- a/server/src/uds/models/DBFile.py +++ b/server/src/uds/models/DBFile.py @@ -58,7 +58,16 @@ class DBFile(UUIDModel): @property def data(self): - return encoders.decode(encoders.decode(self.content, 'base64'), 'zip') + try: + return encoders.decode(encoders.decode(self.content, 'base64'), 'zip') + except Exception: + logger.error('DBFile {} has errors and cannot be used'.format(self.name)) + try: + self.delete() # Autodelete, invalid... + except: + logger.error('Could not even delete {}!!'.format(self.name)) + + return '' @data.setter def data(self, value): From ec5473d99fd2dc4e2f4d5da37e503f48623b4a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Wed, 15 Nov 2017 15:36:36 +0100 Subject: [PATCH 2/2] Fixed autoatrributes && rdp --- server/src/uds/core/util/AutoAttributes.py | 2 +- server/src/uds/transports/RDP/RDPFile.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/src/uds/core/util/AutoAttributes.py b/server/src/uds/core/util/AutoAttributes.py index af9deaf6b..31ccb5f64 100644 --- a/server/src/uds/core/util/AutoAttributes.py +++ b/server/src/uds/core/util/AutoAttributes.py @@ -96,7 +96,7 @@ class AutoAttributes(Serializable): return # We keep original data (maybe incomplete) try: - data = encoders.decode(data, 'bzip2') + data = encoders.decode(data, 'bz2') except Exception: # With old zip encoding data = encoders.decode(data, 'zip') for pair in data.split('\2'): diff --git a/server/src/uds/transports/RDP/RDPFile.py b/server/src/uds/transports/RDP/RDPFile.py index 55ac5abca..b5e917280 100644 --- a/server/src/uds/transports/RDP/RDPFile.py +++ b/server/src/uds/transports/RDP/RDPFile.py @@ -27,7 +27,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ''' Created on Jul 29, 2011 @@ -40,7 +39,7 @@ from uds.core.util import OsDetector import six import os -__updated__ = '2017-09-01' +__updated__ = '2017-11-15' class RDPFile(object): @@ -143,13 +142,24 @@ class RDPFile(object): params.append('/h:{}'.format(self.height)) params.append('/bpp:{}'.format(self.bpp)) + + # RDP Security is A MUST if no username nor password is provided + # NLA requires USERNAME&PASSWORD previously + forceRDPSecurity = False if self.username != '': params.append('/u:{}'.format(self.username)) + else: + forceRDPSecurity = True if self.password != '': params.append('/p:{}'.format(self.password)) + else: + forceRDPSecurity = True if self.domain != '': params.append('/d:{}'.format(self.domain)) + if forceRDPSecurity: + params.append('/sec:rdp') + if self.linuxCustomParameters is not None and self.linuxCustomParameters.strip() != '': params.append(self.linuxCustomParameters.strip())