Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-LANG-SEC-064 --project .About This Rule
Understanding the vulnerability and how it is detected
telnetlib.Telnet() implements the Telnet protocol, a legacy remote terminal protocol that transmits all data including usernames, passwords, commands, and command output in plaintext over TCP. Telnet was deprecated in Python 3.11 and removed in Python 3.13 due to its security problems.
Any credentials used to authenticate to a Telnet service are transmitted in plaintext and can be captured by any observer on the network. Commands executed via Telnet and their output are also visible, potentially exposing sensitive system information.
SSH is the universally accepted secure replacement for Telnet. Python's paramiko library provides a complete SSH client implementation that supports password and key-based authentication, command execution, SFTP, and port forwarding.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Plaintext Credential Transmission
Telnet login username and password are transmitted in plaintext, one character at a time due to Telnet's character-mode protocol. An attacker observing the TCP stream can reassemble and read the complete credentials.
Session Hijacking
The entire Telnet session (commands and output) is transmitted in plaintext. An attacker who can intercept the TCP stream can inject arbitrary commands into the session, capturing or modifying the remote system state.
Network Infrastructure Attack
Routers, switches, and embedded devices that expose Telnet management interfaces are particularly vulnerable. Python scripts automating network device management via Telnet expose device credentials and configuration to network observers.
Deprecated API with Removal Risk
telnetlib was deprecated in Python 3.11 and removed in Python 3.13. Code using telnetlib will fail on Python 3.13+ and must be migrated regardless of the security concern.
How to Fix
Recommended remediation steps
- 1Replace telnetlib with paramiko for SSH-based remote command execution on Linux/Unix systems.
- 2For network device automation (Cisco, Juniper, etc.), use netmiko or NAPALM which use SSH instead of Telnet.
- 3Use SSH key-based authentication instead of password-based authentication when connecting to remote systems.
- 4Disable Telnet on all managed network devices and require SSH-only access.
- 5Migrate any telnetlib-dependent code before upgrading to Python 3.13, where telnetlib has been removed.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to telnetlib.Telnet() constructor and related telnetlib usage in Python source code. All call sites are flagged since Telnet inherently transmits all data in plaintext and is deprecated/removed in modern Python versions.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
FTP Without TLS (ftplib.FTP)
ftplib.FTP() transmits data and credentials in plaintext. Use ftplib.FTP_TLS() or SFTP (via paramiko) for secure file transfer.
Paramiko Implicit Host Key Trust (AutoAddPolicy)
paramiko.AutoAddPolicy() and WarningPolicy() automatically accept unknown SSH host keys, enabling man-in-the-middle attacks on SSH connections.
Paramiko exec_command() Usage
paramiko exec_command() runs commands on a remote host. Audit that command arguments are not derived from untrusted input to prevent command injection.
Frequently Asked Questions
Common questions about telnetlib Usage Detected
New feature
Get these findings posted directly on your GitHub pull requests
The telnetlib Usage Detected rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.