# Telnet

Telnet (short for "telecommunications network") is a client/server application protocol that provides access to virtual terminals of remote systems on local area networks or the Internet. It is a protocol for bidirectional 8-bit communications. Its main goal was to connect terminal devices and terminal-oriented processes.
Telnet consists of two components: (1) the protocol itself which specifies how two parties are to communicate and (2) the software application that provides the service. User data is interspersed in-band with Telnet control information in an 8-bit byte oriented data connection over the Transmission Control Protocol (TCP). Telnet was developed as secret technology in 1969 beginning with RFC 15, extended in RFC 855, and standardized as Internet Engineering Task Force (IETF) Internet Standard STD 8, one of the first Internet standards. Telnet transmits all information including usernames and passwords in plaintext so it is not recommended for security-sensitive applications such as remote management of routers. Telnet's use for this purpose has waned significantly in favor of SSH. Some extensions to Telnet which would provide encryption have been proposed.

## Components

Telnet consists of two components: (1) the protocol itself and (2) the service component. The telnet protocol is a client-server protocol, based on a reliable connection-oriented transport. This protocol is used to establish a connection to Transmission Control Protocol (TCP) port number 23 or 2323, where a Telnet server application is listening. The Telnet protocol abstracts any terminal as a Network Virtual Terminal (NVT). The client must simulate a NVT using the NVT codes when messaging the server.
Telnet predated UDP/IP and originally ran over Network Control Protocol (NCP). The telnet service is best understood in the context of a user with a simple terminal using the local Telnet program (known as the client program) to run a logon session on a remote computer where the user's communications needs are handled by a Telnet server program.

### Telnet Protocol
#### History

Even though Telnet was an ad hoc protocol with no official definition until March 5, 1973, the name actually referred to Teletype Over Network Protocol as the RFC 206 (NIC 7176) on Telnet makes the connection clear:
   The TELNET protocol is based upon the notion of a virtual teletype, employing a 7-bit ASCII character set. The primary function of a User TELNET, then, is to provide the means by which its users can 'hit' all the keys on that virtual teletype.
Essentially, it used an 8-bit channel to exchange 7-bit ASCII data. Any byte with the high bit set was a special Telnet character. On March 5, 1973, a Telnet protocol standard was defined at UCLA with the publication of two NIC documents: Telnet Protocol Specification, NIC 15372, and Telnet Option Specifications, NIC 15373.

#### Extensions

Many extensions were made for Telnet because of its negotiable options protocol architecture. Some of these extensions have been adopted as Internet standards, IETF documents STD 27 through STD 32. Some extensions have been widely implemented and others are proposed standards on the IETF standards track (see below).

### Telnet service

The Telnet service is the application providing services over the Telnet protocol. Most operating systems provide a service that can be installed or enabled to provide Telnet services to clients.

## Security vulnerabilities

Telnet is vulnerable to network-based cyberattacks, such as packet sniffing sensitive information including passwords and fingerprinting. Telnet services can also be exploited to leak information about the server (such as hostnames, IP addresses and brand) by packet sniffing the banner. This information can then be searched to determine if a Telnet service accepts a connection without authentication. Telnet is also frequently exploited by malware due to being improperly configured. In fact, Telnet is targeted by attackers more frequently than other common protocols, especially when compared to UPnP, CoAP, MQTT, AMQP and XMPP. Common devices targeted are Internet of things devices, routers and modems.
The SANS Institute recommends that the use of Telnet for remote logins should be discontinued under normal circumstances for the following reasons:
* Telnet, by default, does not encrypt any data sent over the connection (including passwords), and so it is often feasible to eavesdrop on the communications and use the password later for malicious purposes; anybody who has access to a router, switch, hub or gateway located on the network between the two hosts where Telnet is being used can intercept the packets passing by and obtain login, password and whatever else is typed with a packet analyzer.
* Most Telnet implementations lack authentication. An estimated 22,887 Telnet-enabled devices found by security researchers not only lacked authentication but also provided unrestricted access to the system.
* Most Telnet authentication mechanisms are vulnerable to being intercepted by Man-in-the-middle attacks.
Extensions to Telnet provide Transport Layer Security (TLS) security and Simple Authentication and Security Layer (SASL) authentication that address the above concerns. However, most Telnet implementations do not support these extensions; and they do not address other vulnerabilities such as parsing the banner information. Telnet over VPN is a viable option if SSHv2 is not supported, or a VPN is already used to securely tunnel other application data to the remote network the Telnet server is present in. However, precautions must be taken: ideally the VPN should terminate on the Telnet server itself, unless the LAN has additional security measures against eavesdropping and modification by other devices such as additional encryption and/or VLANs. This is because Telnet traffic leaves the VPN server in its insecure plaintext form after it is decrypted. The VPN software should be a trusted one that is heavily audited (e.g. OpenVPN, WireGuard, IPsec), using preferably certificate-based/public key mutual authentication.
IBM 5250 or 3270 workstation emulation is supported via custom telnet clients, TN5250/TN3270, and IBM i systems. Clients and servers designed to pass IBM 5250 data streams over Telnet generally do support SSL encryption, as SSH does not include 5250 emulation. Under IBM i (also known as OS/400), port 992 is the default port for TelnetS (Telnet over SSL/TLS).

## Uses
### Historical uses

Historically, Telnet provided access to a command-line interface on a remote host. However, because of serious security concerns when using Telnet over an open network such as the Internet, its use for this purpose has waned significantly in favor of SSH. The usage of Telnet for remote management has declined rapidly, especially on the public Internet, in favor of the Secure Shell (SSH) protocol. SSH provides much of the functionality of telnet, with the addition of strong encryption to prevent sensitive data such as passwords from being intercepted, and public key authentication, to ensure that the remote computer is actually who it claims to be.

### Modern day uses

The Telnet client may be used in debugging network services such as SMTP, IRC, HTTP, FTP or POP3, to issue commands to a server and examine the responses. For example, Telnet client applications can establish an interactive TCP session to a port other than the Telnet server port. However, communication with such ports does not involve the Telnet protocol, because these services merely use a transparent 8-bit TCP connection, because most elements of the telnet protocol were designed around the idea of accessing a command line interface and none of these options or mechanisms is employed in most other internet service connections.
For example, a command line telnet client could make an HTTP request to a web server on TCP port 80 as follows:
The older protocol is used these days only in rare cases to access decades-old legacy equipment that does not support more modern protocols. For example, a large number of industrial and scientific devices only have Telnet available as a communication option. Some are built with only a standard RS-232 port and use a serial server hardware appliance to provide the translation between the TCP/Telnet data and the RS-232 serial data. In such cases, SSH is not an option unless the interface appliance can be configured for SSH (or is replaced with one supporting SSH).
Telnet is commonly used by amateur radio operators for providing public information.
Despite recommendation against it, security researchers estimated that 7,096,465 exposed systems on the Internet continue to use Telnet as of 2021. However, estimates of this number have varied significantly, depending on the number of ports scanned beyond the default TCP port 23.

## Technical details

The technical details of Telnet are defined by a variety of specifications including RFC 854.

### USASCII control codes

| Name | Byte code |
| NULL | 0 |
| Line feed | 10 |
| Carriage return | 13 |
| Bell | 7 |
| Backspace | 8 |
| Horizontal tab | 9 |
| Vertical tab | 11 |
| Form feed | 12 |
| Source: J. Postel and Reynolds (1983) ||||

### Telnet commands

Telnet commands consist of at least two bytes. The first byte is the IAC escape character (typically byte 255) followed by the byte code for a given command:
| Name | Byte code | Explanation |
| SE (Subnegotiation end) | 240 | End of negotiation (or data block) of a sub-service of a protocol mechanism |
| NOP (No operation) | 241 | Data packet that does nothing |
| Data Mark | 242 | |
| Break | 243 | |
| Interrupt Process | 244 | Request that other party ends current process |
| Abort output | 245 | Request that other party stops sending output |
| Are you there? | 246 | |
| Erase character | 247 | |
| Erase Line | 248 | |
| Go ahead | 249 | |
| SB (Subnegotiation begin) | 250 | Initiate the negotiation of a sub-service of a protocol mechanism |
| WILL | 251 | Informs other party that this party will use a protocol mechanism |
| WON'T | 252 | Informs other party that this party will not use a protocol mechanism |
| DO | 253 | Instruct other party to use a protocol mechanism |
| DON'T | 254 | Instruct other party to not use a protocol mechanism |
| IAC | 255 | Sequence Initializer/Escape Character |
| Source: J. Postel and Reynolds (1983) ||||

#### Interpret As Command

All data octets except 0xff are transmitted over Telnet as is. (0xff, or 255 in decimal, is the IAC byte (Interpret As Command) which signals that the next byte is a telnet command. The command to insert 0xff into the stream is 0xff, so 0xff must be escaped by doubling it when sending data over the telnet protocol.)

### Telnet options

Telnet also has a variety of options that terminals implementing Telnet should support.
Telnet Options :
| Code | Name | Spec | Notes |
| 0 | Binary Transmission | RFC 856 | The 8-bit mode (so named binary option) is intended to transmit binary data, not ASCII characters. The standard suggests the interpretation of codes 0000–0176 as ASCII, but does not offer any meaning for high-bit-set data octets. There was an attempt to introduce a switchable character encoding support like HTTP has, but nothing is known about its actual software support. |
| 1 | Echo | RFC 857 | |
| 2 | Reconnection | NIC 15391 of 1973 | |
| 3 | Suppress Go Ahead | RFC 858 | The "Go Ahead" command code (249) in the original Telnet protocol is used to notify to the other end that the other end could start sending back messages. This was used in "half duplex" communication, as some terminals could send messages and receive messages, but not simultaneously. |
| 4 | Approx Message Size Negotiation | NIC 15393 of 1973 | |
| 5 | Status | RFC 859 | |
| 6 | Timing Mark | RFC 860 | |
| 7 | Remote Controlled Trans and Echo | RFC 726 | |
| 8 | Output Line Width | NIC 20196 of August 1978 | |
| 9 | Output Page Size | NIC 20197 of August 1978 | |
| 10 | Output Carriage-Return Disposition | RFC 652 | |
| 11 | Output Horizontal Tab Stops | RFC 653 | |
| 12 | Output Horizontal Tab Disposition | RFC 654 | |
| 13 | Output Formfeed Disposition | RFC 655 | |
| 14 | Output Vertical Tabstops | RFC 656 | |
| 15 | Output Vertical Tab Disposition | RFC 657 | |
| 16 | Output Linefeed Disposition | RFC 658 | |
| 17 | Extended ASCII | RFC 698 | |
| 18 | Logout | RFC 727 | |
| 19 | Byte Macro | RFC 735 | |
| 20 | Data Entry Terminal | RFC 1043 RFC 732 | |
| 21 | SUPDUP | RFC 736 RFC 734 | |
| 22 | SUPDUP Output | RFC 749 | |
| 23 | Send Location | RFC 779 | |
| 24 | Terminal Type | RFC 1091 | |
| 25 | End of Record | RFC 885 | |
| 26 | TACACS User Identification | RFC 927 | |
| 27 | Output Marking | RFC 933 | |
| 28 | Terminal Location Number | RFC 946 | |
| 29 | Telnet 3270 Regime | RFC 1041 | |
| 30 | X.3 PAD | RFC 1053 | |
| 31 | Negotiate About Window Size | RFC 1073 | |
| 32 | Terminal Speed | RFC 1079 | |
| 33 | Remote Flow Control | RFC 1372 | |
| 34 | Linemode | RFC 1184 | |
| 35 | X Display Location | RFC 1096 | |
| 36 | Environment Option | RFC 1408 | |
| 37 | Authentication Option | RFC 2941 | |
| 38 | Encryption Option | RFC 2946 | |
| 39 | New Environment Option | RFC 1572 | |
| 40 | TN3270E | RFC 2355 | See IBM 3270 |
| 41 | XAUTH | | |
| 42 | CHARSET | RFC 2066 | |
| 43 | Telnet Remote Serial Port (RSP) | | |
| 44 | Com Port Control Option | RFC 2217 | |
| 45 | Telnet Suppress Local Echo | | |
| 46 | Telnet Start TLS | | |
| 47 | KERMIT | RFC 2840 | See Kermit (protocol) |
| 48 | SEND-URL | | |
| 49 | FORWARD_X | | |
| 50-137 | Unassigned | | |
| 138 | TELOPT PRAGMA LOGON | | |
| 139 | TELOPT SSPI LOGON | | |
| 140 | TELOPT PRAGMA HEARTBEAT | | |
| 141-254 | Unassigned | | |
| 255 | Extended-Options-List | RFC 861 | |
| Source: Internet Assigned Numbers Authority (n.d.) ||||

## Telnet clients

* AbsoluteTelnet is a telnet client for Windows. It also supports SSH and SFTP.
* Inetutils includes a telnet client and server and is installed by default on many Linux distributions.
* Line Mode Browser, a command line web browser
* NCSA Telnet
* PuTTY and plink command line are a free, open-source SSH, Telnet, rlogin, and raw TCP client for Windows, Linux, and Unix.
* Rtelnet is a SOCKS client version of Telnet, providing similar functionality of telnet to those hosts which are behind firewall and NAT.
* RUMBA (Terminal Emulator)
* SecureCRT from Van Dyke Software
* SyncTERM is a BBS terminal program supporting Telnet, SSHv2, RLogin, Serial, Windows, *nix, and Mac OS X platforms, X/Y/ZMODEM and various BBS terminal emulations
* telnet.exe command line utility included in default installation of many versions of Microsoft Windows.
* TeraTerm
* ZOC Terminal

## In popular culture

Star Wars: Episode IV – A New Hope from 1977 has been recreated as a text art movie served through Telnet.