exec_victim.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. int main(int argc, char ** argv, const char ** envp)
  6. {
  7. FILE * out = stdout;
  8. if (argc > 1) {
  9. int fd = atoi(argv[argc - 1]);
  10. printf("inherited file descriptor %d\n", fd);
  11. out = fdopen(fd, "a");
  12. if (!out) {
  13. perror("fdopen");
  14. exit(1);
  15. }
  16. }
  17. fprintf(out, "Hello World (%s)!\n", argv[0]);
  18. fprintf(out, "envp[\'IN_EXECVE\'] = %s\n", getenv("IN_EXECVE"));
  19. fprintf(out, "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. }