runscriptasroot.c 300 B

123456789101112131415161718192021
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. int main(int argc, char** argv)
  6. {
  7. if (argc != 2) {
  8. exit(-1);
  9. }
  10. setuid(0);
  11. pid_t pid = fork();
  12. if ( pid == 0 ) {
  13. // execute command in child
  14. return system(argv[1]);
  15. }
  16. return 0;
  17. }