$25
This exercise is intended to acclimate you to the UNIX environment. It proceeds as follows:
1. Introduce yourself to unix via our collection of videos and reference documents.
2. "Clone" assignment 0 to get the assignment starter les.
3. Answer questions about unix and course logistics in a readme.txt le, and then perform an intruder detection activity with milestones recorded in the same readme.txt le.
4. Build, run, and test a simple C program using the unix tools and then make a small extension to the code.
Note for the Unix experts: If you are already familiar with Unix, you will nd that the Unix overview will cover material you already know, so you can quickly skim through task 1 above. Be sure to explore the things speci c to our CS107 and then you can move right into the fun little intruder detection task and simple C program.
Unix topic reference
Start by reviewing / learning the list of topics in the Unix Reference, which you can nd by clicking on "Getting Help-Unix Reference" at the top of this web page.
For any topic listed that you are unfamiliar with, read through the document and/or watch the video, and then try out the commands and do some of your own experimentation until you feel comfortable. Go through each topic in the list if you need to.
We think the videos are pretty nifty -- live demonstration of using the commands while having someone talk you through it, but we also provide written materials if that's more your style. You're free to do one or the other (or both!) -- whatever works best for you! If you are still confused about a topic after reading/viewing, come by our o ce hours
(/class/cs107/o cehours.html) or post on Piazza (/class/cs107/forum_email.html) to get further help.
The unix materials will be available all quarter and you can return to them at any time during CS107 to be introduced to a command or get a refresher on a topic.
Get started
When starting a CS107 assignment, you get a copy of the starter les by "cloning" your class repo. Follow the instructions in our cloning guide (/class/cs107/unixref/topics/cloning).
The path to your assignment repo is /afs/ir/class/cs107/repos/assign0/$USER . If you attempt to clone your repo and receive an error that the "repository does not exist":
1. double-check for typos in the path. The path needs to be typed just as shown above. This includes the odd-looking $USER at end, which is a environment variable that expands into your username automatically.
2. be sure you are logged into the myth systems.
If you con rm you are on a myth system and your correctly-typed repo path is not available, this indicates that you were not on the Axess enrollment list at the time we created the student repos. Drop an email to cs107@cs and tell us your username and we can manually set up a repo for you. Please make sure to enroll in Axess so you'll automatically get repos in the future.
After cloning the starter project, open up the readme.txt le in your editor of choice. Follow the directions in that le and answer the questions that are posed in it.
Intruder detection activity
Now you can put your newfound knowledge of unix to work! We'll expect you to think about which commands you learned that will be the most helpful as you try to solve the mystery and answer your friend's questions about what happened to their computer.
Situation: You are helping a friend whose Unix-based system has been compromised. A hacker had broken into their system and mucked with the les. The friend made a backup copy of several key directories at the time of the break-in as evidence. You're going to examine those les to try to piece together some of the details of what happened and what needs to be xed.
These evidence les are in samples/server_image-91107/ , which you can access within your cloned assign0 directory. *Note: The samples directory is a symbolic link (further information about symlinks (/class/cs107/unixref/topics/symlinks)).
Your friend has determined that one of the rst things that the intruder did is add their username to the list of "trusted" users of the system. This list is kept in a le
config/trusted.list . Whenever this le is edited, a backup copy of its contents before the edit is automatically made. This backup copy from the most recent edit is also in the config/ directory.
The malicious intruder is the only person whose username was added between these two versions. Based on this information, you should be able to answer these questions (put your answers in the readme.txt ):
What is the username of the intruder? (Hint: the di command could be helpful) What is the date and time when the trusted.list le was changed?
This timestamp indicates when the intruder was active on the system. Your friend believes they were on the system for a few days around that time and no other user was active during those days. It looks like the intruder was installing malicious programs. The system's programs
(including ones you'll recognize like ls and cd , among others) are located in the bin/ directory. Look at the programs and determine which ones may have been edited or installed by the intruder, based on the timestamps of the les.
What programs in the server_image-91107/bin/ directory appear (based on timestamp) to have been edited by the intruder?
Having the malicious code present on the system is of little use (from the intruder's perspective) if it is not executed. Your friend's system has a way that each user can con gure certain programs to be automatically launched whenever they log in. This convenience is something the intruder may have tried to exploit, by editing other users' con guration of this feature to execute the malicious programs they installed. Each user has a le called init.d in their home directory. The users' home directories are located in the user/ directory. You can open a couple of these init.d les to see what they look like, but the main thing to know is that if the name of one of the malicious programs you identi ed appears in the init.d le, that le should be considered compromised. Answer this question in your readme.txt le:
Which users appear to have had their init.d le compromised by the intruder? (Hints: Google "grep or operator" to nd examples of more sophisticated pattern matching pattern with grep and read the grep man page for what ag performs a recursive search in a directory).
Simple C program
The nal task of the assignment gives you practice using the unix development tools to edit, build, run, and test a simple C program.
In your assign0 folder, type make . You should see something like this:
You have now built the program called triangle . Run the program to see what it does:
You should be rewarded with an ascii representation of Sierpinski's triangle - cool! Try to run
make again:
This means that nothing has changed, so there isn't anything to compile. If you want to force recompilation, you can "clean" the program:
Now if you re-run make , you will re-compile the program:
Open triangle.c in a text editor and change the value of the variable nlevels in main from 3 to 5. After you have saved the le, you must re-run make to re-build the program. If you forget to re-run make , you will run the original, non-modi ed program. After running make again, run the newly built program to see the bigger Sierpinski triangle.
The starter code uses a xed constant for the number of levels to print. Your task is to extend the program to take an optional command-line argument that allows the user to dictate the number of levels. With no arguments ./triangle should default to a level 3 triangle, but if the user should also be able to run, say, ./triangle 4 or ./triangle 2 to control the number of levels. If given an unworkable number of levels (anything larger than 8 gets unwieldy and negative would be nonsensical), your program should reject it with a helpful and explanatory message that informs the user how to correct their error.
In order to complete this task, the program will need to convert the user's argument (supplied in string form) into an integer. The C library function atoi can be used to do this. Review the man page ( man atoi ) or look in your C reference to get acquainted with this function.
We'd also like to introduce you to the sanitycheck tool that you will use throughout CS107 as a testing aid. Please carefully read our instructions for using sanitycheck
(/class/cs107/sanitycheck.html) and try it out! The default sanity check tests validate the output of the triangle program when given no argument and the unmodi ed starter program code should pass. Your starter les also include a sample custom_tests les that can be used with sanitycheck to test the extended behavior when triangle is invoked with an argument. When nished, your triangle program should also pass these custom tests.