Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <unistd.h>
  6. #include <fcntl.h>
  7. #include <stdint.h>
  8. #include <inttypes.h>
  9. #include <sys/wait.h>
  10. #include <linux/limits.h>
  11. #include <time.h>
  12.  
  13. extern char **environ;
  14.  
  15. char *tmp_path (void)
  16. {
  17.     char *x;
  18.     const char *default_dir = "/tmp";
  19.     if (!(x = getenv("XDG_RUNTIME_DIR"))) {
  20.         if (!(x = getenv("TMPDIR"))) {
  21.             return (char *)default_dir;
  22.         } else {
  23.             return x;
  24.         }
  25.     } else {
  26.         return x;
  27.     }
  28. }
  29.  
  30. int main(int argc, char *argv[])
  31. {
  32.     pid_t pid;
  33.     char *x;
  34.     int status;
  35.     char path[PATH_MAX], execfile[PATH_MAX], fname[PATH_MAX];
  36.     snprintf(path,PATH_MAX,"%s",tmp_path());
  37.     printf("%s\n",path);
  38.     pid = getpid();
  39.     snprintf(fname,PATH_MAX,"%s/_tmp_%d_.py",path,pid);
  40.     snprintf(execfile,PATH_MAX,"%s/_tmp_%d_.py",path,pid);
  41.     printf("%s\n",fname);
  42.     fflush(stdout);
  43.     int fd = open(fname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC,0700);
  44.     if (fd == -1) {
  45.         exit(1);
  46.     }
  47.     //printf("OK");
  48.     fflush(stdout);
  49.     dup2(fd,1);
  50.     close(fd);
  51.     printf("#!/bin/bash\n#!/usr/bin/env python\nprint(");
  52.     for (int i = 1; i < argc - 1; i++) {
  53.         printf("%s*",argv[i]);
  54.     }
  55.     printf("%s)",argv[argc - 1]);
  56.     fflush(stdout);
  57.     execl("/bin/bash", "bash", "-c", execfile, NULL);
  58.     return 1;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement