SSH transport: `sendDisconnect()` splits most disconnect log lines, and `dataReceived()` drops the version-string length cap
Describe the bug
HoneyPotSSHTransport in src/cowrie/ssh/transport.py has two related bugs, both in SSH transport-layer error handling:
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 ownSSHTransportBase.sendDisconnect(). That includes"bad packet mod","bad decryption","bad MAC", and"compression error", all of whichtwisted.conch.ssh.transport.SSHTransportBase.getPacket()triggers viasendDisconnect(). 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 thereason: ...half appears on its own unprefixed, tab-indented line.dataReceived()reimplements the pre-version-string buffering loop (waiting for the client'sSSH-x.y-...identification line) but drops the 4096-byte cap thattwisted.conch.ssh.transport.SSHTransportBase.dataReceived()applies before that wait. A client that never sends a newline can growself.bufwithout bound. In this codebase that is bounded in duration only by the fixedauth_timeout, sinceresetTimeout()is never called elsewhere in the file, but is not bounded in size within that window.
To Reproduce For (1):
- Connect to Cowrie's SSH port and complete the version exchange.
- 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). - 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):
- Connect to Cowrie's SSH port.
- Send more than 4096 bytes of data containing no
\ncharacter (i.e., never complete an SSH identification line). - Observe that the connection is not disconnected for this reason, and
self.bufkeeps growing with each additional chunk sent, until (if ever)auth_timeoutelapses.
Expected behavior
- Every disconnect reason, not just
"bad packet length", should be logged as a single line/event, consistent with the rest of Cowrie's logging. - A client that sends more than 4096 bytes without completing its version identification line should be disconnected immediately with a
DISCONNECT_CONNECTION_LOSTreason, matching the protectionSSHTransportBase.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
Source: cowrie/cowrie