Impersonating standard web and mail clients with telnet and nc


Capture some interactive sessions with various servers into a log file. Print out the log file and turn it in.

You will interact with the servers using a non-standard, manual client. The client will be either telnet or nc (netcat). For example you can use nc to interact with a web server and get it to send you the same thing it sends when contacted through Internet Explorer or Firefox. nc takes those browsers' place (nc is a browser when it does this). Since you don't usually browse with this particular client, it's non-standard. Since making nc send to the server anything Internet Explorer would normally send requires typing it out, it's manual.

You will operate from the platform of the machine at 66.159.240.70 (with alternative domain name dmorgan.us). Log in to your individual account there, per your instructor. You will then be in your home directory.

The assignment is to capture your session using the Linux "script" command (here's how). It effects logging, so that you will end up with a file containing a copy of what happened on your screen. When you are finished I want the file containing your results transfered to your "assignments" directory on sputnik.smc.edu, where I will come look for it when ready to grade it. Run the script command to start the logging feature at the very beginning of your session, as soon as you have logged in.

Then you'll do 4 things-- get an alphabetic "letter upgrade," browse/get a webpage or other file from a web server, send an email, and receive an email.

1) get a letter upgrade - client platform: 66.159.240.70  server platform: 71.165.106.223

On the server platform a server program that accepts one letter of the alphabet and returns the next is running. It's listening to port 9999. Any client that a) connects to 9999 and b) then sends a letter, will get service. We have used a complete, self-contained program (client3.c) written for just that specific purpose. nc is general purpose, it can connect to any port (application) at any machine (IP address) and send it anything. What it sends is what it's given. It's not written, itself, to send anything in particular. How is it given what it sends? Through its standard input. If you run it alone, that ties into the keyboard. If you pipe or indirect something to it, the pipe or source file replaces the keyboard. No matter. Whatever shows up at it's standard input doorstep, it sends. Issue the following command:

nc  71.165.106.223  9999

It will pause awaiting keyboard input. Give it any letter and press enter. The next letter in the alphabet will appear. Do it again, but supplying the input letter in the first place so it doesn't have to ask you to key it in:

echo A  |  nc  71.165.106.223  9999

The letter B will appear.

2) make a web server send you things - client platform: 66.159.240.70  server platform: 71.165.106.223

Before you do this, from any machine with a graphic interface and browser (not 66.159.240.70, but perhaps the local one at which you are seated)

 - type in "http://71.165.106.223/turtles.html" and view the result. Also, use the browser's feature to view the source

 - type in "http://71.165.106.223/gettysburg.txt" and view the result. Also, use the browser's feature to view the source

 - type in "http://71.165.106.223" and view the result. Also, use the browser's feature to view the source

Now you have an idea what the server has to send. In the first case you asked it to send you turtles.html and it did. In the second case you asked it to send you gettysburg.txt and it did. In the third case you didn't ask it to send you anything but it sent you something, by default. That's because even though you didn't make any specific request yourself, the browser made a general one and the server is set up with a default file to supply in such cases. Congratulations.

Now let's use nc from our client platform to make the server to send these same 3 things:

nc  71.165.106.223  80

This time nothing happens. That's because not only did you make no specific request, this time the browser (nc) made no general one either. These requests are formalized as part of the language that web clients and servers talk. That language is called hyptertext transfer protocol (http). In that language, the general "send me your default stuff" request takes the form " GET  /  HTTP/1.0 ". Then a carriage return follows. If that is sent to the server, it will send default stuff back. Let's make our 3 requests in nc, same as above:

nc  71.165.106.223  80
GET /turtles.html HTTP/1.0
<enter>

then:

nc  71.165.106.223  80
GET /gettysburg.txt HTTP/1.0
<enter>

then:

nc  71.165.106.223  80
GET / HTTP/1.0
<enter>

For documentation what the http commands are, how to do this step-by-step, see Lars Garshol's page.


3) send an email - client platform: 66.159.240.70  server platform: mail.dslextreme.com

The machine mail.dslextreme.com runs both a mail sending (smtp) server on its port 25, and a mail collection (pop) server on its port 110. First we'll send. Use telnet instead of nc this time (more commonly Outlook or Thuderbird might do it instead).

telnet mail.dslextreme.com 25

You find yourself in an interactive environment. You need to know the language in this environment. It's called simple mail transport protocol (smtp). At this prompt, you'll give the following commands in sequence. They will be interspersed on screen with return messaging from the server:

HELO

MAIL FROM:cs70test

RCPT TO:cs70test@dslextreme.com

DATA

QUIT

After you give the DATA command and the server tells you its ready, type something like:

Subject: test from Dave
Sender: cs70test@dslextreme
To: cs70test@dslextreme.com

hello this is a message

.

The dot at the end is important. Also leave blank lines before and after your "message" line. You just sent a message from account cs70test to itself. Try doing the same thing again, but this time from cs70test to some email account you actually have, and can actually test for success or failure.

Did you get the message you sent to yourself?


4) view/collect email messages being held - client platform: 66.159.240.70  server platform: mail.dslextreme.com

We've just sent. Now let's receive. There's a type of server for that called a post office server and it speaks a language called post office protocol (POP). Connect to it with nc as client speaking POP and check the mail being held on the server for user account cs70test. That account has "password" as its password. The post office server runs on port 110. The fact that both smtp and pop servers are co-located on the same machine here (mail.dslextreme.com) is incidental. They can independently be on any machines.

nc  mail.dslextreme.com  110

You find yourself in an interactive environment. You need to know the language in this environment. It's called post office protocol (pop). At this prompt, you'll give the following commands in sequence. They will be interspersed on screen with return messaging from the server:

USER cs70test

PASS password

LIST

RETR <number>

QUIT

After the LIST command you'll get a list of messages that are on the server, numbered and giving their size in bytes. To view a message use the RETR command, followed by that message's number.

 

When you're all done turn off the "script" command's logging:

exit

"script" will have left your work in a file named "typescript". You should verify that it exists ("ls" command) and that it contains the right stuff ("cat typescript" command). If not, re-run script to start over; it will overwrite the typescript file and make a new one for a fresh start.

Place your typescript file (which is not on sputnik!) into the "assignments" subdirectory of your sputnik home directory. To do so, connect to sputnik.smc.edu using ftp and log in under your personal account name. Then "put" the file "typescript" there. Then connect using telnet. You'll find the typescript file in your home directory. Move it (mv) to the assignments subdirectory instead. That's where I'll look for it.