[Twisted-Python] SSH client bad packet length

Anders Bruun Olsen anders at bruun-olsen.net
Mon Oct 6 15:23:13 MDT 2003


On Mon, Oct 06, 2003 at 05:13:40PM -0400, Paul Swartz wrote:
> > 2003/10/06 22:31 CEST [ClientTransport,client] Disconnecting with error, code 2
> >         reason: bad packet length 415956278
> What that error means is that there was an error with one of the
> packets.  Whether it's an error w/ your code or not I can't tell w/out
> seeing the code.

#!/usr/bin/env python

from twisted.conch import error
from twisted.conch.ssh import transport
from twisted.internet import defer

class ClientTransport(transport.SSHClientTransport):

        def verifyHostKey(self, pubKey, fingerprint):
                return defer.succeed(1)

        def connectionSecure(self):
                self.requestService(ClientUserAuth('user',ClientConnection()))


from twisted.conch.ssh import keys, userauth

publicKey = 'ssh-dss
AAAAB3NzaC1kc3MAAAEBAPUkX9Opu89vLxyMxkssKeGUmfabGRrmiuLplkN34HcScnjf/7H/QDshdcRx4+f8GhJo4yH8DAE0/zVAWZK9aMI5LpjSpr9gR2Vyq5df7vnldJljxlGMnT5W79bloP69Fo3Hjf44dTNATxfFMmwHCwMxj1oDkEn78ANyDa5xjoszT54ucm0bPExiPDQ6sz84FEDdKIrrwi8w+rEN5ReBrUPAq9zXHZjt3AOqiaDXbZsRzh6x+XhX7Wg3EkOUfTEhZ1u6baBH0DLg7jiSnURPUwyYoW5qEB0CypjAhl+EaaASvmGcXAl1JSifp0CQ8MedvCb46dGn10McrDVJvFhRxo0AAAAVAOhkyFrn2qzxUk9XmJVc75DKd9Q/AAABACeR0+IjK7SOmBeNzqnLrp5FY1MhO8KwfLpZaHbQPwo6tPR3DBRCBH3oyhxFGpLxWvHsP2LoxmJbqTaTq4T+svuIjICXtlDVOSLd0o6U4A3aDXsoN2gv04RKEkmxrocnY6dYZisHeavP5S10Ediung23ZxOzsBdPEtRDthxOya4QXlqtjIEqAk702qmZGEYCgSRPOQ5Pwm0S7kD8yOn0XQUEY/WjlbZPiM9QUXlroltLnnSeECvFLePsyEVTrvdr8Bne9NxcMW+YZBroKtLOzgH6PLKn4lB8IGOlg+U1qOlkzjDaAMeNL2Hs8vwYVXIcmm3j5JQ5ZYtx2aRHkIUTY3kAAAEBAJxRVoGskwVDnzukLKRxjuFBSpyNr/Iwp0tPvQIyASPsLh5alHRe/2AMTojKdVJkmCjPCEdL4rlzugLkcv6OPzevH5tCtvyU1X2531h51MtIs8jFF7dGPosdt0+hD1O3fA0bXBO4REw0GcMuo/wV9Flx/FZYIkgvqVGalfH5evU0Hj8wQlZaMrW+HcMUrdLBezdMob4qFTK0TQQ8R0KWwYT++ULOGahzY3HwR8GVYYMMGUtRZY96vYkMpLJkSpHobBh2biVb2DuccPqIzCkJWaVdfl8zj5pi07mojvhLXzfWTkZv+nCzZ6DPoW+dMXqg5OE6e8l00gDefFAi8cj5aKc=
drzero at ernest.local'

privateKey = """-----BEGIN DSA PRIVATE KEY-----
Key was censored for privacy reasons
-----END DSA PRIVATE KEY-----"""

class ClientUserAuth(userauth.SSHUserAuthClient):

        def getPassword(self, prompt = None):
                return 
                # this says we won't do password authentication

        def getPublicKey(self):
                return keys.getPublicKeyString(data = publicKey)

        def getPrivateKey(self):
                return defer.succeed(keys.getPrivateKeyObject(data = privateKey))


from twisted.conch.ssh import connection

class ClientConnection(connection.SSHConnection):

        def serviceStarted(self):
                self.openChannel(CatChannel(conn = self))


from twisted.conch.ssh import channel, common

class CatChannel(channel.SSHChannel):

        name = 'session'

        def channelOpen(self, data):
                d = self.conn.sendRequest(self, 'exec', common.NS('cat'), wantReply = 1)
                d.addCallback(self._cbSendRequest)
                self.catData = ''

        def _cbSendRequest(self, ignored):
                self.write('This data will be echoed back to us by "cat."\r\n')
                self.conn.sendEOF(self)
                self.loseConnection()

        def dataReceived(self, data):
                self.catData += data

        def closed(self):
                print 'We got this from "cat":', self.catData
                reactor.stop()


from twisted.internet import protocol, reactor
from twisted.python import log
import sys

def main():
        log.startLogging(sys.stdout, setStdout=0)
        factory = protocol.ClientFactory()
        factory.protocol = ClientTransport
        reactor.connectTCP('eduardo.local', 22, factory)
        reactor.run()

if __name__ == "__main__":
        main()


-- 
Anders
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V
PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y?
------END GEEK CODE BLOCK------
PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41




More information about the Twisted-Python mailing list