exec_victim.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #define _XOPEN_SOURCE 700
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int main(int argc, char** argv, const char** envp) {
  5. FILE* out = stdout;
  6. if (argc > 1) {
  7. int fd = atoi(argv[argc - 1]);
  8. printf("inherited file descriptor %d\n", fd);
  9. out = fdopen(fd, "a");
  10. if (!out) {
  11. perror("fdopen");
  12. exit(1);
  13. }
  14. }
  15. fprintf(out, "Hello World (%s)!\n", argv[0]);
  16. fprintf(out, "envp[\'IN_EXECVE\'] = %s\n", getenv("IN_EXECVE"));
  17. fprintf(
  18. out,
  19. "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  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. 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \
  35. \n");
  36. return 0;
  37. }