468,727 Members | 1,467 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

execve problem???

HI there...
I compile the following code(as root) and sets the setuid bit...
as it gives a shell to any user but when the setuid bit is set the
shell should have the privileges of root but in my case it doesn't
have those privileges. I'm using redhat 7.1

#include<stdio.h>
#include<unistd.h>

int main()
{
char *file[2];
file[0]="/bin/sh";
file[1]=NULL;
execve(file[0],file ,NULL);

return 0;
}

Thanks!
Nov 13 '05 #1
3 2670
Java Boy wrote:
HI there...
I compile the following code(as root) and sets the setuid bit...
as it gives a shell to any user but when the setuid bit is set the
shell should have the privileges of root but in my case it doesn't
have those privileges. I'm using redhat 7.1
Unfortunately, this has nothing to do with standard C -- making it off
topic on news:comp.lang.c.

#include<stdio.h>
#include<unistd.h>

int main()
{
char *file[2];
file[0]="/bin/sh";
file[1]=NULL;
execve(file[0],file ,NULL);

return 0;
}


This should be asked in news:comp.os.linux.development.apps.

When you have a question about standard C, come on back (but read the
FAQs first).
HTH,
--ag
--
Artie Gold -- Austin, Texas

Nov 13 '05 #2
In 'comp.lang.c', "Ema" <pa*****@supereva.it> wrote:
Don't know the solution to the problem you posted, but I found following
mistakes:
#include<stdio.h>
#include<unistd.h>
#include <stdlib.h>

int main()
{
char *file[2];


file[0]="/bin/sh"; /* NOOO! */
Why not? How is the 1st parameter of execve() defined? Does it has to point
to a modifiable string?
file[0] = malloc(8);
sprintf(file[0],"/bin/sh");

file[1]=NULL;
execve(file[0],file ,NULL);


If you insist in using malloc(), you also must use free().
return 0;
}


--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #3
On 6 Aug 2003 17:44:50 -0700, Java Boy <ja*****@zapo.net> wrote:
I compile the following code(as root) and sets the setuid bit...
as it gives a shell to any user but when the setuid bit is set the
shell should have the privileges of root but in my case it doesn't


Is the executable owned by root? SUID makes the program run as the
owner of the file, which is not necessarily root.

This probably isn't a good question for comp.lang.c, as it is not a
general C question.
--
-| Bob Hauck
-| To Whom You Are Speaking
-| http://www.haucks.org/
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

117 posts views Thread by Peter Olcott | last post: by
28 posts views Thread by Jon Davis | last post: by
6 posts views Thread by Ammar | last post: by
2 posts views Thread by goodnamesalltaken | last post: by
reply views Thread by glmlima | last post: by
4 posts views Thread by neojia | last post: by
2 posts views Thread by scoobydoo666 | last post: by
1 post views Thread by yogamatt1970 | last post: by
1 post views Thread by CARIGAR | last post: by
9 posts views Thread by bryonone | last post: by
xarzu
1 post views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.