예제 #1
0
    def _begin_session(self, stdin, stdout, stderr):
        """Begin processing a new session"""

        # pylint: disable=no-self-use

        action = stdin.channel.get_command()
        if not action:
            action = 'echo'

        if action == 'echo':
            yield from echo(stdin, stdout)
        elif action == 'echo_stderr':
            yield from echo(stdin, stdout, stderr)
        elif action == 'close':
            yield from stdin.read(1)
            stdout.write('\n')
        elif action == 'disconnect':
            stdout.write((yield from stdin.read(1)))

            raise asyncssh.DisconnectError(asyncssh.DISC_CONNECTION_LOST,
                                           'Connection lost')
        else:
            stdin.channel.exit(255)

        stdin.channel.close()
        yield from stdin.channel.wait_closed()
예제 #2
0
    async def _begin_session(self, stdin, stdout, stderr):
        """Begin processing a new session"""

        # pylint: disable=no-self-use

        action = stdin.channel.get_command()
        if not action:
            action = 'echo'

        if action == 'echo':
            await echo(stdin, stdout)
        elif action == 'echo_stderr':
            await echo(stdin, stdout, stderr)
        elif action == 'close':
            await stdin.read(1)
            stdout.write('\n')
        elif action == 'disconnect':
            stdout.write((await stdin.read(1)))
            raise asyncssh.ConnectionLost('Connection lost')
        elif action == 'custom_disconnect':
            await stdin.read(1)
            raise asyncssh.DisconnectError(99, 'Disconnect')
        else:
            stdin.channel.exit(255)

        stdin.channel.close()
        await stdin.channel.wait_closed()
예제 #3
0
파일: sshnope.py 프로젝트: wereii/sshnope
def bail(count=True, custom_raise_f=None):
    if count:
        global ACTIVE_CONS
        ACTIVE_CONS -= 1
        logging.info(f'CONN CLOSED, TOTAL {ACTIVE_CONS}')

    if not custom_raise_f:
        raise asyncssh.DisconnectError(RAISE_WITH, RAISE_MSG)

    custom_raise_f()
예제 #4
0
    def begin_auth(self, username):
        """The client has started authentication with the given username."""
        self.username = username
        try:
            self.authorized_keys = asyncssh.read_authorized_keys(KEYS_FILE)
        except Exception as e:
            # No point in continuing without authorized keys
            logging.error("Failed to read key file: %s", e)
            raise asyncssh.DisconnectError(
                asyncssh.DISC_NO_MORE_AUTH_METHODS_AVAILABLE,
                "Invalid server configuration", "en")

        # Auth required
        return True
예제 #5
0
파일: server.py 프로젝트: oofnikj/nuttssh
    def begin_auth(self, username):
        """The client has started authentication with the given username."""
        self.username = username
        try:
            self.authorized_keys = asyncssh.read_authorized_keys(
                config.AUTHORIZED_KEYS_FILE)
        except FileNotFoundError:
            logging.info("Generating authorized keys file")
            with open(config.AUTHORIZED_KEYS_FILE, 'w'):
                pass
            return True
        except ValueError:
            logging.info("Authorized keys file is empty")
            return True
        except Exception as e:
            # No point in continuing without authorized keys
            logging.error("Failed to read key file: %s", e)
            raise asyncssh.DisconnectError(
                asyncssh.DISC_NO_MORE_AUTH_METHODS_AVAILABLE,
                "Invalid server configuration", "en")

        # Auth required
        return True
 def validate_password(self, username, password):
     print('Login attempt from %s with username %s and password %s' %
           (self._conn.get_extra_info('peername')[0], username, password))
     # Sleep, then disconnect
     time.sleep(random.randint(0, 5))
     raise asyncssh.DisconnectError(10, "Connection lost")
예제 #7
0
 def validate_password(self, username, password):
     print(f'Login attempt from {self._conn.get_extra_info("peername")[0]} with username {username} and password {password}')
     time.sleep(random.randint(0,5))
     raise asyncssh.DisconnectError(10,"Connection lost")