예제 #1
0
    def openShell(self, transport):
        """
        Write 60 lines of data to the transport, then exit.
        """
        proto = protocol.Protocol()
        proto.makeConnection(transport)
        transport.makeConnection(wrapProtocol(proto))

        # Send enough bytes to the connection so that a rekey is triggered in
        # the client.
        def write(counter):
            i = counter()
            if i == 60:
                call.stop()
                transport.session.conn.sendRequest(
                    transport.session, 'exit-status', '\x00\x00\x00\x00')
                transport.loseConnection()
            else:
                transport.write("line #%02d\n" % (i,))

        # The timing for this loop is an educated guess (and/or the result of
        # experimentation) to exercise the case where a packet is generated
        # mid-rekey.  Since the other side of the connection is (so far) the
        # OpenSSH command line client, there's no easy way to determine when the
        # rekey has been initiated.  If there were, then generating a packet
        # immediately at that time would be a better way to test the
        # functionality being tested here.
        call = LoopingCall(write, count().next)
        call.start(0.01)
예제 #2
0
 def request_shell(self, data):
     protocol  = EchoProtocol()
     transport = SSHSessionProcessProtocol(self)
     protocol.makeConnection(transport)
     transport.makeConnection(wrapProtocol(protocol))
     self.client = transport
     return True
예제 #3
0
파일: session.py 프로젝트: ZionOps/cowrie
 def openShell(self, processprotocol):
     """
     """
     self.protocol = insults.LoggingServerProtocol(
         protocol.HoneyPotInteractiveProtocol, self)
     self.protocol.makeConnection(processprotocol)
     processprotocol.makeConnection(session.wrapProtocol(self.protocol))
예제 #4
0
파일: ssh.py 프로젝트: andrew-morris/cowrie
 def execCommand(self, proto, cmd):
     serverProtocol = protocol.LoggingServerProtocol(
         protocol.HoneyPotExecProtocol, self, self.env, cmd)
     self.protocol = serverProtocol
     serverProtocol.makeConnection(proto)
     proto.makeConnection(session.wrapProtocol(serverProtocol))
     self.protocol = serverProtocol
예제 #5
0
    def openShell(self, protocol):

        serverProtocol = insults.ServerProtocol(SSHDemoProtocol, self)

        serverProtocol.makeConnection(protocol)

        protocol.makeConnection(session.wrapProtocol(serverProtocol))
예제 #6
0
파일: ssh.py 프로젝트: M0r13n/ssh_keys
 def openShell(self, transport):
     """
     Use the custom protocol
     """
     protocol = EchoProtocol()
     protocol.makeConnection(transport)
     transport.makeConnection(session.wrapProtocol(protocol))
예제 #7
0
파일: ssh.py 프로젝트: Wonderfall/cowrie
 def execCommand(self, proto, cmd):
     """
     """
     self.protocol = protocol.LoggingServerProtocol(
         protocol.HoneyPotExecProtocol, self, cmd)
     self.protocol.makeConnection(proto)
     proto.makeConnection(session.wrapProtocol(self.protocol))
예제 #8
0
파일: session.py 프로젝트: ZionOps/cowrie
 def execCommand(self, processprotocol, cmd):
     """
     """
     self.protocol = insults.LoggingServerProtocol(
         protocol.HoneyPotExecProtocol, self, cmd)
     self.protocol.makeConnection(processprotocol)
     processprotocol.makeConnection(session.wrapProtocol(self.protocol))
예제 #9
0
    def openShell(self, transport):
        """
        Write 60 lines of data to the transport, then exit.
        """
        proto = protocol.Protocol()
        proto.makeConnection(transport)
        transport.makeConnection(wrapProtocol(proto))

        # Send enough bytes to the connection so that a rekey is triggered in
        # the client.
        def write(counter):
            i = counter()
            if i == 60:
                call.stop()
                transport.session.conn.sendRequest(transport.session,
                                                   'exit-status',
                                                   '\x00\x00\x00\x00')
                transport.loseConnection()
            else:
                transport.write("line #%02d\n" % (i, ))

        # The timing for this loop is an educated guess (and/or the result of
        # experimentation) to exercise the case where a packet is generated
        # mid-rekey.  Since the other side of the connection is (so far) the
        # OpenSSH command line client, there's no easy way to determine when the
        # rekey has been initiated.  If there were, then generating a packet
        # immediately at that time would be a better way to test the
        # functionality being tested here.
        call = LoopingCall(write, count().next)
        call.start(0.01)
예제 #10
0
 def request_shell(self, data):
     protocol = Protocol()
     transport = SSHSessionProcessProtocol(self)
     protocol.makeConnection(transport)
     transport.makeConnection(wrapProtocol(protocol))
     self.client = transport
     return True
예제 #11
0
파일: ssh.py 프로젝트: Wonderfall/cowrie
 def openShell(self, proto):
     """
     """
     self.protocol = protocol.LoggingServerProtocol(
         protocol.HoneyPotInteractiveProtocol, self)
     self.protocol.makeConnection(proto)
     proto.makeConnection(session.wrapProtocol(self.protocol))
예제 #12
0
파일: User.py 프로젝트: TerrorBite/textgame
    def openShell(self, trans):
        """
        Called when a shell is opened by a user logging in via SSH or similar.
        """
        # Obtain a protocol instance. This is our custom Network.SSHServerProtocol.
        # The protocol controls the way that data is sent and received down the connection.
        # In our case, it presents a TTY-based user interface to the user, while all we care
        # about is sending lines to the user and receiving lines from them.
        from Network import SSHServerProtocol
        # Get the protocol instance. The protocol is also our transport.
        #     Note that the Twisted networking model is a stack of protocols,
        #     where lower level protocols transport higher level ones.
        self.transport = proto = SSHServerProtocol(self, *self.savedSize)
        # Connect the protocol and the transport together (I don't really understand why
        # it needs to be connected both ways like this, or what the wrapper does)
        proto.makeConnection(trans)
        trans.makeConnection(session.wrapProtocol(proto))
        #self.send_message("Hi there!")
        # Obtain the Player object from the database
        player_id = self.world.db.get_player_id(self.username, self._charname)
        log.debug("Username: {0}, character: {2}, id: {1}".format(self.username, player_id, self._charname))

        self.player = self.world.get_thing(player_id)
        # Finish login (what does this call do?)
        self.complete_login()
예제 #13
0
파일: ssh.py 프로젝트: dgvncsz0f/pingpong
 def execCommand(self, proto, cmd):
     p = session_wrapper_protocol(self, False)
     p.makeConnection(proto)
     proto.makeConnection(session.wrapProtocol(p))
     p.dataReceived(cmd)
     if (not cmd.endswith("\n")):
         p.dataReceived("\n")
     p.stransport.terminate()
예제 #14
0
파일: MockSSH.py 프로젝트: Nikosl/MockSSH
    def openShell(self, protocol):
        serverProtocol = insults.ServerProtocol(SSHProtocol,
                                                self,
                                                self.prompt,
                                                self.commands)

        serverProtocol.makeConnection(protocol)
        protocol.makeConnection(session.wrapProtocol(serverProtocol))
예제 #15
0
파일: ssh.py 프로젝트: andrew-morris/cowrie
 def openShell(self, proto):
     serverProtocol = protocol.LoggingServerProtocol(
         protocol.HoneyPotInteractiveProtocol, self, self.env)
     self.protocol = serverProtocol
     serverProtocol.makeConnection(proto)
     proto.makeConnection(session.wrapProtocol(serverProtocol))
     #self.protocol = serverProtocol
     self.protocol = proto
 def openShell(self, trans):
     log.msg("Your terminal name is %r.  "
             "Your terminal is %d columns wide and %d rows tall." %
             (self.terminalName, self.windowSize[0], self.windowSize[1]))
     log.msg("ExampleSession: open shell!")
     ep = SSHServerConsoleProtocol(self.terminalName)
     ep.makeConnection(trans)
     trans.makeConnection(session.wrapProtocol(ep))
예제 #17
0
 def request_exec(self, data):
     print 'request_exec', data
     protocol = SCPProtocol()
     transport = SSHSessionProcessProtocol(self)
     protocol.makeConnection(transport)
     transport.makeConnection(wrapProtocol(protocol))
     self.client = transport
     return True
예제 #18
0
 def openShell(self, protocol):
     shell_protocol = insults.ServerProtocol(
         ShellProtocol,
         self,
         self.executables,
     )
     shell_protocol.makeConnection(protocol)
     protocol.makeConnection(session.wrapProtocol(shell_protocol))
예제 #19
0
파일: session.py 프로젝트: emil2k/joltem
    def openShell(self, protocol):
        """ Open a shell and connect it to proto. """

        peer_address = protocol.getPeer().address  # IAddress
        (host, port) = (peer_address.host, peer_address.port)
        log.msg("Open shell from %s:%d." % (host, port))
        serverProtocol = ServerProtocol(GatewayTerminalProtocol, self.avatar)
        serverProtocol.makeConnection(protocol)
        protocol.makeConnection(wrapProtocol(serverProtocol))
예제 #20
0
 def openShell(self, transport):
     """
     Use our protocol as shell session.
     """
     protocol = EchoProtocol()
     # Connect the new protocol to the transport and the transport
     # to the new protocol so they can communicate in both directions.
     protocol.makeConnection(transport)
     transport.makeConnection(session.wrapProtocol(protocol))
예제 #21
0
 def openShell(self, transport):
     """
     Use our protocol as shell session.
     """
     protocol = EchoProtocol()
     # Connect the new protocol to the transport and the transport
     # to the new protocol so they can communicate in both directions.
     protocol.makeConnection(transport)
     transport.makeConnection(session.wrapProtocol(protocol))
예제 #22
0
 def openShell(self, protocol):
     serverProto = ServerProtocol2(
         makeSSHApplicationProtocol, self.reactor, self.user_id)
     serverProto.makeConnection(protocol)
     protocol.makeConnection(wrapProtocol(serverProto))
     self.ssh_protocol = serverProto
     app_protocol = serverProto.terminalProtocol.app_protocol
     app_protocol.term_size = self.term_size
     app_protocol.update_display()
 def openShell(self, trans):
     log.msg(
         "Your terminal name is %r.  "
         "Your terminal is %d columns wide and %d rows tall." % (
             self.terminalName, self.windowSize[0], self.windowSize[1]))
     log.msg("ExampleSession: open shell!")
     ep = SSHServerConsoleProtocol(self.terminalName)
     ep.makeConnection(trans)
     trans.makeConnection(session.wrapProtocol(ep))
예제 #24
0
 def openShell(self, protocol):
     #serverProtocol = insults.ServerProtocol(remoteCLI, self)
     control = self.service.root.getServiceNamed('control').handle_command
     serverProtocol = insults.ServerProtocol(manhole.ColoredManhole, {
         'app': self.service.root,
         'stop': reactor.stop,
         'c': control
     })
     serverProtocol.makeConnection(protocol)
     protocol.makeConnection(session.wrapProtocol(serverProtocol))
예제 #25
0
 def openShell(self, protocol):
     _log.debug("openShell %s", protocol.getHost().address.port)
     # protocol is an SSHSessionProcessProtocol object
     # protocol.getHost().address.port
     # protocol.factory
     # protocol.transport
     # TODO if port is global sshport create CLI
     ts_protocol = TSProtocol(self.avatar)
     ts_protocol.makeConnection(protocol)
     protocol.makeConnection(session.wrapProtocol(ts_protocol))
예제 #26
0
파일: ssh.py 프로젝트: ekohl/vncauthproxy
def attach_protocol_to_channel(protocol, channel):
    # These are from
    # http://as.ynchrono.us/2011/08/twisted-conch-in-60-seconds-protocols.html
    transport = SSHSessionProcessProtocol(channel)
    protocol.makeConnection(transport)
    transport.makeConnection(wrapProtocol(protocol))
    channel.client = transport

    # And this one's from me :3
    channel.dataReceived = protocol.dataReceived
예제 #27
0
def attach_protocol_to_channel(protocol, channel):
    # These are from
    # http://as.ynchrono.us/2011/08/twisted-conch-in-60-seconds-protocols.html
    transport = SSHSessionProcessProtocol(channel)
    protocol.makeConnection(transport)
    transport.makeConnection(wrapProtocol(protocol))
    channel.client = transport

    # And this one's from me :3
    channel.dataReceived = protocol.dataReceived
예제 #28
0
 def openShell(self, protocol):
     serverProto = ServerProtocol2(
         make_terminal_adapter, self.reactor, self.user_id)
     serverProto.makeConnection(protocol)
     protocol.makeConnection(wrapProtocol(serverProto))
     self.ssh_protocol = serverProto
     self.set_term_adapter_term_size()
     app_protocol = serverProto.terminalProtocol.app_protocol
     app_protocol.term_size = self.term_size
     app_protocol.update_display()
예제 #29
0
 def makeProtocol(self):
     env = HoneyPotEnvironment()
     user = HoneyPotAvatar("root", env)
     
     serverProtocol = insults.ServerProtocol(
         HoneyPotInteractiveProtocol, user, env)
     serverProtocol.makeConnection(protocol)
     protocol.makeConnection(session.wrapProtocol(serverProtocol))
     #honeypot = HoneyPotInteractiveProtocol(user, env)
     return serverProtocol
예제 #30
0
 def openShell(self, transport):
     """
     Use our protocol as shell session.
     """
     protocol = CLIProtocol(self.datastore)
     # Connect the new protocol to the transport and the transport
     # to the new protocol so they can communicate in both directions.
     protocol.makeConnection(transport)
     transport.makeConnection(session.wrapProtocol(protocol))
     protocol.transport.write(
         b'Welcome to Digital Sky\r\nType "help" for help.\r\n$ ')
예제 #31
0
    def execCommand(self, protocol, cmd):
        cfg = config()
        if cfg.has_option('honeypot', 'exec_enabled'):
            if ( cfg.get('honeypot', 'exec_enabled') != "true" ):
                print 'exec disabled not executing command: "%s"' % cmd
                raise os.OSError

        print 'Executing command: "%s"' % cmd
        serverProtocol = LoggingServerProtocol(HoneyPotProtocol, self, self.env, cmd)
        serverProtocol.makeConnection(protocol)
        protocol.makeConnection(session.wrapProtocol(serverProtocol))
예제 #32
0
    def connectionMade(self):
        processprotocol = TelnetSessionProcessProtocol(self)

        # If we are dealing with a proper Telnet client: enable server echo
        if self.transport.options:
            self.transport.willChain(SGA)
            self.transport.willChain(ECHO)

        self.protocol = insults.LoggingTelnetServerProtocol(
                cproto.HoneyPotInteractiveTelnetProtocol, self)
        self.protocol.makeConnection(processprotocol)
        processprotocol.makeConnection(session.wrapProtocol(self.protocol))
예제 #33
0
파일: session.py 프로젝트: clom/cowrie-1
    def connectionMade(self):
        processprotocol = TelnetSessionProcessProtocol(self)

        # If we are dealing with a proper Telnet client: enable server echo
        if self.transport.options:
            self.transport.will(SGA)
            self.transport.will(ECHO)

        self.protocol = insults.LoggingTelnetServerProtocol(
            cproto.HoneyPotInteractiveTelnetProtocol, self)
        self.protocol.makeConnection(processprotocol)
        processprotocol.makeConnection(session.wrapProtocol(self.protocol))
예제 #34
0
파일: ssh.py 프로젝트: CZ-NIC/kippo
    def execCommand(self, processprotocol, cmd):
        cfg = config()
        # default is enabled
        if cfg.has_option('honeypot', 'exec_enabled'):
            if ( cfg.get('honeypot', 'exec_enabled') != "true" ):
                print 'exec disabled not executing command: "%s"' % cmd
                raise os.OSError

        print 'Executing command'
        self.protocol = cowrie.core.protocol.LoggingServerProtocol(
            cowrie.core.protocol.HoneyPotExecProtocol, self, cmd)
        self.protocol.makeConnection(processprotocol)
        processprotocol.makeConnection(session.wrapProtocol(self.protocol))
예제 #35
0
    def openShell(self, transport):
        """
        Use our protocol as shell session.
        """
        converter = transport.session.conn.transport.factory
        protocol = SideProtocol()
        # Connect the new protocol to the transport and the transport
        # to the new protocol so they can communicate in both directions.
        protocol.makeConnection(transport)
        transport.makeConnection(session.wrapProtocol(protocol))

        converter.push_a_side(protocol)
        protocol.other_side = converter.get_b_side(protocol)
예제 #36
0
    def openShell(self, transport):
        """
        Use our protocol as shell session.
        """
        converter = transport.session.conn.transport.factory
        protocol = SideProtocol()
        # Connect the new protocol to the transport and the transport
        # to the new protocol so they can communicate in both directions.
        protocol.makeConnection(transport)
        transport.makeConnection(session.wrapProtocol(protocol))

        converter.push_a_side(protocol)
        protocol.other_side = converter.get_b_side(protocol)
예제 #37
0
    def openShell(self, transport):
        """
        wire the protocol to the transport channel
        :param transport:
        """
        serverProtocol = insults.insults.ServerProtocol(
            SSHProtocol)  # neues ServerProtocol mit SSHProtocol als Terminal
        serverProtocol.makeConnection(transport)
        transport.makeConnection(session.wrapProtocol(serverProtocol))

        remote = transport.session.avatar.conn.transport.transport.client
        log.request("SSH", remote[0], remote[1], self.local_ip, self.local_port,
                    "<open shell>", transport.session.avatar.username)
예제 #38
0
파일: ssh.py 프로젝트: netkey/kippo
    def execCommand(self, processprotocol, cmd):
        cfg = config()
        # default is enabled
        if cfg.has_option('honeypot', 'exec_enabled'):
            if (cfg.get('honeypot', 'exec_enabled') != "true"):
                print 'exec disabled not executing command: "%s"' % cmd
                raise os.OSError

        print 'Executing command'
        self.protocol = cowrie.core.protocol.LoggingServerProtocol(
            cowrie.core.protocol.HoneyPotExecProtocol, self, cmd)
        self.protocol.makeConnection(processprotocol)
        processprotocol.makeConnection(session.wrapProtocol(self.protocol))
예제 #39
0
    def openShell(self, transport):
        """
        wire the protocol to the transport channel
        :param transport:
        """
        serverProtocol = insults.insults.ServerProtocol(
            SSHProtocol)  # neues ServerProtocol mit SSHProtocol als Terminal
        serverProtocol.makeConnection(transport)
        transport.makeConnection(session.wrapProtocol(serverProtocol))

        ip = transport.session.avatar.conn.transport.transport.client[0]
        port = transport.session.avatar.conn.transport.transport.server._realPortNumber
        log.request("SSH", ip, port, "Request shell", transport.session.avatar.username.decode())
예제 #40
0
파일: ssh.py 프로젝트: Tubbz-alt/NESi
    def openShell(self, transport):
        protocol = SSHProtocol()
        protocol.makeConnection(transport)
        transport.makeConnection(session.wrapProtocol(protocol))

        command_processor = self.avatar.cli(
            self.avatar.model,
            protocol,
            transport, (),
            template_root=self.avatar.template_root,
            daemon=True)
        command_processor.skipLogin = True
        thread = threading.Thread(target=command_processor.loop, args=())
        thread.start()
예제 #41
0
    def request_subsystem(self, data):
        subsystem, junk = common.getNS(data)
        if subsystem == 'amp':
            #import pdb; pdb.set_trace()
            protocol = EchoDateProtocol(self.avatar)
            transport = SSHSessionProcessProtocol(self)
            protocol.makeConnection(transport)
            transport.makeConnection(wrapProtocol(protocol))
            self.client = transport
            return True  # subsystem request OK

        else:
            log.msg('Unknown subsystem requested: %r' % (subsystem, ))
            return False  # Fail subsystem request.
예제 #42
0
파일: User.py 프로젝트: TerrorBite/textgame
    def openShell(self, trans):
        """
        Called when a shell is opened by a user logging in via SSH or similar.
        """
        # Create an SSHProtocol object and connect it
        from Network import SSHServerProtocol

        # self.transport = t = insults.ServerProtocol(SSHProtocol, self, *self.savedSize)
        self.transport = t = SSHServerProtocol(self, *self.savedSize)
        t.makeConnection(trans)
        trans.makeConnection(session.wrapProtocol(t))
        # self.send_message("Hi there!")
        self.player = self.world.get_thing(self.world.db.get_player_id(self.username))
        self.complete_login()
예제 #43
0
    def request_subsystem(self, data):
        subsystem, junk = common.getNS(data)
        if subsystem == 'amp':
            #import pdb; pdb.set_trace()
            protocol = EchoDateProtocol(self.avatar)
            transport = SSHSessionProcessProtocol(self)
            protocol.makeConnection(transport)
            transport.makeConnection(wrapProtocol(protocol))
            self.client = transport
            return True # subsystem request OK

        else:
            log.msg('Unknown subsystem requested: %r' % (subsystem,))
            return False # Fail subsystem request.
예제 #44
0
    def execCommand(self, protocol, cmd):
        cfg = config()
        if not cfg.has_option('honeypot', 'exec_enabled') or \
                cfg.get('honeypot', 'exec_enabled').lower() not in \
                    ('yes', 'true', 'on'):
            print 'Exec disabled. Not executing command: "%s"' % cmd
            raise core.exceptions.NotEnabledException, \
                'exec_enabled not enabled in configuration file!'
            return

        print 'exec command: "%s"' % cmd
        serverProtocol = kippo.core.protocol.LoggingServerProtocol(
            kippo.core.protocol.HoneyPotExecProtocol, self, self.env, cmd)
        serverProtocol.makeConnection(protocol)
        protocol.makeConnection(session.wrapProtocol(serverProtocol))
예제 #45
0
파일: ssh.py 프로젝트: DrDomAdmin/kippo
    def execCommand(self, protocol, cmd):
        cfg = config()
        if not cfg.has_option('honeypot', 'exec_enabled') or \
                cfg.get('honeypot', 'exec_enabled').lower() not in \
                    ('yes', 'true', 'on'):
            print 'Exec disabled. Not executing command: "%s"' % cmd
            raise core.exceptions.NotEnabledException, \
                'exec_enabled not enabled in configuration file!'
            return

        print 'exec command: "%s"' % cmd
        serverProtocol = kippo.core.protocol.LoggingServerProtocol(
            kippo.core.protocol.HoneyPotExecProtocol, self, self.env, cmd)
        serverProtocol.makeConnection(protocol)
        protocol.makeConnection(session.wrapProtocol(serverProtocol))
예제 #46
0
파일: ssh.py 프로젝트: blackstagio/kippo
    def execCommand(self, proto, cmd):
        cfg = config()
        if not cfg.has_option('honeypot', 'exec_enabled') or \
                cfg.get('honeypot', 'exec_enabled').lower() not in \
                    ('yes', 'true', 'on'):
            log.msg( 'Exec disabled. Not executing command: "%s"' % cmd )
            raise exceptions.NotEnabledException(
                'exec_enabled not enabled in configuration file!')
            return

        serverProtocol = protocol.LoggingServerProtocol(
            protocol.HoneyPotExecProtocol, self, self.env, cmd)
        self.protocol = serverProtocol
        serverProtocol.makeConnection(proto)
        proto.makeConnection(session.wrapProtocol(serverProtocol))
        self.protocol = serverProtocol
예제 #47
0
    def execCommand(self, proto, cmd):
        cfg = config()
        if not cfg.has_option('honeypot', 'exec_enabled') or \
                cfg.get('honeypot', 'exec_enabled').lower() not in \
                    ('yes', 'true', 'on'):
            log.msg('Exec disabled. Not executing command: "%s"' % cmd)
            raise exceptions.NotEnabledException(
                'exec_enabled not enabled in configuration file!')
            return

        serverProtocol = protocol.LoggingServerProtocol(
            protocol.HoneyPotExecProtocol, self, self.env, cmd)
        self.protocol = serverProtocol
        serverProtocol.makeConnection(proto)
        proto.makeConnection(session.wrapProtocol(serverProtocol))
        self.protocol = serverProtocol
예제 #48
0
    def openShell(self, trans):
        """ called back on a successful connection """

        # Instantiate the protocol.
        self.ep = self.WRAPPROTOCOL()
        self.avatar.con = self.ep
        self.ep.user = self.avatar
        self.ep.cb = self.cb

        # the peer information
        self.ep.peer = self.avatar.conn.transport.transport.getPeer()
        # . method from the actual transport.
        #self.ep.loseRealConnection = self.avatar.conn.transport.transport.loseConnection
        # Twisted black magic
        self.ep.makeConnection(trans)
        trans.makeConnection(session.wrapProtocol(self.ep))
예제 #49
0
    def openShell(self, trans):
        """ called back on a successful connection """
        
        # Instantiate the protocol.
        self.ep = self.WRAPPROTOCOL()
        self.avatar.con = self.ep
        self.ep.user = self.avatar
        self.ep.cb = self.cb

        # the peer information
        self.ep.peer = self.avatar.conn.transport.transport.getPeer()
        # . method from the actual transport.
        #self.ep.loseRealConnection = self.avatar.conn.transport.transport.loseConnection
        # Twisted black magic
        self.ep.makeConnection(trans)
        trans.makeConnection(session.wrapProtocol(self.ep))
 def test_wrapProtocol(self):
     """
     L{wrapProtocol}, when passed a L{Protocol} should return something that
     has write(), writeSequence(), loseConnection() methods which call the
     Protocol's dataReceived() and connectionLost() methods, respectively.
     """
     protocol = MockProtocol()
     protocol.transport = StubTransport()
     protocol.connectionMade()
     wrapped = session.wrapProtocol(protocol)
     wrapped.dataReceived(b"dataReceived")
     self.assertEqual(protocol.transport.buf, b"dataReceived")
     wrapped.write(b"data")
     wrapped.writeSequence([b"1", b"2"])
     wrapped.loseConnection()
     self.assertEqual(protocol.data, b"data12")
     protocol.reason.trap(error.ConnectionDone)
예제 #51
0
    def connectionMade(self):
        processprotocol = TelnetSessionProcessProtocol(self)

        # If we are dealing with a proper Telnet client: enable server echo
        if self.transport.options:
            self.transport.willChain(SGA)
            self.transport.willChain(ECHO)

        self.protocol = insults.LoggingTelnetServerProtocol(
            cproto.HoneyPotInteractiveTelnetProtocol, self)

        # somewhere in Twisted this exception gets lost. Log explicitly here
        try:
            self.protocol.makeConnection(processprotocol)
            processprotocol.makeConnection(session.wrapProtocol(self.protocol))
        except Exception:
            log.msg(traceback.format_exc())
예제 #52
0
    def connectionMade(self):
        processprotocol = TelnetSessionProcessProtocol(self)

        # If we are dealing with a proper Telnet client: enable server echo
        if self.transport.options:
            self.transport.willChain(SGA)
            self.transport.willChain(ECHO)

        self.protocol = insults.LoggingTelnetServerProtocol(
            cproto.HoneyPotInteractiveTelnetProtocol, self)

        # somewhere in Twisted this exception gets lost. Log explicitly here
        try:
            self.protocol.makeConnection(processprotocol)
            processprotocol.makeConnection(session.wrapProtocol(self.protocol))
        except Exception as e:
            log.msg(traceback.format_exc())
예제 #53
0
 def test_wrapProtocol(self):
     """
     L{wrapProtocol}, when passed a L{Protocol} should return something that
     has write(), writeSequence(), loseConnection() methods which call the
     Protocol's dataReceived() and connectionLost() methods, respectively.
     """
     protocol = MockProtocol()
     protocol.transport = StubTransport()
     protocol.connectionMade()
     wrapped = session.wrapProtocol(protocol)
     wrapped.dataReceived('dataReceived')
     self.assertEquals(protocol.transport.buf, 'dataReceived')
     wrapped.write('data')
     wrapped.writeSequence(['1', '2'])
     wrapped.loseConnection()
     self.assertEquals(protocol.data, 'data12')
     protocol.reason.trap(error.ConnectionDone)
예제 #54
0
파일: objshssh.py 프로젝트: iapyeh/objsh
    def execCommand(self, proto, cmd):
        """
        Support command execution sessions.

        Arguments:
            proto: is an instance of SSHSessionProcessProtocol
        """
        self.avatar.addr = proto.getPeer().address
        self.remote_ip = self.avatar.addr.host
        self.protocol = self.protocol_class(self.avatar)

        # Connect the new protocol to the transport and the transport
        # to the new protocol so they can communicate in both directions.
        self.protocol.makeConnection(proto)
        proto.makeConnection(session.wrapProtocol(self.protocol))
        # execute command might also requires get_pty
        #assert not self.is_pty

        # in case, there is no new line at the file end
        end = '' if cmd[-1] in ('\r', '\n') else '\n'
        self.protocol.rawDataReceived(cmd + end + 'EOF\n')
예제 #55
0
파일: objshssh.py 프로젝트: iapyeh/objsh
    def openShell(self, proto):
        """
        Use our protocol as shell session.
        
        Arguments:
            proto: is a twisted.conch.ssh.session.SSHSessionProcessProtocol object

        * SSHAutoTester in autotest.py goes this way.
        * self.protocol is a objshshell.ObjshProtocol object
        """
        if self.is_pty:
            log.msg('shell opened by pty')
        else:
            log.msg('shell not opened by pty')
        self.avatar.addr = proto.getPeer().address
        self.remote_ip = self.avatar.addr.host
        self.protocol = self.protocol_class(self.avatar)

        # Connect the new protocol to the transport and the transport
        # to the new protocol so they can communicate in both directions.
        self.protocol.makeConnection(proto)
        proto.makeConnection(session.wrapProtocol(self.protocol))
예제 #56
0
파일: ssh.py 프로젝트: barsch/seishub.core
 def openShell(self, protocol):
     serverProtocol = insults.ServerProtocol(SSHServiceProtocol,
                                             self.avatar)
     serverProtocol.makeConnection(protocol)
     protocol.makeConnection(session.wrapProtocol(serverProtocol))
예제 #57
0
 def openShell(self, transport):
     protocol = EchoProtocol()
     protocol.makeConnection(transport)
     transport.makeConnection(session.wrapProtocol(protocol))
예제 #58
0
파일: ssh.py 프로젝트: netkey/kippo
 def openShell(self, processprotocol):
     log.msg("openshell: %s" % (repr(processprotocol), ))
     self.protocol = cowrie.core.protocol.LoggingServerProtocol(
         cowrie.core.protocol.HoneyPotInteractiveProtocol, self)
     self.protocol.makeConnection(processprotocol)
     processprotocol.makeConnection(session.wrapProtocol(self.protocol))