Advertisement
metalx1000

Android Moto G Root Telnet

Jul 19th, 2015
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.00 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. img=boot.img
  4. img2=boot2.img
  5. port=9999
  6.  
  7. url="https://github.com/metalx1000/Moto-G-root-tricks/blob/master/img/stock_boot.img?raw=true"
  8. dir="work"
  9.  
  10. #check if root user
  11. if [[ $EUID -ne 0 ]]; then
  12.   echo "You must be a root user"
  13.   echo "Trying to restart script as sudo"
  14.   sudo $0 $@
  15.   exit
  16. fi
  17.  
  18. echo "Removing any previous work..."
  19. rm -fr $dir
  20.  
  21. mkdir $dir
  22.  
  23. if [ "$1" = "remote" ]
  24. then
  25.   cat << EOM
  26.     Warning!!!
  27.     This is not safe!
  28.     By using 'remote' option you
  29.     are granting root access to
  30.     anyone on your network
  31. EOM
  32.   sleep 2
  33.   access=""
  34. else
  35.   access="-b 127.0.0.1"
  36. fi
  37.  
  38.  
  39. #check for needed programs
  40. if [ ! -f "/usr/bin/abootimg" ] || [ ! -f "/usr/bin/fastboot" ] || [ ! -f "/usr/bin/adb" ]
  41. then
  42.   apt-get install abootimg android-tools-fastboot android-tools-adb -y
  43. fi
  44.  
  45. #get stock boot img
  46. wget -c "$url" -O "$dir/$img"
  47.  
  48. cd $dir
  49. #unpack stock boot img
  50. file $img
  51. #head -n1 $img
  52. mkdir boot
  53. cd boot
  54.  
  55. abootimg -x ../$img
  56. file initrd.img
  57.  
  58. echo "updating bootimg.cfg"
  59. rm bootimg.cfg
  60. wget "https://raw.githubusercontent.com/metalx1000/Moto-G-root-tricks/master/config/bootimg.cfg"
  61.  
  62. mkdir ramdisk
  63. cd ramdisk
  64. gunzip -c ../initrd.img | cpio -i
  65.  
  66. echo "Adding Service to Startup..."
  67. cat << EOF >> init.rc
  68.  
  69. service init_my /init_my.sh
  70.     class main
  71.     user root
  72.     group root
  73.     oneshot
  74.  
  75. EOF
  76.  
  77. echo "Creating Custom init Script..."
  78. cat << EOS >> init_my.sh
  79. #!/system/bin/sh
  80. echo "loading..."
  81. sleep 30
  82. #/system/bin/busybox telnetd -p $port -l /system/bin/sh $access
  83. /sbin/busybox telnetd -p $port -l /system/bin/sh $access
  84.  
  85. EOS
  86. chmod 777 init_my.sh
  87.  
  88. cat << DEB > sbin/debian
  89. #!/system/bin/sh
  90. #mounts and chroots debian system on Android
  91. #might need to create loop
  92. #busybox mknod /dev/loop0 b 7 0
  93. #busybox mknod -m640 /dev/block/loop255 b 7 255
  94.  
  95. #to install this script you need to make system RW
  96. #mmcblk0p5 might change so check 'mount' command
  97. #mount -o remount,rw /dev/block/mmcblk0p5 /system
  98. #on Lollipop run this to stop ld.so ERROR  -- unset LD_PRELOAD
  99. dir=/storage/sdcard1/
  100. chroot=\${dir}debian
  101. img=\${dir}debian_arm.img
  102.  
  103. mounts () {
  104.   mount -o loop -t ext4 \$img \$chroot
  105.   busybox mount --bind /dev \$chroot/dev
  106.   busybox mount --bind /dev/pts \$chroot/dev/pts
  107.   busybox mount -t proc proc \$chroot/proc
  108.   busybox mount -t sysfs sysfs \$chroot/sys
  109. }
  110.  
  111. mount|grep "\$chroot"&&echo "Already Mounted"|| mounts
  112.  
  113. export PATH=\$bin:/usr/bin:/usr/sbin:/bin:\$PATH
  114. export TERM=linux
  115. export HOME=/root
  116. export USER=root
  117.  
  118. busybox chroot \$chroot /bin/bash
  119. DEB
  120. chmod 777 sbin/debian
  121.  
  122. echo "Getting Busybox for boot image..."
  123. wget "https://github.com/metalx1000/Moto-G-root-tricks/blob/master/bin/busybox?raw=true" -O sbin/busybox
  124. chmod 777 sbin/busybox
  125.  
  126. #repack boot img
  127. cd ../
  128. pwd
  129. rm -fr initrd_new.img
  130. abootimg-pack-initrd initrd_new.img ramdisk/
  131. abootimg --create ../$img2 -f bootimg.cfg -k zImage -r initrd_new.img
  132. cd ../
  133. adb reboot bootloader
  134.  
  135. echo "Loading $img2 to phone's RAM..."
  136. fastboot boot ./$img2
  137. #adb shell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement