Programming Languages

Project Files
Due Sunday, September 25th

Worth 50 points


This class requires a broad background and draws from a variety of tool sets. The following is designed with the intent to give you a chance to exercise some of the skills you will need at specific points in the class that we won't have time to introduce. These exercises are not designed to be conceptually challenging and should be doable in a line or two of code each. Note that the project files include a test suite which has examples in case you have confusion when trying to get exactly the right output.

Doing this assignment on hamsa is recommended to avoid any cross-platform headache.


C is a wonderfully low-level language which gives the programmer a great deal of control over the computer. Many well known and common vulnerabilities can be exploited by abusing that power.

Fill in the body of the following function:

* Parameters: buffer (pointer to a 100 character buffer)
*             num    (4 byte int)
* Description: Writes a string to buffer containing num's value written in decimal, hexadecimal
* (left padded with 0s to be 8 characters wide and prefixed with 0x), then it's hexadecimal
* value printed in little-endian (also left padded and prefixed).  These fields should
* appear in order as listed and be separated by | (the pipe character).
int put_stuff_in_buffer(char* buffer, int num) {
    return 0;

Hint: Remember EECS 213


MySQL is going to be the database of choice for this class. You will probably only need to know MySQL on one or two occasions for this course, which is why we don't have time to teach it to you. However, it will be significantly less frustrating to learn MySQL and then learn SQL injection rather than learn both at the same time.

Write a series of .sql files:

  1. Creates a table called test with 3 columns.
    • 1st column: An int column called pk that is by default 1 more than the previous row when a new row is inserted, known as a primary key.
    • 2nd column: A varchar(20) column called name which can be used to store user names.
    • 3rd column: A char(32) column called password which can be used to store password hashes.
  2. Adds 2 rows to the table for users Foo and Bar, both with password f00Bar. The passwords should be stored as hashes.
  3. Creates a table called test_color with two columns:
    • 1st column: An int column called user_pk which can be used to identify the matching row in the test table.
    • 2nd column: A varchar(20) column called fav_color which can be used to store the user's favorite color.
  4. Changes Foo's password to "FoodBar" and sets Foo and Bar's favorite colors to "Purple" and "White", respectively.
  5. A single query that dumps:
    • All of the rows in both tables.
    • All of the names of all of the columns in both tables and the tables they belong to.

Output of Solution to 5.sql:

| pk        | name          | password                         |
| 1         | Foo           | *13488180CAC0FAD93622133AD6DBF52 |
| 2         | Bar           | *87151771178AE37AFFF2EA68112ADCF |
| 1         | Purple        |                                  |
| 2         | White         |                                  |
| pk        | test          |                                  |
| name      | test          |                                  |
| password  | test          |                                  |
| user_pk   | test_color    |                                  |
| fav_color | test_color    |                                  |




Ruby is an all-purpose scripting language that is popular among the security community because of its ties to the Metasploit toolset. It's also good for the occasional one-liner off the command line.

Just to get you exposed to it, write a function called verify which validates that its argument (a string) could be buffer after it has been passed to put_stuff_in_buffer() in the C exercise. If it is, return a true value, otherwise return a false value.

Hint: Use regular expressions.

*Resources: is a good crash course.


You really should know javascript if you want to do anything with the web (and we do things related to the web in this class). However, the course is designed such that you don't need any background in javascript coming in, though hopefully you'll leave knowing some.

Shell Commands

Knowing how to live in a text-only environment is really useful. In fact, it's crtitical, because once you've exploited a machine, you often have nothing but characters coming at you from a TCP socket. The following commands will be sufficient to complete the exercises below. It is highly recommended that you refer to their man pages for more information:

  1. Commands to know
    • Elementary: cd, ls, cp, mv, echo, cat, less
    • Basic: grep, ps, kill, find, bg, fg, export (in bash, set for csh), chmod, touch, man
    • Useful: pushd, popd, killall, top, screen
    • Programming: make, gcc, gdb
    • Internet: wget, curl, nc, netstat
  2. Piping and Redirection
    • The concept of piping doesn't really exist in a graphical environment
    • What do the characters |, <, > do? How does & relate to them?
    • How do you use the contents of a file as though you had typed them into a program? (aka redirect a file to stdin)
  3. Learn a command-line text editor
    • Strictly speaking, you will not have to know how to use a command line text-editor in this class, but it will make your life easier now and in the future.
    • Your options: vi, emacs, nano
      • all can do the basics (syntax highlighting, find/replace)
      • vi (or vim) is the most widespread text editor for *nix environments
      • emacs is a similarly popular alternative to vi
      • nano will be on all the computers for which you have a login in this class but is not recommended

Write a series of .sh files (they will be run by bash):

  1. Makes a new (empty) directory named test in the current working directory

  2. Creates the following 10 files inside the new directory test: file1.txt, file2.txt, file3.csv, file4.txt, file5.csv, file6.txt, file7.csv, file8.txt, file9.csv,

  3. Writes the string This is file 1. to the file file1.txt

  4. Changes the name of file1.txt to foobar.txt

  5. Lists all the filenames with the csv extension. The output should print one file on each line and they should be sorted alphabetically. The listing should include test/ as part of the relative path name.

  6. Delete file8.txt. <Temporary Note> The testrig was updated on Friday so redownload the project files if you are getting errors on this part in particular.

  7. Changes the permissions of the file to be readable and executable by the owner but only readable by everyone else.

  8. Prints 400 of the letter A to stdout (hint: use ruby)