How HTTP Servers Receive Telnet

I understand that Telnet is a protocol as well as HTTP. I have this opinion that after the initial TCP connection is completed, the Telnet client will send some telnet code to the server on the other hand, in this case, to the HTTP server. But since the HTTP server does not understand the specific Telnet codes, it should cause an error or disconnect the connection, etc. But actually we can telnet to the HTTP server and retrieve the pages if we enter the correct HTTP headers and send them. How could this be so? The Wikipedia entry really did not help me understand this particular point. (Http://en.wikipedia.org/wiki/Telnet#Telnet_data)

+6
telnet
source share
3 answers

You are right in saying that telnet is its own protocol, which is described in several RFCs. You can look at wikipedia to find out exactly which and what other resources explain the protocol.

This basically works as follows: when you use telnet to connect to the server, it displays every printable character that the server sends to you. And everything you type will be sent back to the server. So you can get web pages when connected to a web server: you send a command that the http server accepts and get the correct result.

Now there are several telnet specifications. IIRC, you will not send them to the server unless the server sends them first. These parameters are used to enable / disable the local echo (think about passwords, you do not want them to be visible when you log into the system), coordinate the size of the terminal and coordinate the end of the line. These commands are several bytes long and begin with byte 255 (called IAC, interpreted as a command). When you connect to the telnet server, your client will interpret them and respond accordingly, all automatically in the background, without showing you these commands.

Although it is not specific to telnet, the telnet server can also send ANSI escape sequences . They are used for colors, bold, cursor positioning ... The telnet client will also interpret them (or just pass them to the terminal emulator that you use, for example xterm).

If you want something "lower level" than telnet that will not interpret telnet options and actually display what you get, you can take a look at netcat

+4
source

Telnet is just an interactive way to open a TCP connection to a listening socket. Since the telnet client blindly sends what you enter into this socket, it can theoretically emulate any other protocol over TCP. In fact, the fact that non-printable characters are interpreted by the keyboard driver is the only limit.

HTTP does not use non-printable characters except to distinguish between an HTTP header and a body with two consecutive "line breaks" (i.e., an "empty line").
Please note: I am not talking about the HTML tag tag here, but a payload (e.g. SOAP body).

No magic here basically.

Let's look at the dynamics of things.
HTTP supports several commands, such as GET, POST, PUT, etc ... Each command has its own syntax, and there is a related response with a consistent syntax and well-defined error codes. When you connect to an HTTP server using telnet, you open a socket connection and the server creates a stream to control the dialog box with your client. You can then simulate the browser by typing the command that the browser sends. Each time you press the CR key, the client sends a string to the server. If the command contains several lines, you can enter several lines, each of which corresponds to the command header line. After you press two CRs in a row (i.e., an empty line), the command header will be considered completed by the server, and the response will be collected together and sent back to your client. Since the goal of the telnet clientโ€™s life is to receive the received characters (unless otherwise indicated), you can see the header and body of the response in the terminal window. Telnet stops. The browser will display HTML (if the response is an HTML page).
I hope this clarifies everything.

+3
source

You can request an HTTP server using telnet, I often do this as a quick and nasty test telnet does not send any codes. it just establishes a connection, but there are special telnet codes that you can send if you need

do it...

telnet server.com 80 GET http/1.0 /^m host: server.com^m ^m ... servers response 

^ m = enter key

I did it on linux in windows, it could be different.

DC

0
source

All Articles