390 likes | 841 Views
Telnet. The Telnet Protocol RFC 854. Overview of Telnet. Allow for remote logins to a host computer via the Internet Essentially a raw socket Emulates a virtual terminal Excellent site: http://www.scit.wlv.ac.uk/~jphb/comms/telnet.html
E N D
Telnet The Telnet Protocol RFC 854
Overview of Telnet • Allow for remote logins to a host computer via the Internet • Essentially a raw socket • Emulates a virtual terminal • Excellent site: • http://www.scit.wlv.ac.uk/~jphb/comms/telnet.html • Note: SSH is Secure SHell – an encrypted version of Telnet (port 22)
Network Virtual Terminals • Mega-Handshake • Determine: • Terminal type • Terminal width/height • Terminal Speed • Remote Flow Control • Environment Variables
WILL / WONT / DO / DONTVirtual Terminal Negotiations • WILL – Sender supports certain functionality • WONT – Sender cannot support the specified functionality • DO – Sender wants the other end to do something • DONT – Sender wants the other end not to do something
Combinations • Sender WILL/Receiver DO: Sender wants to use certain functionality. Receiver says OK. • Sender WILL/Receiver DONT: Receiver cannot support that option • Sender DO/ Receiver WILL: Sender can handle certain functionality if receiver wants. • Sender DO/ Receiver WONT: Receiver cannot support option • Sender WONT/ Receiver DONT: Option disabled • Sender DONT/ Receiver WONT: Option disabled
Telnet Algorithmics • Telnet begins at port 23 • Client and server communicate in eight-bit bytes • Client and server negotiate options • Normal telnet commands are sent
Commands • Distinguished by the most significant bit set! • SE – 240: End subnegotiations • NOP – 241: No operation • AYT – 246: Are you there? • GA – 249: Go ahead. Used in old dialup • SB – 250: Subnegotiations • IAC – 255: Interpret As Command
Negotiable Options • Echo : 1 : RFC 857 • Suppress Go Ahead : 3 : RFC 858 • Status : 5 : RFC 859 • Timing Mark : 6 : RFC 860 • Terminal Type : 24 : RFC 1091 • Window Size : 31 : RFC 1073 • Terminal Speed : 32 : RFC 1079 • Remote Flow Ctrl : 33 : RFC 1372 • Linemode : 34 : RFC 1184 • Environment Vars : 36 : RFC 1408
Negotiable Options • For some options, further negotiations are needed: Client: 255 (IAC), 251 (WILL), 24 (Term Type) Server:255 (IAC), 253 (DO), 24 Server:255 (IAC), 250 (SB), 24, 1 , 255 (IAC), 240 (SE) Client: 255 (IAC), 250 (SB), 24, 0, 'V', 'T', '1', '0', '0', 255 (IAC), 240 (SE)
How Telnet Works Primary Thread Server
Enter the Client Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationSuppress Go Ahead 255 (IAC), 253 (DO), 3 (SGA) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill Term Type 255 (IAC), 251 (WILL), 24 (TT) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill NAWS 255 (IAC), 251 (WILL), 31 (WinSize) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill TermSpeed 255 (IAC), 251 (WILL), 32 (TS) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill LineFlow 255 (IAC), 251 (WILL), 33 (LF) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill LineMode 255 (IAC), 251 (WILL), 34 (LM) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill New Environment 255 (IAC), 251 (WILL), 36 (NEnv) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill Status 255 (IAC), 251 (WILL), 5 (Status) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Client Bombards with InformationWill XDisplay 255 (IAC), 251 (WILL), 35 (XDisp) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Get Ready • Server will now send back a series of DOs • Each option is sub-negotiated
Server Bombards with InformationDO TermType 255 (IAC), 251 (DO), 24 (Type) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Server Bombards with InformationInterpret Command and Send Response Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Server Bombards with Information Interpret Command and Send Response 255 (IAC), 250 (SB), 24 (Type), 0, 'V', 'T', '1', '0', '0', 255, 240 (SE) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Server Bombards with InformationDO WinSize 255 (IAC), 251 (DO), 31 (WinSize) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Server Bombards with InformationInterpret Command and Send Response Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Server Bombards with Information Interpret Command and Send Response 255 (IAC), 250 (SB), 31 (WinSize), 0, 80, 0, 24, 255, 240 (SE) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Etc… Etc… 255 (IAC), 251 (DO), X Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Etc… Etc… Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Etc… Etc… 255 (IAC), 250 (SB), X, X, X, 255, 240 (SE) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
What if you DONT want to do something? • Send the WONT command • Good default response! • Technically, you can do this for ALL responses • Good if you don't know what the option is • Example: Timing mark…
Server Requests DO 255 (IAC), 251 (DO), 6 (TMark) Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Interpret Command Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Send Back WONT 255 (IAC), 252 (WONT), 6 Primary Thread Primary Thread Socket (23) Secondary Reader Thread Client Server
Overall Algorithm • Byte mode: • Optionally send all your DOs • Interpret commands coming over the net • Send appropriate responses • String mode: • Read and send Strings for the rest of the time
Things that Might Save You Time • A class that: • knows all the command codes (constants) • can print out those codes in English • A class that can send terminal info: • Big case statement • Generic sendDO( ), sendDONT( ) • Generic sendWILL( ), send WONT( ) • Specific methods for sending subnegotiated options (like TermType, TermSpeed, etc)