So this was the project that I received and I'm stuck half way.
In most Linux distributions (Fedora and Ubuntu included),
/bin/shis actually a symbolic link to/bin/bash. To use zsh, we need to link/bin/shto/bin/zsh. The following instructions describe how to change the default shell to zsh:
- login as root
cd /binrm shln –s zsh shThe
system(const char *cmd)library function can be used to execute a command within a program. The waysystem(cmd)works is to invoke the/bin/shprogram, and then let the shell program to executecmd. Because of the shell program invoked, callingsystem()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 asPATH; 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/lscommand; however, the programmer only uses the relative path for the ls command, rather than the absolute path:int main() { system("ls"); return 0; }Login as root, write this program into a file named
bad_ls.c, compile it (usinggcc –o bad_ls bad_ls.c) and copy the executable as a Set-UID program into/tmpwith permissions 4755.Is it a good idea to let regular users execute the
/tmp/bad_lsprogram (owned by root) instead of/bin/ls? Describe an attack by which a regular user can manipulate thePATHenvironment variable in order to read the/etc/shadowfile.
I have successfully changed the default shell to zsh, created the executable bad_ls, and copied it to /tmp with permission ID 4755.
Describe an attack by which a regular user can manipulate the
PATHenvironment variable in order to read the/etc/shadowfile.
This is where I'm stuck.
After running the bad_ls file, I change the PATH env Variable to point to the current directory by using the code
export PATH =.:$PATH
If I run ls -a /etc/shadow, all I get is this: /etc/shadow
I would be really thankful if you could guide me in this problem.