[Twisted-Python] SSH client bad packet length
Hi, I am trying to learn a bit of Twisted in order to make an app that will use SSH for running commands on remote hosts. I have followed the SSH howto on the homepage where I have changed it to accept any fingerprint and have put my own private and public keys in instead of the ones from the example and have it connecting to a server of mine that accepts passwordless key-auth. Lastly I have enabled logging to stdout (it might be an idea to add to the howto which module to import to get the log object!). When it connects this is the output I get: drzero@ernest pyssh-stuff $ ./sshsimpleclient.py 2003/10/06 22:31 CEST [-] Log opened. 2003/10/06 22:31 CEST [-] Starting factory <twisted.internet.protocol.ClientFactory instance at 0x8323b0c> 2003/10/06 22:31 CEST [ClientTransport,client] kex alg, key alg: diffie-hellman-group-exchange-sha1 ssh-rsa 2003/10/06 22:31 CEST [ClientTransport,client] client->server: aes256-ctr hmac-sha1 none 2003/10/06 22:31 CEST [ClientTransport,client] server->client: aes256-ctr hmac-sha1 none 2003/10/06 22:31 CEST [ClientTransport,client] Disconnecting with error, code 2 reason: bad packet length 415956278 2003/10/06 22:31 CEST [ClientTransport,client] connection lost 2003/10/06 22:31 CEST [ClientTransport,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x8323b0c> 2003/10/06 22:32 CEST [-] Main loop terminated. Note that the packet length changes.. Is it a problem in my code (which is basically the howto code) or a problem with my server (Gentoo w/ OpenSSH 3.7.1p2) or something else? -- 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
On Mon, 2003-10-06 at 17:04, Anders Bruun Olsen wrote:
Hi,
I am trying to learn a bit of Twisted in order to make an app that will use SSH for running commands on remote hosts. I have followed the SSH howto on the homepage where I have changed it to accept any fingerprint and have put my own private and public keys in instead of the ones from the example and have it connecting to a server of mine that accepts passwordless key-auth. Lastly I have enabled logging to stdout (it might be an idea to add to the howto which module to import to get the log object!).
When it connects this is the output I get:
drzero@ernest pyssh-stuff $ ./sshsimpleclient.py 2003/10/06 22:31 CEST [-] Log opened. 2003/10/06 22:31 CEST [-] Starting factory <twisted.internet.protocol.ClientFactory instance at 0x8323b0c> 2003/10/06 22:31 CEST [ClientTransport,client] kex alg, key alg: diffie-hellman-group-exchange-sha1 ssh-rsa 2003/10/06 22:31 CEST [ClientTransport,client] client->server: aes256-ctr hmac-sha1 none 2003/10/06 22:31 CEST [ClientTransport,client] server->client: aes256-ctr hmac-sha1 none 2003/10/06 22:31 CEST [ClientTransport,client] Disconnecting with error, code 2 reason: bad packet length 415956278 2003/10/06 22:31 CEST [ClientTransport,client] connection lost 2003/10/06 22:31 CEST [ClientTransport,client] Stopping factory <twisted.internet.protocol.ClientFactory instance at 0x8323b0c> 2003/10/06 22:32 CEST [-] Main loop terminated.
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. -p -- Paul Swartz (o_ z3p at twistedmatrix dot com //\ http://www.twistedmatrix.com/users/z3p.twistd/ V_/_ AIM: Z3Penguin
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@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
On Mon, 2003-10-06 at 17:23, Anders Bruun Olsen wrote:
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.
code clipped
can you file a bugtracker request for this? it seems the problem is that Conch and OpenSSH handle *-ctr encryption modes differently. -p -- Paul Swartz (o_ z3p at twistedmatrix dot com //\ http://www.twistedmatrix.com/users/z3p.twistd/ V_/_ AIM: Z3Penguin
On Mon, Oct 06, 2003 at 06:56:46PM -0400, Paul Swartz wrote:
code clipped can you file a bugtracker request for this? it seems the problem is that Conch and OpenSSH handle *-ctr encryption modes differently.
Done. -- 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
participants (2)
-
Anders Bruun Olsen
-
Paul Swartz