Skip to content

fix: stabilize TELNET connection flow and enable LLM prompts#260

Merged
mariocandela merged 1 commit intobeelzebub-labs:mainfrom
YOZZOPANOZZO:telnet-fix
Feb 13, 2026
Merged

fix: stabilize TELNET connection flow and enable LLM prompts#260
mariocandela merged 1 commit intobeelzebub-labs:mainfrom
YOZZOPANOZZO:telnet-fix

Conversation

@YOZZOPANOZZO
Copy link
Copy Markdown
Contributor

@YOZZOPANOZZO YOZZOPANOZZO commented Feb 12, 2026

Describe the bug
TELNET had two issues:

login/terminal could freeze during connection handling
LLMHoneypot commands failed on TELNET with ìno prompt for protocol selected'
To Reproduce

Enable TELNET with a command using plugin: "LLMHoneypot".
Start Beelzebub and connect via telnet.
Log in and run commands like git or uname.
See freeze behavior or LLM failure.
Expected behavior
TELNET login should be stable, and TELNET LLM commands should work like SSH.

Summary by CodeRabbit

  • New Features

    • Added TELNET protocol support alongside existing SSH capabilities; TELNET port (23) now exposed and accessible.
    • Improved TELNET session handling with refined input processing and user session tracking.
  • Bug Fixes

    • Enhanced error reporting with additional context for better diagnostics.
  • Tests

    • Added test coverage for TELNET protocol functionality.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

This PR extends TELNET protocol support to LLM integration, exposes the TELNET port in Docker Compose, refines IAC negotiation and input handling in the TELNET implementation, improves error context in the cloud plugin, and adds corresponding test coverage.

Changes

Cohort / File(s) Summary
Infrastructure Configuration
docker-compose.yml
Added TELNET port binding (23:23) to beelzebub service.
LLM Protocol Integration
plugins/llm-integration.go, plugins/llm-integration_test.go
Extended LLM prompt building to handle TELNET protocol alongside SSH; added TestBuildPromptTelnet test case.
TELNET Implementation
protocols/strategies/TELNET/telnet.go
Refactored IAC negotiation constants and handling; improved readLine to properly strip IAC sequences and subnegotiations; added User field propagation in traces; simplified initial negotiation flow; adjusted login prompt formatting.
Error Handling
plugins/beelzebub-cloud.go
Wrapped JSON unmarshalling errors with additional context including response body.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • Issue #259: Addresses TELNET freeze and LLM prompt failures by implementing TELNET protocol handling in LLM integration and refactoring IAC negotiation logic.

Possibly related PRs

  • PR #253: Modifies overlapping TELNET implementation and LLM integration code paths, extending protocol support across similar layers.

Poem

🐰 A telnet tale of codes so neat,
IAC strips and prompts repeat,
User traces leap through air,
Port 23 binds with care,
Protocol dreams made complete!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description identifies the bugs (freeze and LLM failure), provides reproduction steps, and states expected behavior, but does not follow the provided template structure with checkboxes for contributing guidelines, tests, linting, or core feature changes. Align the description with the provided template: add checkbox sections for contribution guidelines, test verification, linting, and explanation of changes and why they should be included.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: stabilizing TELNET connection flow and enabling LLM prompts for the protocol, which aligns with the bug fixes and objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@protocols/strategies/TELNET/telnet.go`:
- Around line 328-330: The discarded conn.Read call when handling IAC option
bytes (cases WILL, WONT, DO, DONT) ignores errors and can leave buf[0] stale if
the connection drops; update the code in telnet.go so the read used to discard
the option byte checks both (n, err) = conn.Read(buf[:1]) and handles errors
(return or break from the loop on non-nil err or n==0) instead of ignoring them,
ensuring you don't proceed using an uninitialized buf[0].
🧹 Nitpick comments (2)
protocols/strategies/TELNET/telnet.go (2)

339-342: Consider adding explicit parentheses for readability.

The precedence is correct (&& > || in Go), but explicit grouping makes intent clearer at a glance.

Suggested tweak
-		if b >= 32 && b <= 126 || b == '\t' {
+		if (b >= 32 && b <= 126) || b == '\t' {

284-292: Negotiation drain reads only once — may miss multi-segment IAC bursts.

conn.Read returns as soon as any data is available, so if the client sends negotiation across multiple TCP segments (common with some telnet clients), only the first segment is consumed. Consider a small read loop until the deadline expires.

Suggested approach
 func negotiateTelnet(conn net.Conn) {
 	buf := make([]byte, 256)
 	conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
-	conn.Read(buf)
+	for {
+		_, err := conn.Read(buf)
+		if err != nil {
+			break
+		}
+	}
 	conn.SetReadDeadline(time.Time{})
 }

@mariocandela
Copy link
Copy Markdown
Contributor

Issue: #259

@mariocandela mariocandela linked an issue Feb 13, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@mariocandela mariocandela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work! :)

@mariocandela mariocandela merged commit 48a4fd1 into beelzebub-labs:main Feb 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: TELNET freeze and LLM support

2 participants