execve problem???

J

Java Boy

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!
 
A

Artie Gold

Java said:
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
#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
When you have a question about standard C, come on back (but read the
FAQs first).


HTH,
--ag
 
E

Emmanuel Delahaye

Ema said:
Don't know the solution to the problem you posted, but I found following
mistakes:
#include<stdio.h>
#include<unistd.h>

#include said:
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().
 
B

Bob Hauck

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top