niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » *nix » Linux » security
access root privileges through C program
Post new topic   Reply to topic Page 1 of 1 [10 Posts] View previous topic :: View next topic
Author Message
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Mon Jul 17, 2006 3:43 am    Post subject: Re: access root privileges through C program Reply with quote

Unruh <unruh-spam@physics.ubc.ca> (06-07-16 22:30:26):

Quote:
However, you can write a program with special permissions ( which only
root can give it called suid) which can have root privs when it starts
up. If you ever give them up in that program you cannot get them back.

Actually it can. The program can somehow reclaim root privileges, if it
had them before, but I don't know how exactly. I think, it had to do
with Linux caps.


Regards,
E.S.
Back to top
Unruh
*nix forums Guru


Joined: 22 Mar 2005
Posts: 1166

PostPosted: Sun Jul 16, 2006 10:30 pm    Post subject: Re: access root privileges through C program Reply with quote

Colin McKinnon <colin.thisisnotmysurname@ntlworld.deletemeunlessURaBot.com> writes:

Quote:
motet520 wrote:

i know with privileges rise from linux tool with uselib24.c and,
hatrorihan20.c(this case is not accuratery) etc. It cannot do well
English it will be ruined long.


I agree that the English is rather confusing.

You CANNOT use a C program to switch to root privs. If y ou could the root
privs would be totally useless. Anyone could write a program to give
themselves root.
However, you can write a program with special permissions ( which only root
can give it called suid) which can have root privs
when it starts up. If you ever give them up in that program you cannot get
them back.

Quote:
Yoda, be not swayed by the dark side - use the force you must. motet520
seeks to tempt you with exploits. Read
http://www.unixpapa.com/incnote/setuid.html and acheive enlightnment.

C.
Back to top
Colin McKinnon
*nix forums Guru


Joined: 19 Feb 2005
Posts: 410

PostPosted: Sun Jul 16, 2006 9:59 pm    Post subject: Re: access root privileges through C program Reply with quote

motet520 wrote:

Quote:
i know with privileges rise from linux tool with uselib24.c and,
hatrorihan20.c(this case is not accuratery) etc. It cannot do well
English it will be ruined long.


Yoda, be not swayed by the dark side - use the force you must. motet520
seeks to tempt you with exploits. Read
http://www.unixpapa.com/incnote/setuid.html and acheive enlightnment.

C.
Back to top
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Sat Jul 15, 2006 9:09 am    Post subject: Re: access root privileges through C program Reply with quote

Unruh <unruh-spam@physics.ubc.ca> (06-07-15 06:12:32):

Quote:
You should make the program owned by root and have the setuid bit
on. The code is then able to change its effective UID between the
user and root with the seteuid() system call.

No you shouldn't, because programs SUID to root could possibly harm
system security. If you're good at writing perfectly secure code,
then that's not much of a problem, but otherwise I'd suggest using
'sudo' from your program instead. Don't use the SUID bit, where not
necessary.

In fact that can be much less secure. With suid the program can give up
root priv when no longer needed. Once it has given up root, you cannot get
it back however.
Under sudo, the program always runs as root, meaning any bugs are running
as root.
Ie, suid root is more secure than sudo on that same program.

Sure, but as long as you call those programs with a fixed command line,
nothing can happen. Otherweise being logged in as root somewhere would
be a security hazard.

And the code, which is run (like lsmod, ls, cat, ...) is well known and
tested. New code is always potentially buggy. You have to parse
command line options and open files before giving up root privileges.
There is enough room for a security risk.


Regards,
E.S.
Back to top
Unruh
*nix forums Guru


Joined: 22 Mar 2005
Posts: 1166

PostPosted: Sat Jul 15, 2006 6:12 am    Post subject: Re: access root privileges through C program Reply with quote

Ertugrul Soeylemez <never@drwxr-xr-x.org> writes:

Quote:
Tauno Voipio <tauno.voipio@iki.fi.NOSPAM.invalid> (06-07-14 20:24:22):

hi
i want to develop a program in C with gtk frontend , which is run
under normal user privilges and want to have root privileges and i
want to run some commands like lsmod etc. After finishing up the
commands processing like lsmod i want come back to normal privileges
program. I want to restore the user privileges to the program. How
to implement it? please help me. mail me to yoda.techies@gmail.com

You should make the program owned by root and have the setuid bit on.
The code is then able to change its effective UID between the user and
root with the seteuid() system call.

No you shouldn't, because programs SUID to root could possibly harm
system security. If you're good at writing perfectly secure code, then
that's not much of a problem, but otherwise I'd suggest using 'sudo'
from your program instead. Don't use the SUID bit, where not necessary.

In fact that can be much less secure. With suid the program can give up
root priv when no longer needed. Once it has given up root, you cannot get
it back however.
Under sudo, the program always runs as root, meaning any bugs are running
as root.
Ie, suid root is more secure than sudo on that same program.




Quote:
Regards,
E.S.
Back to top
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Sat Jul 15, 2006 5:36 am    Post subject: Re: access root privileges through C program Reply with quote

Tauno Voipio <tauno.voipio@iki.fi.NOSPAM.invalid> (06-07-14 20:24:22):

Quote:
hi
i want to develop a program in C with gtk frontend , which is run
under normal user privilges and want to have root privileges and i
want to run some commands like lsmod etc. After finishing up the
commands processing like lsmod i want come back to normal privileges
program. I want to restore the user privileges to the program. How
to implement it? please help me. mail me to yoda.techies@gmail.com

You should make the program owned by root and have the setuid bit on.
The code is then able to change its effective UID between the user and
root with the seteuid() system call.

No you shouldn't, because programs SUID to root could possibly harm
system security. If you're good at writing perfectly secure code, then
that's not much of a problem, but otherwise I'd suggest using 'sudo'
from your program instead. Don't use the SUID bit, where not necessary.


Regards,
E.S.
Back to top
Tauno Voipio
*nix forums Guru


Joined: 14 Mar 2005
Posts: 678

PostPosted: Fri Jul 14, 2006 8:24 pm    Post subject: Re: access root privileges through C program Reply with quote

yoda.techies@gmail.com wrote:
Quote:
hi
i want to develop a program in C with gtk frontend , which is run
under normal user privilges and want to have root privileges and i want
to run some commands like lsmod etc. After finishing up the commands
processing like lsmod i want come back to normal privileges program. I
want to restore the user privileges to the program. How to implement
it? please help me.
mail me to yoda.techies@gmail.com


You should make the program owned by root and have the setuid bit on.
The code is then able to change its effective UID between the user
and root with the seteuid() system call.

For module listing, you do not need root privileges, it suffices to open
and read the file /proc/modules. For testing, just do

cat /proc/modules

--

Tauno Voipio
tauno voipio (at) iki fi
Back to top
motet520
*nix forums beginner


Joined: 14 Jul 2006
Posts: 2

PostPosted: Fri Jul 14, 2006 3:30 pm    Post subject: Re: access root privileges through C program Reply with quote

i am sorry . hatrorihan20.c no --> hatorihazo.c right ^____^
motet520 작성:

Quote:
i know with privileges rise from linux tool with uselib24.c and,
hatrorihan20.c(this case is not accuratery) etc. It cannot do well
English it will be ruined long.

thank you.

yoda.techies@gmail.com 작성:

hi
i want to develop a program in C with gtk frontend , which is run
under normal user privilges and want to have root privileges and i want
to run some commands like lsmod etc. After finishing up the commands
processing like lsmod i want come back to normal privileges program. I
want to restore the user privileges to the program. How to implement
it? please help me.
mail me to yoda.techies@gmail.com

thanks in advance
Back to top
motet520
*nix forums beginner


Joined: 14 Jul 2006
Posts: 2

PostPosted: Fri Jul 14, 2006 3:28 pm    Post subject: Re: access root privileges through C program Reply with quote

i know with privileges rise from linux tool with uselib24.c and,
hatrorihan20.c(this case is not accuratery) etc. It cannot do well
English it will be ruined long.

thank you.

yoda.techies@gmail.com 작성:

Quote:
hi
i want to develop a program in C with gtk frontend , which is run
under normal user privilges and want to have root privileges and i want
to run some commands like lsmod etc. After finishing up the commands
processing like lsmod i want come back to normal privileges program. I
want to restore the user privileges to the program. How to implement
it? please help me.
mail me to yoda.techies@gmail.com

thanks in advance
Back to top
yoda.techies@gmail.com
*nix forums beginner


Joined: 14 Jul 2006
Posts: 2

PostPosted: Fri Jul 14, 2006 12:12 pm    Post subject: access root privileges through C program Reply with quote

hi
i want to develop a program in C with gtk frontend , which is run
under normal user privilges and want to have root privileges and i want
to run some commands like lsmod etc. After finishing up the commands
processing like lsmod i want come back to normal privileges program. I
want to restore the user privileges to the program. How to implement
it? please help me.
mail me to yoda.techies@gmail.com

thanks in advance
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [10 Posts] View previous topic :: View next topic
The time now is Fri Nov 21, 2008 1:55 pm | All times are GMT
navigation Forum index » *nix » Linux » security
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts [554] Relay access denied annami Postfix 0 Tue Oct 21, 2008 9:12 am
No new posts [554] Relay access denied annami Postfix 0 Tue Oct 21, 2008 9:11 am
No new posts [554] Relay access denied annami Postfix 0 Tue Oct 21, 2008 9:10 am
No new posts can u solve this program :P bawen C++ 0 Mon Jul 24, 2006 6:26 pm
No new posts Need Help with Program in Perl on a Netware Server fhadzocos@gmail.com Perl 3 Fri Jul 21, 2006 1:57 pm

Online Advertising | Credit Cards UK | Mortgages | Loans | Credit Counseling
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3873s ][ Queries: 20 (0.2838s) ][ GZIP on - Debug on ]