Skip to content

Client direct-tcpip request to Paramiko server results in message authentication code incorrect #630

Open

Description

@sngardner

I have a very simple server implemented on top of ServerInterface.

class SSHServer(paramiko.ServerInterface):
    def __init__(self):
        self.event = Event()

    def check_auth_none(self, username):
        return paramiko.AUTH_SUCCESSFUL

    def check_channel_exec_request(self, channel, command):
        if command.startswith('custom_shell'):
            t = channel.get_transport()
            p = Process(target=custom_shell, args=(channel, 1))
            if keep_tuns.get(str(t)):
                keep_tuns[str(t)] += [p]
            else:
                keep_tuns[str(t)] = [p]
            return True
        else:
            return False

    def check_channel_request(self, kind, chanid):
        return paramiko.OPEN_SUCCEEDED

    def check_channel_direct_tcpip_request(self, chanid, origin, destination):
        return paramiko.OPEN_SUCCEEDED
    def handle(self):
        print "Handling new request on socket %s" % self.request

        t = paramiko.Transport(self.request, gss_kex=False)
        t.add_server_key(host_key)
        server = SSHServer()

        try:
            t.start_server(server=server)
        except Exception as e:
            print e

        channel = t.accept(1)
        if channel:
            print "got: %s" % channel.get_id()
            for p in keep_tuns.get(str(t), []):
                if not p.pid:
                    p.start()

        next_channel = t.accept()
        print "Got another channel! %s" % next_channel
        next_channel.send("Hey!")
        for p in keep_tuns.get(str(t), []):
            p.join()

The custom shell works fine, and after I added the check_channel_direct_tcpip_request implementation my Server will create a new channel once a client requests a new 'direct-tcpip' request via a local-forward.

However, the client immediately disconnects because (I am assuming) of an unexpected response from the server to it's 'direct-tcpip' request.

sgardner@buildenv paramiko-test% ssh -p 2200 -L8180:localhost:80 sgardner@localhost custom_shell
...
Bad packet length 4269956071.
ssh_dispatch_run_fatal: Connection to 127.0.0.1: message authentication code incorrect

Am I missing a method that I need to implement for this, or is there possibly a bug in Transport. _parse_channel_open?

Activity

  1. bitprophet commented on Dec 6, 2015

    @bitprophet
    Member

    Could be a bug, MAC related stuff got an update in 1.16 (if that's what you're on?), though it was mostly just adding ciphers/algorithms and not changing the behavior involved. Those changes may have impacted the SSHServer side, which gets less testing love than the more widely-used Client.

    I will try to recreate when I have time but in the meantime, please try the usual troubleshooting stuff like swapping out Paramiko versions to determine if the issue begins at a given version number, that will help narrow it down. Thanks!

    EDIT: also, for the "maybe not a bug but an incomplete implementation" option, maybe compare your code to the test server used by Fabric (https://github.com/fabric/fabric/blob/master/tests/server.py) - it works well enough to test Fabric's use of SSHClient.

  2. added this to the 1.16.1 milestone on Dec 6, 2015
  3. bitprophet commented on Dec 6, 2015

    @bitprophet
    Member

    Also assigning to 1.16.1 in case this is a regression caused in 1.16.0.

  4. sngardner commented on Dec 6, 2015

    @sngardner
    Author

    Cool, I'll check out Fabric's implementation and if I haven't missed anything, earlier versions of Paramiko.

  5. sngardner commented on Dec 7, 2015

    @sngardner
    Author

    I am using 1.15.0 - has the same behavior as 1.16.0. I apparently need to update my implementation to work with earlier versions, however.

  6. modified the milestones: , 1.16.1 on Apr 24, 2016
  7. modified the milestones: 1.16.2 / 1.17.1 / 2.0.1, on Jun 21, 2016
  8. modified the milestones: 1.17.3 et al, on Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions