exec_victim.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc, char** argv, const char** envp) {
  4. FILE* out = stdout;
  5. if (argc > 1) {
  6. int fd = atoi(argv[argc - 1]);
  7. printf("inherited file descriptor %d\n", fd);
  8. out = fdopen(fd, "a");
  9. if (!out) {
  10. perror("fdopen");
  11. exit(1);
  12. }
  13. }
  14. fprintf(out, "Hello World (%s)!\n", argv[0]);
  15. fprintf(out, "envp[\'IN_EXECVE\'] = %s\n", getenv("IN_EXECVE"));
  16. fprintf(
  17. out,
  18. "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  19. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  20. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  21. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  22. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  23. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  24. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  25. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  26. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  27. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  28. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  29. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  30. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  31. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  32. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  33. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  34. \n");
  35. return 0;
  36. }