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.
lsvia asystemcall is a bad idea. What is special aboutls? – steeldriver Oct 16 '16 at 19:56PATHis used by the shell when you execute a command such asls. Also have a read of theNOTESsection of thesystemmanual page (man 3 system). – steeldriver Oct 16 '16 at 21:33bashas default shell (via symlink tosh) for 10 years (!). The last version where thas was the case was 6.06. Instead Ubuntu, as well as Debian and most of their derivatives, usedash. Also, you should not - ever - change the default shell (i.e./bin/sh, be it a symlink or even binary) unless you know exactly what that entails. Packages, daemons, etc. may depend on/bin/shbehaving in a certain way, where the replacement may do things differently. – Adaephon Oct 18 '16 at 13:08/etc/shadowwhile being logged in as normal user (On terminal of course). All I know is that when you use the terminal as a normal user, you run the/tmp/bad_lsand use PATH env variable to point to a directory such that when you run thebad_lsfile, you will be given root privileges and you will then be able to read the/etc/shadowfile as a normal user. Please reply with a solution ASAP, I've hardly got any time to submit it. – Data Shark Oct 18 '16 at 17:14