def _setHive(self, val): if (val is None): raise OpsCommandException('You must set hive, hive cannot be None') if (val.lower() in HIVES): self.optdict['hive'] = val.lower() else: raise OpsCommandException(('Invalid hive %s' % val))
def _setLimitAddr(self, value): value = value.strip() if (value == '0.0.0.0'): raise OpsCommandException('Invalid limit IP address 0.0.0.0') elif util.ip.validate(value): self._limitAddr = value else: raise OpsCommandException(('Invalid limit IP address %s' % value))
def _setClientPort(self, value): try: value = int(value) if ((value < 0) or (value > 65535)): raise OpsCommandException( 'Invalid client port, must be an integer between 0-65535') except ValueError: raise OpsCommandException( 'Invalid client port, must be an integer between 0-65535') self._clientPort = value
def _setSourcePort(self, value): try: value = int(value) if ((value < (-1)) or (value > 65535)): raise OpsCommandException( 'Invalid source port, must be an integer between 0-65535 or -1 for unspecified' ) except ValueError: raise OpsCommandException( 'Invalid source port, must be an integer between 0-65535') self._sourcePort = value
def _setProtocol(self, val): if (val == TCP): self.tcp = True elif (val == UDP): self.udp = True else: raise OpsCommandException('Protocol must be tcp or udp')
def _setTargetPort(self, value): try: value = int(value) except ValueError: raise OpsCommandException( 'Invalid target port, must be an integer between 0-65535') self._targetPort = value
def _setTime(self, val): if (val in ['modified', 'created', 'accessed']): self.optdict['time'] = val elif (val is None): del self.optdict['time'] else: raise OpsCommandException( '-time must be one of accessed|created|modified')
def _setChunksize(self, val): if (val is None): if ('chunksize' in self.optdict): del self.optdict['chunksize'] return if (type(val) is int): self.optdict['chunksize'] = val else: raise OpsCommandException('chunksize is required to be an integer')
def _setChunksize(self, val): if (val is not None): try: val = int(val) except: raise OpsCommandException( '-chunksize for a dir command must be an integer') self.optdict['chunksize'] = val else: del self.optdict['chunksize']
def _setPacketsize(self, value): if (value is not None): try: value = int(value) self.optdict['packetsize'] = value except ValueError: raise OpsCommandException( 'Packetsize for a redirect command must be an integer > 0') elif ('packetsize' in self.optdict): del self.optdict['packetsize']
def _setMax(self, val): if (val is not None): try: val = int(val) except: raise OpsCommandException( '-max for a dir command must be an integer') self.optdict['max'] = val else: del self.optdict['max']
def _setConnections(self, value): if (value is not None): try: value = int(value) self.optdict['connections'] = value except ValueError: raise OpsCommandException( 'Max connections for a redirect command must be an integer >= 0' ) else: self.optdict['connections'] = 0
def _setLimitConnections(self, value): if (value is None): self.limit_address = '0.0.0.0' self.limit_mask = '0.0.0.0' else: parts = value.split(' ') if (len(parts) != 2): raise OpsCommandException( 'You must specify limit address and limit mask and nothing else when using connection limiting' ) self.limit_mask = parts[1] self.limit_address = parts[0]
def _setPortsharing(self, value): if (value is None): (self.client_address == '0.0.0.0') self.client_port = (-1) else: parts = value.split(' ') if (len(parts) != 2): raise OpsCommandException( 'You must specify client source address and client source port and nothing else when using port sharing' ) self.client_address = parts[1] self.client_port = parts[0]
def _setTarget(self, value): if (value is None): self.target_address = '0.0.0.0' self.target_port = (-1) return parts = value.split(' ') if (len(parts) < 2): raise OpsCommandException( 'You must specify at least a target address and target port') self.target_address = parts[0] self.target_port = parts[1] if (len(parts) >= 3): self.source_address = parts[2] if (len(parts) == 4): self.source_port = parts[3]
def __init__(self, plugin='redirect', lplisten=None, implantlisten=None, target=None, **optdict): self._listenport = (-1) self._bindAddr = '0.0.0.0' self._direction = None self._clientPort = (-1) self._clientAddr = '0.0.0.0' self._targetAddr = '0.0.0.0' self._targetPort = (-1) self._sourceAddr = '0.0.0.0' self._sourcePort = (-1) self._limitAddr = '0.0.0.0' self._limitMask = '0.0.0.0' self.optdict = optdict if ('protocol' in optdict): self.protocol = optdict['protocol'] del optdict['protocol'] elif ('tcp' in optdict): self.protocol = 'tcp' elif ('udp' in optdict): self.protocol = 'udp' if ((lplisten is not None) and (implantlisten is not None)): raise OpsCommandException( 'You can only set one of lplisten and implantlisten') elif (lplisten is not None): if ((type(lplisten) == bool) and lplisten): self.direction = 'lplisten' else: self.lplisten = lplisten elif (implantlisten is not None): if ((type(implantlisten) == bool) and implantlisten): self.direction = 'implantlisten' else: self.implantlisten = implantlisten self.target = target delmark = [] for key in optdict: if ((not (key in VALID_OPTIONS)) or (key in ['lplisten', 'implantlisten', 'target'])): delmark.append(key) for deler in delmark: del optdict[deler] ops.cmd.DszCommand.__init__(self, plugin=plugin, **optdict)
def _setLimitMask(self, value): value = value.strip() if util.ip.validate(value): self._limitMask = value else: raise OpsCommandException(('Invalid limit mask %s' % value))
def _setDirection(self, val): if (not (val in [IMPLANTLISTEN, LPLISTEN])): raise OpsCommandException( 'redirect command: direction must be one of lplisten or implantlisten' ) self._direction = val
def _setSourceAddr(self, value): value = value.strip() if util.ip.validate(value): self._sourceAddr = value else: raise OpsCommandException(('Invalid source IP address %s' % value))
def _setTargetAddr(self, value): value = value.strip() if util.ip.validate(value): self._targetAddr = value else: raise OpsCommandException('Invalid target IP address')
def _setListenPort(self, val): val = int(val) if ((val < 0) or (val > 65535)): raise OpsCommandException( 'Listen port must be an integer between 0-65535') self._listenport = val