Lab #1

Only available on StudyMode
  • Topic: Unix, File system, Environment variable
  • Pages : 9 (2039 words )
  • Download(s) : 275
  • Published : July 18, 2011
Open Document
Text Preview
Computer science department
Data security – Lab # 1

Lab Description
Set-UID is an important security mechanism in Unix operating systems. When a Set-UID program is run, it assumes the owner’s privileges. For example, if the program’s owner is root, then when anyone runs this program, the program gains the root’s privileges during its execution. Set-UID allows us to do many interesting things, but unfortunately, it is also the culprit of many bad things. Therefore, the objective of this lab is two-fold: • Appreciate its good side: understand why Set-UID is needed and how it is implemented. • Be aware of its bad side: understand its potential security problems.

Lab Tasks

This is an exploration lab. Your main task is to ”play” with the Set-UID mechanism in Linux, and write a lab report to describe your discoveries. You are required to accomplish the following tasks in Linux: 1) Figure out why “passwd”, “chsh”, and “su” commands need to be Set-UID programs. What will happen if they are not? If you are not familiar with these programs, you should first learn what they can do by reading their manuals.

2) Run Set-UID shell programs in Linux, and describe and explain your observations. • Login as root, copy /bin/zsh to /tmp, and make it a set-root-uid program with permission 4755. Then login as a normal user, and run /tmp/zsh. Will you get root privilege? Please describe your observation. If you cannot find /bin/zsh in your operating system, please use the following command to install it:

• Instead of copying /bin/zsh, this time, copy /bin/bash to /tmp, make it a set-root-uid program. Run /tmp/bash as a normal user. will you get root privilege? Please describe and explain your observation.

3) (Setup for the rest of the tasks) As you can find out from the previous task, /bin/bash has certain built-in protection that prevent the abuse of the Set-UID mechanism. To see the life before such a protection scheme was implemented, we are going to use a different shell program called /bin/zsh. In Fedora, /bin/sh is actually a symbolic link to /bin/bash. To use zsh, we need to link /bin/sh to /bin/zsh. The following instructions describe how to change the default shell to zsh.

4) The PATH environment variable.
The system(const char *cmd) library function can be used to execute a command within a program. The way system(cmd) works is to invoke the /bin/sh program, and then let the shell program to execute cmd. Because of the shell program invoked, calling system() within a Set-UID program is extremely dangerous. This is because the actual behavior of the shell program can be affected by environment variables, such as PATH; these environment variables are under user’s control. By changing these variables, malicious users can control the behavior of the Set-UID program.

The Set-UID program below is supposed to execute the /bin/ls command; however, the programmer only uses the relative path for the ls command, rather than the absolute path:

• Can you let this Set-UID program (owned by root) run your code instead of /bin/ls? If you can, is your code running with the root privilege? Describe and explain your observations.

• (b) Now, change /bin/sh so it points back to /bin/bash, and repeat the above attack. Can you still get the root privilege? Describe and explain your observations.

5) The difference between system() and execve().
a. Before you work on this task,please make sure that /bin/sh is pointed to /bin/zsh.

Background: Eyal works for an auditing agency, and he needs to investigate a company for a suspected fraud. For the investigation purpose, Eyal needs to be able to read all the files in the company’s Unix system; on the other hand, to protect the integrity of the system, Eyal should not be able to modify any file. To achieve this goal, Ron, the superuser of the system, wrote a special...
tracking img