During execution ofthecommand, SIGCHLDwillbeblocked, andSIGINT and SIGQUIT will be ignored, intheprocess that calls system(). (These signals will be handled according to their defaults inside the child process that executes command.)
If commandisNULL, thensystem() returnsastatusindicatingwhethera shell is available onthesystem.
[10/31/22]seed@VM:~/lab/Labsetup$ sudo chown root ls [10/31/22]seed@VM:~/lab/Labsetup$ sudo chmod 4755 ls [10/31/22]seed@VM:~/lab/Labsetup$ ll ls -rwsr-xr-x 1 root seed 16696 Oct 31 04:22 ls
Make myprog a Set-UID root program, export the LD PRELOAD environment variable again in the root account and run it
1 2 3 4
root@VM:/home/seed/lab/Labsetup# export LD_PRELOAD="/home/seed/lab/Labsetup/libmylib.so.1.0.1" root@VM:/home/seed/lab/Labsetup# ./myprog LD_PRELOAD=/home/seed/lab/Labsetup/libmylib.so.1.0.1 I am not sleeping!
Make myprog a Set-UID user1 program (i.e., the owner is user1, which is another user account),export the LD PRELOAD environment variable again in a different user’s account (not-root user) and run it.
和Make myprog a regular program, and run it as a normal user.结果相同
Task 8: Invoking External Programs Using system() versus execve()
[10/31/22]seed@VM:~/lab/Labsetup$ a.out "catall.c;/bin/sh" /bin/cat:'catall.c;/bin/sh': No such file or directory
Task 9: Capability Leaking
The setuid() system call can be used to revoke the privileges. According to the manual, “setuid() sets the effective user ID of the calling process. If the effective UID of the caller is root, the real UID and saved set-user-ID are also set”. Therefore, if a Set-UID program with effective UID 0 calls setuid(n), the process will become a normal process, with all its UIDs being set to n
/* Assume that /etc/zzz is an important system file, * and it is owned by root with permission 0644. * Before running this program, you should create * the file /etc/zzz first. */ fd = open("/etc/zzz", O_RDWR | O_APPEND); if (fd == -1) { printf("Cannot open /etc/zzz\n"); exit(0); }
// Print out the file descriptor value printf("fd is %d\n", fd);
// Permanently disable the privilege by making the // effective uid the same as the real uid setuid(getuid());