def connectionMade(self): try: client = self.transport.getPeer().host # client ip log.msg("Incoming connection: %s" % client) fd = self.transport.fileno() flags = fcntl(fd, F_GETFL) # Get current fd flags fcntl(fd, F_SETFL, flags | os.O_NONBLOCK) ready, _, _ = select.select((fd, ), (), (), .5) if fd in ready: # Get some data. req = os.read(fd, 4096) if "Mozilla/5.0" in req: # Probably it is Nesca, fire! self.transport.write(b'%s\r\n' % (self.ourVersionString + PAYLOAD, )) log.msg("Nesca scan detected, attacking: %s" % client) else: # Regular ssh connection or another shit, drop it log.msg("Dropping connection with host: %s" % client) self.transport.loseConnection() except Exception as e: log.msg("Exception in SSHServerTransport: %s" % str(e)) # Passing connection to normal transport. SSHServerTransport.connectionMade(self)
def dataReceived(self, data): # before calling the super method, we collect destination address if self.dest_server_addr is None: # accept the destination server address parts = data.split(' ') self.dest_server_addr = (parts[0], parts[1]) # remove the address from the data data = data[len(parts[0]) + 1 + len(parts[1]) + 1:] # only now, that we have the address, we connect the other side self.connect_b() # check if to keep working, if there's more data if len(data) == 0: return SSHServerTransport.dataReceived(self, data)
def dataReceived(self, data): # before calling the super method, we collect destination address if self.dest_server_addr is None: # accept the destination server address parts = data.split(' ') self.dest_server_addr = (parts[0], parts[1]) # remove the address from the data data = data[len(parts[0]) + 1 + len(parts[1]) + 1:] # only now, that we have the address, we connect the other side self.connect_b() # check if to keep working, if there's more data if len(data) == 0: return SSHServerTransport.dataReceived(self, data)
def connectSSHTransport(service, hostAddress=None, peerAddress=None): """ Connect a SSHTransport which is already connected to a remote peer to the channel under test. @param service: Service used over the connected transport. @type service: L{SSHService} @param hostAddress: Local address of the connected transport. @type hostAddress: L{interfaces.IAddress} @param peerAddress: Remote address of the connected transport. @type peerAddress: L{interfaces.IAddress} """ transport = SSHServerTransport() transport.makeConnection(StringTransport( hostAddress=hostAddress, peerAddress=peerAddress)) transport.setService(service)
def connectSSHTransport(service, hostAddress=None, peerAddress=None): """ Connect a SSHTransport which is already connected to a remote peer to the channel under test. @param service: Service used over the connected transport. @type service: L{SSHService} @param hostAddress: Local address of the connected transport. @type hostAddress: L{interfaces.IAddress} @param peerAddress: Remote address of the connected transport. @type peerAddress: L{interfaces.IAddress} """ transport = SSHServerTransport() transport.makeConnection( StringTransport(hostAddress=hostAddress, peerAddress=peerAddress)) transport.setService(service)
def connectionMade(self): SSHServerTransport.connectionMade(self) self.transport.setTcpKeepAlive(True)
def protocol(self): return SSHServerTransport()
def connectionMade(self): # upon receiving a connection connect on towards the HTTP side self.dest_server_addr = None SSHServerTransport.connectionMade(self)
def connectionMade(self): # upon receiving a connection connect on towards the HTTP side self.dest_server_addr = None SSHServerTransport.connectionMade(self)
def connectionMade(self): SSHServerTransport.connectionMade(self) self.transport.setTcpKeepAlive(True)
def connectionLost(self, reason): log.msg(metric='num_clients', count=-1) return SSHServerTransport.connectionLost(self, reason)
def connectionMade(self): log.msg(metric='num_clients') return SSHServerTransport.connectionMade(self)