#40603·cowrie

SSH transport: `sendDisconnect()` splits most disconnect log lines, and `dataReceived()` drops the version-string length cap

Author: vbontchevCreated Sep 10, 2026Updated Sep 20, 2026

Describe the bug HoneyPotSSHTransport in src/cowrie/ssh/transport.py has two related bugs, both in SSH transport-layer error handling:

  1. sendDisconnect() only special-cases the literal reason string "bad packet length" (a workaround for a client protocol-mismatch false positive, see the comment referencing http://kbyte.snowpenguin.org/portal/2013/04/30/kippo-protocol-mismatch-workaround/). Every other disconnect reason falls through to Twisted's own SSHTransportBase.sendDisconnect(). That includes "bad packet mod", "bad decryption", "bad MAC", and "compression error", all of which twisted.conch.ssh.transport.SSHTransportBase.getPacket() triggers via sendDisconnect(). Twisted's method logs with an embedded newline ("Disconnecting with error, code {code}\nreason: {description}"), so the event is split across two physical lines in the log output: the first line gets the normal timestamp/namespace prefix, and the reason: ... half appears on its own unprefixed, tab-indented line.

  2. dataReceived() reimplements the pre-version-string buffering loop (waiting for the client's SSH-x.y-... identification line) but drops the 4096-byte cap that twisted.conch.ssh.transport.SSHTransportBase.dataReceived() applies before that wait. A client that never sends a newline can grow self.buf without bound. In this codebase that is bounded in duration only by the fixed auth_timeout, since resetTimeout() is never called elsewhere in the file, but is not bounded in size within that window.

To Reproduce For (1):

  1. Connect to Cowrie's SSH port and complete the version exchange.
  2. Send a packet whose padded length is not a multiple of the negotiated cipher's block size (or trigger any other check in getPacket() besides the packet-length-over-1MB one).
  3. Observe the resulting log entry for the disconnect: it is split across two lines instead of appearing as one event, e.g.:
2026-09-09T01:36:21+0000 [cowrie.ssh.transport.HoneyPotSSHTransport#info] Disconnecting with error, code 2
	reason: b'bad packet mod (444%8 == 4)'

For (2):

  1. Connect to Cowrie's SSH port.
  2. Send more than 4096 bytes of data containing no \n character (i.e., never complete an SSH identification line).
  3. Observe that the connection is not disconnected for this reason, and self.buf keeps growing with each additional chunk sent, until (if ever) auth_timeout elapses.

Expected behavior

  1. Every disconnect reason, not just "bad packet length", should be logged as a single line/event, consistent with the rest of Cowrie's logging.
  2. A client that sends more than 4096 bytes without completing its version identification line should be disconnected immediately with a DISCONNECT_CONNECTION_LOST reason, matching the protection SSHTransportBase.dataReceived() already provides upstream.

Server (please complete the following information):

  • OS: OS-independent (SSH transport-layer logic bug, not affected by host OS; observed on Windows 10 Pro)
  • Python: 3.14.2
  • Twisted: 26.4.0

Additional context Both bugs sit in the same method neighborhood of the same file (sendDisconnect() and the dataReceived() code immediately preceding it), which is why they are filed together rather than as separate reports.

Bug 1's root cause is in Twisted's own SSHTransportBase.sendDisconnect() (the embedded \n in its log format string). Since HoneyPotSSHTransport.sendDisconnect() already partially overrides that method for one specific reason string, the fix extends the existing override to cover all reasons instead of patching the Twisted dependency itself. The "bad packet length" workaround (skip sending the actual SSH_MSG_DISCONNECT packet) is unchanged.

Bug 2's root cause is a straightforward omission versus the method it overrides (SSHTransportBase.dataReceived()), which does include the 4096-byte cap.

  • Cowrie Mode: Shell (default)

Patched files:

  • src/cowrie/ssh/transport.py

transport.py