Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You should be able to observe two different behaviours in the scenarios described above, even though you are running the same program. Note the different

You should be able to observe two different behaviours in the scenarios described above, even though you are running the same program. Note the different behaviours of the 4 programs here?
Explain why the behaviours in the four different programs in Step 2 are different.
image text in transcribed

Step 1. First, we will see how these environment variables influence the behaviour of dynamic loader/linker when running a normal program. Please follow these steps:

1. We will now build a dynamic link library. Create the program as shown in Code Listing 6, and name it mylib.c.

If we run a program that uses our dynamically linked library it will override the default sleep() function in libc and print our text out instead:

#include stdio.h>

void sleep (int s)

{

/* If this is invoked by a privileged program, you can do damage here! */ printf("I am not sleeping! "); }

Code Listing 6: Dynamic library - sleep() call

2. We can compile the above program using the following commands (in the -lc argument, the second character is a lower case L not a 1/one):

$ gcc -fPIC -g -c mylib.c

$ gcc -shared -o libmylib.so.1.0.1 mylib.o -lc

3. Now, set the LD PRELOAD environment variable so that the system knows about out dynamic link library:

$ export LD_PRELOAD=./libmylib.so.1.0.1

4. Finally, compile the program in Code Listing 7 and call it task8.c. Ensure that it is in the same directory as the above dynamic link library libmylib.so.1.0.1:

/* task8.c */

int main()

{ sleep(1); return 0;

}

Code Listing 7: Program to invoke sleep() system call.

5. Make four copies of the executable. Call them task8-a, task8-b, task8-c, and task8-d

Step 2. After you have done the above, please run the task8 executables under the following conditions, and observe what happens. (NOTE: pay close attention to the instructions!). If the program picks up our dynamic library, it should print our text. If it uses the default system sleep() library, then it will sleep for 1 second and return the CLI prompt without printing anything.

1. Leave task8-a as normal program and run it as the normal uwe user.

2. Change task8-b so that it is a root owned, Set-UIDprogram (Use chown and chmod), and run it as the uweuser.

3. Change task8-c so that it is a ubuntu owned, Set-UIDprogram. (ubuntu is another user that is already present in this VM). Run this program as the uwe user.

4. Change task8-d so that it is a root owned, Set-UIDprogram. Change the shell to the root account using the command sudo su. We are now running this program as the root user in the root account.

Export the LD_PRELOAD environment variable again in the root account and run the task8-d program.

image text in transcribed
Environment Variable & SET-UID Lab v1.0 Question: You should be able to observe two different behaviours in the scenarios described above, even though you are running the same program. Note the different behaviours of the 4 programs here. Step 3. Explain why the behaviours in the four different programs in Step 2 are different. Environment Variable & SET-UID Lab v1.0 Question: You should be able to observe two different behaviours in the scenarios described above, even though you are running the same program. Note the different behaviours of the 4 programs here. Step 3. Explain why the behaviours in the four different programs in Step 2 are different

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions