Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE DO ALL TASKS THANK YOU Files needed for this lab are included in Labsetup.zip. To download the lab files to your CloudLab machine, run

"PLEASE DO ALL TASKS"

THANK YOU

image text in transcribedimage text in transcribedimage text in transcribed

Files needed for this lab are included in Labsetup.zip. To download the lab files to your CloudLab machine, run the followings: mkdir setuid_lab cd setuid_lab wget https://seedsecuritylabs.org/Labs_20.04/Files/Environment_Variable_and_SetUID/Labs unzip Labsetup.zip cd Labsetup Task 1: Manipulating Environment Variables In this task, we study the commands that can be used to set and unset environment variables. We are using Bash in the seed account. The default shell that a user uses is set in the /etc/passwd file (the last field of each entry). You can change this to another shell program using the command chsh (please do not do it for this lab). Please do the following tasks: - Use printenv or env command to print out the environment variables. If you are interested in some particular environment variables, such as PWD, you can use printenv PWD or env I grep PWD. - Use export and unset to set or unset environment variables. It should be noted that these two commands are not separate programs; they are two of the Bash's internal commands (you will not be able to find them outside of Bash). Task 2: Passing Environment Variables from Parent Process to Child Process In this task, we study how a child process gets its environment variables from its parent. In Unix, fork ( ) creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent; however, several things are not inherited by the child (please see the manual of fork () by typing the following command: man fork). In this task, we would like to know whether the parent's environment variables are inherited by the child process or not. - Step 1. Please compile and run the following program, and describe your observation. The program can be found in the Labsetup folder; it can be compiled using gcc myprintenv. c, which will generate a binary called a.out. Let's run it and save the output into a file using a. out > file. - Step 2. Now comment out the printenv ( ) statement in the child process case (Line 1), and uncomment the printenv() statement in the parent process case (Line 2). Compile and run the code again, and describe your observation. Save the output in another file. - Step 3. Compare the difference of these two files using the diff command. Please draw your conclusion. Task 3: Environment Variables and execve() In this task, we study how environment variables are affected when a new program is executed via execve ( ). The function execve ( ) calls a system call to load a new command and execute it; this function never returns. No new process is created; instead, the calling process's text, data, bss, and stack are overwritten by that of the program loaded. Essentially, execve () runs the new program inside the calling process. We are interested in what happens to the environment variables; are they automatically inherited by the new program? - Step 1. Please compile and run the myenv. c program, and describe your observation. This program simply executes a program called /usr/bin/env, which prints out the environment variables of the current process. \#include extern char **environ; int main() char argv [2]; argv 0]= "/usr/bin/env"; argv[1] = NULL; execve("/usr/bin/env", argv, NULL); // Line 1 return 0; \} - Step 2. Change the invocation of execve( ) in Line 1 to the following; describe your observation: execve("/usr/bin/env", argv, environ); - Step 3. Please draw your conclusion regarding how the new program gets its environment variables

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions