Beispiel #1
0
 def demux(self, source, sourcePort, destination, destinationPort, data):
     logger.debug("{} received {} bytes of data from {}:{} for {}:{}".format(self, len(data), source, sourcePort, destination, destinationPort))
     for dumper in self._dumps:
         dumpPacket = WirePacket(source=source, sourcePort=sourcePort,
                                 destination=destination, destinationPort=destinationPort,
                                 data=data)
         dumper.transport.write(dumpPacket.__serialize__())
             
     remotePortKey = PortKey(source, sourcePort, destination, destinationPort)
     
     # this portkey is backwards. The source is from the remote machine
     # but our ports have the remote machine being the destination. 
     # So, invert:
     
     localPortKey = remotePortKey.inverseKey()
     
     # Check if the full port key is already in connections. If so, we're all done
     if localPortKey in self._connections:
         self._connections[localPortKey].write(data)
         return
     
     # If there's no port key in connections, check for listening port.
     listeningPort = localPortKey.sourcePort
     if listeningPort in self._ports and self._ports[listeningPort].isListener():
         # We have a new connection. Spawn.
         # use a controlled port so that if the listening port is closed,
         # all of the spawned ports are closed.
         self._connections[localPortKey] = ConnectionData(localPortKey, self._ports[listeningPort])
         self._connections[localPortKey].write(data)
         self._ports[listeningPort].spawnConnection(localPortKey)
         
     else:
         pass # drop? Fail silently?
    def demux(self, source, sourcePort, destination, destinationPort, data):
        remotePortKey = PortKey(source, sourcePort, destination,
                                destinationPort)

        # this portkey is backwards. The source is from the remote machine
        # but our ports have the remote machine being the destination.
        # So, invert:

        localPortKey = remotePortKey.inverseKey()

        # Check if the full port key is already in connections. If so, we're all done
        if localPortKey in self._connections:
            self._connections[localPortKey].write(data)
            return

        # If there's no port key in connections, check for listening port.
        listeningPort = localPortKey.sourcePort
        if listeningPort in self._ports and self._ports[
                listeningPort].isListener():
            # We have a new connection. Spawn.
            # use a controlled port so that if the listening port is closed,
            # all of the spawned ports are closed.
            self._connections[localPortKey] = ConnectionData(
                localPortKey, self._ports[listeningPort])
            self._connections[localPortKey].write(data)
            self._ports[listeningPort].spawnConnection(localPortKey)

        else:
            pass  # drop? Fail silently?
Beispiel #3
0
 def data_received(self, data):
     self._deserializer.update(data)
     for controlPacket in self._deserializer.nextPackets():
         if isinstance(controlPacket, VNICSocketOpenPacket):
             logger.info("{} received socket open operation.".format(self._vnic))
             self.socketOpenReceived(controlPacket)
         elif isinstance(controlPacket, VNICSocketClosePacket):
             logger.info("{} received socket close {} operation".format(self._vnic, controlPacket.ConnectionId))
             self.controlLost(controlPacket.ConnectionId)
         elif isinstance(controlPacket, WirePacket):
             logger.debug("{} received raw wire for dump mode connection.".format(self._vnic))
             outboundKey = PortKey(controlPacket.source, controlPacket.sourcePort, 
                                     controlPacket.destination, controlPacket.destinationPort)
             self._vnic.write(outboundKey, controlPacket.data)
         elif isinstance(controlPacket, VNICPromiscuousLevelPacket):
             logger.info("{} received promiscuous control packet.".format(self._vnic))
             try:
                 logger.info("{} setting prom. mode to {}".format(self._vnic, controlPacket.set))
                 if controlPacket.set != controlPacket.UNSET:
                     self._vnic.setPromiscuousLevel(controlPacket.set)
                 controlPacket.set = controlPacket.UNSET
                 controlPacket.get = self._vnic.promiscuousLevel()
                 logger.info("{} returning level {}".format(self, controlPacket.get))
                 self.transport.write(controlPacket.__serialize__())
             except Exception as error:
                 logger.error("{} got error {}".format(self._vnic, error))
         #elif isinstance(controlPacket, VNICSocketStatusPacket):
         #    self.socketStatusReceived(controlPacket)
         #elif isinstance(controlPacket, VNICSocketClosePacket):
         #    self.socketCloseReceived(controlPacket)
         else:
             logger.info("{} received unknown packet {}".format(self._vnic, controlPacket))
Beispiel #4
0
 def createOutboundSocket(self, control, destination, destinationPort):
     port = next(self._freePorts)
     
     self._ports[port] = control
     
     portKey = PortKey(str(self._address), port, destination, destinationPort)
     self._connections[portKey] = ConnectionData(portKey, control)
     control.spawnConnection(portKey)
     
     return port