Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.

Programming Exam

chengsteven edited this page Sep 10, 2018 · 4 revisions

Network Security Programming Exam Fall 2018

This programming exam is to test your ability to write python networking programs.

Instructions.

Seth: sethjn@cs.jhu.edu; github: @sethnielson
Steven: stevencheng@jhu.edu; github: @chengsteven
Chanakya: cgaur1@jhu.edu; github: @cgaur1

FIRST, please set up a github repository for this course and send the staff (me and the two TA's) a link. This repository will be used throughout the semester. The free version won't let you invite us to private repositories, but for this test, you do not need to keep your project private. However, for subsequent labs, you will need private repos so you should get setup with a development pack.

https://help.github.com/articles/applying-for-a-student-developer-pack/

Once you have this set up, make your repository private and invite us to your repos.

For today, create a folder named pytest in the root of your repository and place all your test submissions in this directory.

SECOND, write some programs for the list below. There are five different client-server networking programs to write. You may choose to implement any number of these, but each program is worth a specific number of points. The minimum passing score is 50.

For each program, you must create programs to the required specifications. Please pay special attention to command line requirements.

You may use either python2 or python3 for this test. You must put either #!/usr/bin/python or #!/usr/bin/python3 at the top of your program.

THIRD, check in your work to your github.

FOURTH, optionally, if you finish early, you can ask for a visual check-off. Raise your hand and either I or a CA will review your work, observe it running, and give you a score. Otherwise, we will grade your work out of github after class.

NOTE For all programs below, if the client sends "__EXIT__" to the server, the server shuts down. The client will always shut down after receiving a response.

NOTE Do NOT use absolute paths. Use relative paths only. My computer will not be able to understand your absolute paths during grading. Save your txt files to the same directory in which your python scripts are stored.

Program 1. A simple Echo Server

Points: 15

This program creates a server that listens on a specified port for incoming connections. Clients send ascii strings to the server and the server echos the identical string back to the client. For grading purposes (and to ensure you don't just copy an echo program off the Internet), both client and server will save strings to files.

Server requirements:

  • filename: pytest_echoserver.py
  • Command line: pytest_echoserver.py <port>
  • Upon startup, listen on the port specified at the command line
  • Upon connection, record the ip address and port of the client
  • Upon receipt of data, store the ip address, port, and data in a text file in the following format
    • timestamp
    • ip address : port
    • data
  • The first message received must be saved in echo_message_1.txt, then echo_message_2.txt, and so forth
  • Close the connection after receiving the __EXIT__ request, and exit

Client requirements:

  • filename: pytest_echoclient.py
  • command line: pytest_echoclient.py <port> <message>
  • Upon startup, connect to localhost:port
  • Send the message
  • await response
  • Upon response, save the data in a text file in the following format
    • timestamp
    • echoed data
  • the first message received must be saved in echo_response_1.txt, then echo_response_2.txt, and so forth
  • Close the connection after receiving the __EXIT__ request, and exit

Program 2: Magic 8 Ball

Points: 35

This program creates a server that listens on a specified port for incoming connections. Clients will send a question to the server and the server will randomly respond with one of the following 8 responses.

  1. Your guess is as good as mine.
  2. You need a vacation.
  3. It's Trump's fault!
  4. I don't know. What do you think?
  5. Nobody ever said it would be easy, they only said it would be worth it.
  6. You really expect me to answer that?
  7. You're going to get what you deserve.
  8. That depends on how much you're willing to pay.

The answers should be given back randomly. No matter what the client sends to the server, the server should respond with one of the eight responses at random.

WITH ONE EXCEPTION. The server must keep track of the questions it has received and the answers that it has given. A duplicate question must always result in the same answer. Put another way. The first time a server receives a question, it should give a random answer. But thereafter, it must always answer that question the same way.

Server requirements:

  • filename: pytest_8ballserver.py
  • Command line: pytest_8ballserver.py <port>
  • Upon startup, listen on the port specified at the command line
  • Upon the receipt of new data, select a random response, record the data,response pair, and send back the response
  • Upon the receipt of old data, send back the previous response
  • Upon receipt of data, store the question and the selected answer in a text file in the following format
    • timestamp
    • question
    • answer
  • the first message received must be saved in 8ball_message_1.txt, then 8ball_message_2.txt, and so forth
  • Close the connection after receiving the __EXIT__ request, and exit

Client requirements:

  • filename: pytest_8ballclient.py
  • command line: pytest_8ballclient.py <port> <question>
  • Upon startup, connect to localhost:port
  • Send the question
  • await response
  • Upon response, save the data in a text file in the following format
    • timestamp
    • question
    • response
  • the first message received must be saved in 8ball_response_1.txt, then 8ball_response_2.txt, and so forth
  • Close the connection before exiting.

Program 3: Simple Bank

Points 35

This program creates a server that listens on a specified port for incoming connections. Clients will send one of three commands:

  • balance
  • deposit n
  • withdraw n

The server stores a balance for exactly one person, which starts at 0. If the bank receives a balance command, it should send back the current balance (and the client will print it out). If the bank receives a deposit amount, it will add the transmitted amount (n) to the balance and send back "OK". If it receives a withdraw amount, it subtracts that amount and sends back how much was withdrawn. If the withdraw amount is greater than the balance, it will only withdraw the current balance and sends back that amount.

Server requirements:

  • filename: pytest_bankserver.py
  • Command line: pytest_bankserver.py <port>
  • Upon startup, listen on the port specified at the command line
  • Set balance to 0
  • Upon receipt of commands, adjust the balance accordingly, and send back the response
  • Upon receipt of commands, store the command and updated balance in the following format
    • timestamp
    • command
    • balance
  • the first message received must be saved in 8ball_message_1.txt, then 8ball_message_2.txt, and so forth
  • Close the connection after receiving the __EXIT__ request, and exit

Client requirements:

  • filename: pytest_bankclient.py
  • command line: pytest_bankclient.py <port> <command> <arg>>
  • Upon startup, connect to localhost:port
  • Send the command and appropriate argument
  • await response
  • Upon response, save the data in a text file in the following format
    • timestamp
    • command arg
    • response
  • the first message received must be saved in bank_response_1.txt, then bank_response_2.txt, and so forth
  • Close the connection before exiting.

Program 4: Server Side Calculator

Points: 50

This program creates a server that listens on a specified port for incoming connections. Clients will send a math problem to the server and the server will respond with the result of the calculation. The problems will be in the format of op expr expr. expr can be another op expr expr or a number. op will be one of [+ - * /]. For example, * -2 + 3 5 will result in -16 or (-2 * (3 + 5)). For grading purposes, have the server write the complete expression to a file with the result of the calculation on a new line. You can assume the client will only send well formed math problems.

Server requirements:

  • filename: pytest_calcserver.py
  • Command line: pytest_calcserver.py <port>
  • Upon startup, listen on the port specified at the command line
  • Upon connection, record the ip address and port of the client
  • Upon receipt of a math problem, expression, and result in a text file in the following format
    • timestamp
    • math problem, with each element of the expression space separated as above
    • result
  • The first math problem received must be saved in calc_message_1.txt, then calc_message_2.txt, and so forth
  • Close the connection after receiving the __EXIT__ request, and exit

Client requirements:

  • filename: pytest_calcclient.py
  • command line: pytest_calcclient.py <port> <problem>
  • Upon startup, connect to localhost:port
  • Send the message
  • await response
  • Upon response, save the data in a text file in the following format
    • timestamp
    • response
  • the first message received must be saved in calc_response_1.txt, then calc_response_2.txt, and so forth
  • Close the connection before exiting.

Problem 5: Simple Security

Points: 50

In this program, you will be implementing a super simple server that encrypts and decrypts messages on command. The encryption mechanism you use does not have to be secure (it can be a Vigenere or Ceaser cipher) and feel free to use whatever libraries you need. You may also used fixed keys on the server side; just don't do this in the real world!
Your client will send encrypt,P where P is some plaintext. The server will respond with cipher,C where C is the ciphertext. The client will then send decrypt,C where C is the same ciphertext, and the server will respond with plain,P where P is the original plaintext.

Server requirements:

  • filename: pytest_simplesecserver.py
  • Command line: pytest_simplesecserver.py <port>
  • Upon startup, listen on the port specified at the command line
  • Upon connection, record the ip address and port of the client
  • Upon receipt of encrypt,P, send cipher,C
  • Upon receipt of decrypt,C, send plain,P
  • After sending plain,P, P, C in a text file in the following format
    • timestamp
    • P
    • C
  • The first file must be saved as security_message_1.txt, then security_message_2.txt, and so forth
  • Close the connection after receiving the __EXIT__ request, and exit

Client requirements:

  • filename: pytest_simplesecclient.py
  • command line: pytest_simplesecclient.py <port> <plaintext>
  • Upon startup, connect to localhost:port
  • Send encrypt,P
  • await response (cipher,C)
  • Send decrypt,C
  • await response (plain,P)
  • Upon the second response, save the data in a text file in the following format
    • timestamp
    • P (your chosen plaintext)
    • C (the received ciphertext)
  • the first file must be saved as security_response_1.txt, then security_response_2.txt, and so forth
  • Close the connection before exiting.

Problem 6: Simple Web Server

Points: 80

This program will act as a simple HTTP web server and client. The client will send GET requests to the server, and the server will send back an HTTP response fulfilling the GET request, either with a success or a failure message. You will need to have the server pull files from the local filesystem, i.e. if the client requests /requested_file, then the server will respond with /path/to/server/root/requested_file if it exists.

Server requirements:

  • filename: pytest_simplewebserver.py
  • Command line: pytest_simplewebserver.py <port> <path_to_server_root>
  • Upon startup, listen on the port specified at the command line
  • Upon connection, record the ip address and port of the client
  • Upon receipt of a request, send an HTTP response (you must look up the correct formatting of the HTTP response).
  • After sending the response, requested file, and the response code in the following format
    • timestamp
    • requested file
    • response code
  • The first file must be saved as web_message_1.txt, then web_message_2.txt, and so forth
  • Close the connection after receiving the __EXIT__ request, and exit

Client requirements:

  • filename: pytest_simplewebclient.py
  • command line: pytest_simplewebclient.py <port> <requested file path>
  • Upon startup, connect to localhost:port
  • Send a HTTP request for the requested file path
  • await response
  • Upon receipt of the response, save the data in a text file in the following format
    • timestamp
    • requested file path
    • response code
    • response content if response code is a success
  • the first file must be saved as web_response_1.txt, then web_response_2.txt, and so forth
  • Close the connection before exiting.

Clone this wiki locally