Skip to content

Instantly share code, notes, and snippets.

@vvoody
Created May 16, 2012 21:41
Show Gist options
  • Save vvoody/2714182 to your computer and use it in GitHub Desktop.
Save vvoody/2714182 to your computer and use it in GitHub Desktop.
/*
* wrapper of running shell script as given user
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "one argument required! script name(full path).\n");
return 1;
}
int ret;
char * script = argv[1];
ret = setuid(1001);
printf("ret: %d\n", ret);
printf("getuid: %d, geteuid: %d\n", getuid(), geteuid());
/* char *newenvp[] = { NULL }; */
/* char *newargv[] = { script, NULL }; */
/* execve(script, newargv, newenvp); */
/* perror("execve"); */
ret = execl("/usr/bin/bash", "/usr/bin/bash", script, (char *)0);
printf("ret: %d", ret);
return 0;
}
#!/bin/sh
date
whoami
sleep 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment