LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 11-20-2013, 06:42 AM   #1
goldengriff
LQ Newbie
 
Registered: Nov 2013
Posts: 14

Rep: Reputation: Disabled
Question Can you let this Set-UID program (owned by root) run??


hi dear's,
The system(const char *cmd) library function can be used to execute a command within a program. The way system(cmd) works is to invoke the /bin/sh program, and then let the shell program to execute cmd. Because of the shell program invoked, calling system() 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 as PATH; 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/ls command; however, the programmer only uses the relative path for the ls command, rather than the absolute path:
int main()
{
system("ls");
return 0;
}
Can you let this Set-UID program (owned by root) run your code instead of /bin/ls? If you can, is your code running with the root privilege?
thanks
 
Old 11-20-2013, 07:10 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
You can, it is, that is unsafe. Actually some shells drop an euid if different from ruid but you don't want to rely on that.

Code:
int main()
{
execl("/bin/ls", "ls", (char *)0);
return 0;
}

Last edited by linosaurusroot; 11-20-2013 at 07:12 AM.
 
1 members found this post helpful.
Old 11-20-2013, 07:15 AM   #3
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,334

Rep: Reputation: Disabled
If you have a specific question about your assignment (page 2, lab task 4), that's fine, but don't expect others to do your homework for you.
 
1 members found this post helpful.
Old 11-20-2013, 07:16 AM   #4
goldengriff
LQ Newbie
 
Registered: Nov 2013
Posts: 14

Original Poster
Rep: Reputation: Disabled
dear linosaurusroot,
i run ur code, but below error showed:
tcnewcode.c: In function ‘main’:
tcnewcode.c:6:1: warning: incompatible implicit declaration of built-in function ‘execl’ [enabled by default]
why??
your complete code is:
Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
execl("/bin/ls", "ls", (char *)0);
return 0;
}
 
Old 11-20-2013, 03:39 PM   #5
widget
Senior Member
 
Registered: Oct 2008
Location: S.E. Montana
Distribution: Debian Testing, Stable, Sid and Manjaro, Mageia 3, LMDE
Posts: 2,628

Rep: Reputation: 497Reputation: 497Reputation: 497Reputation: 497Reputation: 497
There are many people on this forum to whom English is not their native language. This is an English language forum.

Try to use English so that people can have a chance to understand what you are trying to get across to them rather than look like u r dumb.
 
Old 11-20-2013, 07:54 PM   #6
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by goldengriff View Post
dear linosaurusroot,
i run ur code, but below error showed:
tcnewcode.c: In function ‘main’:
tcnewcode.c:6:1: warning: incompatible implicit declaration of built-in function ‘execl’ [enabled by default]
why??
your complete code is:
Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
execl("/bin/ls", "ls", (char *)0);
return 0;
}

"man execl" tells you to use "#include <unistd.h>" ... it is good to check man pages before asking here.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
run set-uid shell program in ubuntu and set premission 4755 goldengriff Ubuntu 12 11-20-2013 02:51 AM
setuid program owned by non-root user hmadhi Linux - Security 4 11-22-2011 01:33 AM
How can I have a script owned as root and run as root by a user: setuid? stickey bit? abefroman Linux - Newbie 9 04-19-2008 05:15 PM
Using Set UID to run script as root robo555 Linux - Software 3 11-23-2007 12:05 AM
login run from root-owned xterm garba Linux - Security 2 07-23-2005 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 04:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration