Introduction§
In this assignment, you will use the nc (netcat) program to experiment with text-based application protocols.
In the first part, you will use nc to contact a web server and request a page "manually." In the second part, you will consider SMTP servers and sending email. In the third part, you will investigate another text-based application protocol with which you might not yet be familiar.
In each case, the server you contact will not know that a human controls one end of the connection; you must follow the application protocol exactly to obtain the desired result.
Goals§
- To understand protocols as rules for conversation
- To understand how application layer protocols use an ASCII encoding for messages
- To experiment with some common application protocols
Acknowledgments§
This lab is based on experiments 3.2 and 3.3 in Hands-On Networking with Internet Technologies by Douglas Comer (2nd edition, 2005).
References§
- P&D: World Wide Web (HTTP)
- P&D: SMTP - Message Transfer (includes an example of an SMTP exchange sending an email)
- The Simple Mail Transfer Protocol (SMTP)
- Internet Relay Chat (IRC) and Example IRC Communications
- RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
- RFC 2821: Simple Mail Transfer Protocol
- RFC 2812: Internet Relay Chat: Client Protocol
- You can find an index of Internet RFCs at rfc-editor.org (there are... many), or just pull them up via web searches.
Logistics§
Each student should complete this assignment and write it up individually. However, you may discuss the material with whomever you wish. You may obtain help from anyone you wish, but you should clearly document that help.
Lab Report§
Again, pay attention to the Technical Report Guidelines and Suggestions when writing lab reports.
In this lab report: For each step in the laboratory assignment, show what you did (within reason — do not include long transcripts of unimportant output), explain what you saw, and answer the questions given. (If you want to record a transcript of everything you do to look at or copy from later, investigate the script unix utility.)
Assignment§
Preparation§
To prepare for this assignment, skim the first two references above that describe protocols for the web and email. You may wish to find other resources to fill in details or provide alternative explanations.
Determine where you will run the nc program:
- It is available in most Unix-like operating systems, including MacOS and Linux.
- If running Ubuntu (e.g. via WSL), run
sudo apt install netcatto install it. - If you do not have and cannot install nc on your own computer, you can access an IWU server running Linux that has it. Log in to sun.iwu.edu via SSH by running ssh [username]@sun.iwu.edu (replacing [username] with your IWU username) and run nc from there.
Determine how to run nc:
- On any system where it is installed, you should be able to read its manpage (manual) by running
man nc(press 'q' to quit). - We will only run it as a client, for which the required arguments are the hostname and port to which you want to connect.
- We will also need to send CRLF as the line-ending string (this stands for "carriage-return line-feed," which are two whitespace characters often written in code as \r\n). Find in the manpage how to make nc send CRLF as the line-ending. It will require adding an option to the command you run.
Part A: Use nc to retrieve a web page§
- Use
ncto connect towww.iwu.edu. The HTTP server listens for incoming connections on port 80. Be sure to make nc send CRLF as the line-ending. - Using information from the references or other sources, request the index page for the host
www.iwu.edu.- I recommend writing out your request in a text editor beforehand, and then you can quickly copy and paste the entire request into your terminal instead of slowly typing it out.
- Be careful with the request. A slight deviation from the protocol will result in an error. If you see
https:///400.htmlin the response, that means you have sent a malformed request, and you need to correct it. (That's not how a server is supposed to indicate an error, but this one is not quite perfectly configured...) - Notice that you do not receive a document containing IWU's front page. Why not? Why will we not be able to retrieve IWU's web site using
nc? How does a standard web browser handle the response you received?
- Using
ncagain, connect to an HTTP server atwww.example.com, and again request the index page for that host.- Make your request both with and without the
Host:header (documentation). How does it change the response? Why does the response change? - Verify that for at least one of those requests the server returns an HTML document that matches what you see when you go to www.example.com in your browser.
- Make your request both with and without the
- What do you expect to happen if you request a web page that does not exist? Why? Try it with
www.example.comand find out. - Try using the HEAD operation to request metainformation about the index page for the host
www.example.com. How is the server's reponse similar to its response in task 4? How is the response different? How is the HEAD operation useful? - Try making an HTTP request to delete a page from
www.example.com. What happens? - Why do you think the HTTP protocol includes the PUT and DELETE commands? How might they be used? Do you think they are often used in practice? Why or why not?
Part B: Use nc to send an email§
- Read the Message Transfer subsection in Peterson & Davie's introduction to SMTP. It contains an example of sending an email via SMTP.
- Use
ncto contact the campus SMTP server smtp.iwu.edu on the default port for SMTP. - Following the example in Peterson & Davie, type appropriate SMTP commands to send yourself an email. Use a fake IWU hostname test.iwu.edu as the host name in the HELO command. Use your own email address for both the sender address and the recipient address.
- Your attempt to send an email should fail. When in the exchange does it fail? If you receive a response or error message, what does the response you receive tell you about why you can't send a message just by following the example in Peterson & Davie? (You may not receive a response at all. In that case, just report that.)
- So how do we send email from on campus now? What server do we contact, on what port, and with what protocol? Well, most of us use GMail on the web. Directly connecting mail client software to mail servers is less and less common these days. IWU's instructions for configuring your email no longer describe how to do it. An archived version of that page that did give instructions links to this Google documentation. That Google page does describe how to directly connect your email client software... down at the bottom, tucked away under "Set up Gmail with older versions of Outlook and other clients," specifically in Step 4 after you have turned on a scary-sounding "less secure apps" option.
- What ports would you connect your email client to if you used this approach?
- Why does this now make it infeasible for us to contact that outgoing mail server via nc (as humans) and send email?
- Read about open mail relays on Wikipedia. What is an open mail relay and why is it a problem?
- Is smtp.iwu.edu an open mail relay? Why or why not? If you're not sure, what additional experiments would determine the answer?
The following parts of the email section of this lab are no longer possible, but they were when I first taught this class! They were great fun, too. The thing is, it wasn't good that this was possible. You could send email from president@whitehouse.gov, or anyone else for that matter. And it's not hard to see how that could be used... improperly. So it's now more secure. Good. [These are included here just for reference -- you don't need to answer the questions, and you can't try the things it says to try any more...]
- What do you think will happen if the RCPT TO command names a user that does not exist, such as
santaclaus@iwu.edu? Why? Try it and find out. - What do you think will happen if the MAIL FROM command names a user that does not exist? Why? Try it and find out.
- What do you think will happen if the MAIL FROM command names a user on another domain, such as
president@whitehouse.gov? Why? Try it and find out.
Part C: Investigate and experiment with another text-based protocol§
- Internet Relay Chat (IRC) is a popular text-based protocol that is not covered by our textbook. Search the web for information about its purpose and history, and write a one-paragraph description with appropriate citations.
- Identify an IRC server you can connect to. You will need to know the server's name and port number. You will want to find the name of an IRC channel that is appropriate for experimentation (i.e., where you won't annoy the other users).
- Use the above references on IRC (and augment with other resources found in searches, if needed). Read about the protocol architecture and messages.
- Based on what you read, make yourself a "cheat sheet" listing messages to accomplish the following tasks. Don't just write the name of the message; try to figure out what parameters you will use as well.
- register a client connection
- list the channels on the server
- join a channel
- send a message to all users on the channel
- quit
- Using nc, connect to the server and port you identified. Send appropriate messages to carry out the above tasks. (It may be easiest to type the registration commands in a text editor and copy-paste them into nc.) Consider that you are connecting to an IRC server probably used by real people to have real conversations, and choose your channel and message carefully.
- In your own words, explain the purpose of the PING and PONG messages.
Discussion Questions§
- What did you find most surprising or interesting about this assignment?
- How long did you spend on this assignment? What problems, if any, did you run into?