I'm trying to write a program that run /bin/bash with user smith privileges,
smith:x:1000:1000:Basket:/home/smith:/bin/bash
I tried this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
setgid(1000);
setuid(1000);
char command[50];
strcpy( command, "/bin/bash" );
system(command);
return(0);
}
and I used those command to set the owner, group, and the permissions
chown smith command
chgrp smith command
chmod +x command
chmod u+s command
the permissions after the commands:
-rwsr-xr-x 1 smith smith 16840 Jun 6 17:11 command
and didn't work, I tried with root as next:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
setgid(0);
setuid(0);
char command[50];
strcpy( command, "/bin/bash" );
system(command);
return(0);
}
and I used the same commands for permissions and so on but instead of smith, I wrote root and I worked and when I run it I'm getting a shell as root.
So how I can do it with a smith user?