Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <string.h>
  3.  
  4. int
  5. main(int argc, char *argv[])
  6. {
  7. int fd[2];
  8.  
  9. char *s = "ls -1 \"/usr/bin\" | while IFS= read -r fp\ndo\ncat <<- EOF\n\t$fp\nEOF\ndone;";
  10. //char *s = "ls -1";
  11.  
  12.  
  13. pipe(fd);
  14.  
  15. switch(fork()) {
  16. case 0:
  17. close(fd[1]);
  18. dup2(fd[0], 0);
  19. execl("/bin/sh", "sh", NULL);
  20. close(fd[0]);
  21. break;
  22. default:
  23. close(fd[0]);
  24. write(fd[1], s, strlen(s) + 1);
  25. close(fd[1]);
  26. break;
  27. }
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement