PageRenderTime 2559ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/mini-x.sh

https://gitlab.com/rchicoli/kali-arm-build-scripts
Shell | 233 lines | 155 code | 44 blank | 34 comment | 6 complexity | 1f0dc1e13a743369c97400bdffeb41ae MD5 | raw file
  1. #!/bin/bash
  2. if [[ $# -eq 0 ]] ; then
  3. echo "Please pass version number, e.g. $0 1.0.1"
  4. exit 0
  5. fi
  6. basedir=`pwd`/mini-x-$1
  7. # Package installations for various sections.
  8. # This will build a minimal XFCE Kali system with the top 10 tools.
  9. # This is the section to edit if you would like to add more packages.
  10. # See http://www.kali.org/new/kali-linux-metapackages/ for meta packages you can
  11. # use. You can also install packages, using just the package name, but keep in
  12. # mind that not all packages work on ARM! If you specify one of those, the
  13. # script will throw an error, but will still continue on, and create an unusable
  14. # image, keep that in mind.
  15. arm="abootimg cgpt fake-hwclock ntpdate vboot-utils vboot-kernel-utils uboot-mkimage"
  16. base="kali-menu kali-defaults initramfs-tools usbutils"
  17. desktop="xfce4 network-manager network-manager-gnome xserver-xorg-video-fbdev"
  18. tools="passing-the-hash winexe aircrack-ng hydra john sqlmap wireshark libnfc-bin mfoc"
  19. services="openssh-server apache2"
  20. extras="iceweasel wpasupplicant"
  21. export packages="${arm} ${base} ${desktop} ${tools} ${services} ${extras}"
  22. export architecture="armhf"
  23. # Set this to use an http proxy, like apt-cacher-ng, and uncomment further down
  24. # to unset it.
  25. #export http_proxy="http://localhost:3142/"
  26. mkdir -p ${basedir}
  27. cd ${basedir}
  28. # create the rootfs - not much to modify here, except maybe the hostname
  29. debootstrap --foreign --arch $architecture kali kali-$architecture http://http.kali.org/kali
  30. cp /usr/bin/qemu-arm-static kali-$architecture/usr/bin/
  31. LANG=C chroot kali-$architecture /debootstrap/debootstrap --second-stage
  32. cat << EOF > kali-$architecture/etc/apt/sources.list
  33. deb http://http.kali.org/kali kali main contrib non-free
  34. deb http://security.kali.org/kali-security kali/updates main contrib non-free
  35. EOF
  36. echo "kali" > kali-$architecture/etc/hostname
  37. cat << EOF > kali-$architecture/etc/hosts
  38. 127.0.0.1 kali localhost
  39. ::1 localhost ip6-localhost ip6-loopback
  40. fe00::0 ip6-localnet
  41. ff00::0 ip6-mcastprefix
  42. ff02::1 ip6-allnodes
  43. ff02::2 ip6-allrouters
  44. EOF
  45. cat << EOF > kali-$architecture/etc/network/interfaces
  46. auto lo
  47. iface lo inet loopback
  48. auto eth0
  49. iface eth0 inet dhcp
  50. EOF
  51. cat << EOF > kali-$architecture/etc/resolv.conf
  52. nameserver 8.8.8.8
  53. EOF
  54. export MALLOC_CHECK_=0 # workaround for LP: #520465
  55. export LC_ALL=C
  56. export DEBIAN_FRONTEND=noninteractive
  57. mount -t proc proc kali-$architecture/proc
  58. mount -o bind /dev/ kali-$architecture/dev/
  59. mount -o bind /dev/pts kali-$architecture/dev/pts
  60. cat << EOF > kali-$architecture/debconf.set
  61. console-common console-data/keymap/policy select Select keymap from full list
  62. console-common console-data/keymap/full select en-latin1-nodeadkeys
  63. EOF
  64. cat << EOF > kali-$architecture/third-stage
  65. #!/bin/bash
  66. dpkg-divert --add --local --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d
  67. cp /bin/true /usr/sbin/invoke-rc.d
  68. echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d
  69. chmod +x /usr/sbin/policy-rc.d
  70. apt-get update
  71. apt-get install locales-all
  72. debconf-set-selections /debconf.set
  73. rm -f /debconf.set
  74. apt-get update
  75. apt-get -y install git-core binutils ca-certificates initramfs-tools uboot-mkimage
  76. apt-get -y install locales console-common less nano git
  77. echo "root:toor" | chpasswd
  78. sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules
  79. rm -f /etc/udev/rules.d/70-persistent-net.rules
  80. apt-get --yes --force-yes install $packages
  81. rm -f /usr/sbin/policy-rc.d
  82. rm -f /usr/sbin/invoke-rc.d
  83. dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
  84. rm -f /third-stage
  85. EOF
  86. chmod +x kali-$architecture/third-stage
  87. LANG=C chroot kali-$architecture /third-stage
  88. cat << EOF > kali-$architecture/cleanup
  89. #!/bin/bash
  90. rm -rf /root/.bash_history
  91. apt-get update
  92. apt-get clean
  93. rm -f /0
  94. rm -f /hs_err*
  95. rm -f cleanup
  96. rm -f /usr/bin/qemu*
  97. EOF
  98. chmod +x kali-$architecture/cleanup
  99. LANG=C chroot kali-$architecture /cleanup
  100. umount kali-$architecture/proc/sys/fs/binfmt_misc
  101. umount kali-$architecture/dev/pts
  102. umount kali-$architecture/dev/
  103. umount kali-$architecture/proc
  104. # Create the disk and partition it
  105. echo "Creating image file for Mini-X"
  106. dd if=/dev/zero of=${basedir}/kali-$1-mini-x.img bs=1M count=7000
  107. parted kali-$1-mini-x.img --script -- mklabel msdos
  108. parted kali-$1-mini-x.img --script -- mkpart primary fat32 2048s 264191s
  109. parted kali-$1-mini-x.img --script -- mkpart primary ext4 264192s 100%
  110. # Set the partition variables
  111. loopdevice=`losetup -f --show ${basedir}/kali-$1-mini-x.img`
  112. device=`kpartx -va $loopdevice| sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
  113. device="/dev/mapper/${device}"
  114. bootp=${device}p1
  115. rootp=${device}p2
  116. # Create file systems
  117. mkfs.vfat $bootp
  118. mkfs.ext4 $rootp
  119. # Create the dirs for the partitions and mount them
  120. mkdir -p ${basedir}/bootp ${basedir}/root
  121. mount $bootp ${basedir}/bootp
  122. mount $rootp ${basedir}/root
  123. echo "Rsyncing rootfs into image file"
  124. rsync -HPavz -q ${basedir}/kali-$architecture/ ${basedir}/root/
  125. # Uncomment this if you use apt-cacher-ng otherwise git clones will fail.
  126. #unset http_proxy
  127. # Kernel section. If you want to use a custom kernel, or configuration, replace
  128. # them in this section.
  129. git clone --depth 1 https://github.com/linux-sunxi/u-boot-sunxi
  130. git clone --depth 1 https://github.com/linux-sunxi/linux-sunxi -b stage/sunxi-3.4 ${basedir}/kernel
  131. git clone --depth 1 https://github.com/linux-sunxi/sunxi-tools
  132. git clone --depth 1 https://github.com/linux-sunxi/sunxi-boards
  133. cd ${basedir}/sunxi-tools
  134. make fex2bin
  135. ./fex2bin ${basedir}/sunxi-boards/sys_config/a10/mini-x.fex ${basedir}/bootp/script.bin
  136. cd ${basedir}/kernel
  137. mkdir -p ../patches
  138. wget http://patches.aircrack-ng.org/mac80211.compat08082009.wl_frag+ack_v1.patch -O ../patches/mac80211.patch
  139. patch -p1 --no-backup-if-mismatch < ../patches/mac80211.patch
  140. touch .scmversion
  141. export ARCH=arm
  142. export CROSS_COMPILE=arm-linux-gnueabihf-
  143. make sun4i_defconfig
  144. make -j $(grep -c processor /proc/cpuinfo) uImage modules
  145. make modules_install INSTALL_MOD_PATH=${basedir}/root
  146. cp arch/arm/boot/uImage ${basedir}/bootp
  147. cd ${basedir}
  148. # Create boot.txt file
  149. cat << EOF > ${basedir}/bootp/boot.cmd
  150. setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10 ${extra}
  151. fatload mmc 0 0x43000000 script.bin
  152. fatload mmc 0 0x48000000 uImage
  153. bootm 0x48000000
  154. EOF
  155. # Create u-boot boot script image
  156. mkimage -A arm -T script -C none -d ${basedir}/bootp/boot.cmd ${basedir}/bootp/boot.scr
  157. cd ${basedir}/u-boot-sunxi/
  158. # Build u-boot
  159. make distclean
  160. make Mini-X -j $(grep -c processor /proc/cpuinfo)
  161. dd if=u-boot-sunxi-with-spl.bin of=$loopdevice bs=1024 seek=8
  162. rm -rf ${basedir}/root/lib/firmware
  163. cd ${basedir}/root/lib
  164. git clone https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git firmware
  165. rm -rf ${basedir}/root/lib/firmware/.git
  166. cd ${basedir}
  167. # Unmount partitions
  168. umount $bootp
  169. umount $rootp
  170. kpartx -dv $loopdevice
  171. # Clean up all the temporary build stuff and remove the directories.
  172. # Comment this out to keep things around if you want to see what may have gone
  173. # wrong.
  174. echo "Cleaning up temporary build system"
  175. rm -rf ${basedir}/*sunxi* ${basedir}/patches ${basedir}/kernel ${basedir}/bootp ${basedir}/root ${basedir}/kali-$architecture ${basedir}/boot
  176. # If you're building an image for yourself, comment all of this out, as you
  177. # don't need the sha1sum or to compress the image, since you will be testing it
  178. # soon.
  179. echo "Generating sha1sum for kali-$1-mini-x.img"
  180. sha1sum kali-$1-mini-x.img > ${basedir}/kali-$1-mini-x.img.sha1sum
  181. # Don't pixz on 32bit, there isn't enough memory to compress the images.
  182. MACHINE_TYPE=`uname -m`
  183. if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  184. echo "Compressing kali-$1-mini-x.img"
  185. pixz ${basedir}/kali-$1-mini-x.img ${basedir}/kali-$1-mini-x.img.xz
  186. rm ${basedir}/kali-$1-mini-x.img
  187. echo "Generating sha1sum for kali-$1-mini-x.img.xz"
  188. sha1sum kali-$1-mini-x.img.xz > ${basedir}/kali-$1-mini-x.img.xz.sha1sum
  189. fi