Files
arm-kali/usb-armory-mkii.sh

190 lines
6.5 KiB
Bash
Raw Normal View History

2021-09-16 06:42:05 +01:00
#!/usr/bin/env bash
#
# Kali Linux ARM build-script for USB Armory MKII (32-bit)
2021-10-12 22:10:32 +01:00
# Source: https://gitlab.com/kalilinux/build-scripts/kali-arm
2021-09-16 06:42:05 +01:00
#
# This is a community script - you will need to generate your own image to use
# More information: https://www.kali.org/docs/arm/usb-armory-mkii/
#
2021-08-30 15:10:03 -05:00
# Hardware model
hw_model=${hw_model:-"usb-armory-mkii"}
2022-08-22 23:03:04 +03:00
2020-08-07 21:07:43 +02:00
# Architecture
architecture=${architecture:-"armhf"}
2022-08-22 23:03:04 +03:00
2021-08-30 15:10:03 -05:00
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
desktop=${desktop:-"xfce"}
# Load default base_image configs
source ./common.d/base_image.sh
2021-08-30 15:10:03 -05:00
# Network configs
2021-11-06 15:45:57 +01:00
basic_network
2021-08-30 15:10:03 -05:00
add_interface eth0
2020-08-07 21:07:43 +02:00
# Third stage
2022-08-22 23:03:04 +03:00
cat <<EOF >>"${work_dir}"/third-stage
status_stage3 'Install dhcp and vnc server'
2021-08-30 15:10:03 -05:00
eatmydata apt-get install -y isc-dhcp-server tightvncserver || eatmydata apt-get install -y --fix-broken
2021-09-19 10:56:45 +01:00
status_stage3 'Remove /etc/modules*'
2021-08-30 15:10:03 -05:00
rm /etc/modules
rm /etc/modules-load.d/modules.conf
2021-09-19 10:56:45 +01:00
status_stage3 'Add our /etc/modules-load.d/'
2021-08-30 15:10:03 -05:00
cat << __EOF__ > /etc/modules-load.d/modules.conf
2020-08-07 21:07:43 +02:00
ledtrig_heartbeat
ci_hdrc_imx
g_ether
#g_mass_storage
#g_multi
2021-08-30 15:10:03 -05:00
__EOF__
2020-08-07 21:07:43 +02:00
2021-09-19 10:56:45 +01:00
status_stage3 'Add our /etc/modprobe.d/'
2021-08-30 15:10:03 -05:00
cat << __EOF__ > /etc/modprobe.d/usbarmory.conf
2020-08-07 21:07:43 +02:00
options g_ether use_eem=0 dev_addr=1a:55:89:a2:69:41 host_addr=1a:55:89:a2:69:42
# To use either of the following, you should create the file /disk.img via dd
2021-09-16 06:58:38 +01:00
# "dd if=/dev/zero of=/disk.img bs=1M count=2048" would create a 2GB disk.img file
2020-08-07 21:07:43 +02:00
#options g_mass_storage file=disk.img
#options g_multi use_eem=0 dev_addr=1a:55:89:a2:69:41 host_addr=1a:55:89:a2:69:42 file=disk.img
2021-08-30 15:10:03 -05:00
__EOF__
2020-08-07 21:07:43 +02:00
2021-09-19 10:56:45 +01:00
status_stage3 'Add our /etc/network/interfaces.d/usb0'
2021-08-30 15:10:03 -05:00
cat << __EOF__ > /etc/network/interfaces.d/usb0
2020-08-07 21:07:43 +02:00
allow-hotplug usb0
iface usb0 inet static
address 10.0.0.1
netmask 255.255.255.0
gateway 10.0.0.2
2021-08-30 15:10:03 -05:00
__EOF__
2020-08-07 21:07:43 +02:00
2021-09-19 10:56:45 +01:00
status_stage3 'Add our /etc/dhcp/dhcpd.conf'
2021-09-16 06:58:38 +01:00
# Debian reads the config from inside /etc/dhcp
2021-08-30 15:10:03 -05:00
cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.old
cat << __EOF__ > /etc/dhcp/dhcpd.conf
2020-08-07 21:07:43 +02:00
# Sample configuration file for ISC dhcpd for Debian
# Original file /etc/dhcp/dhcpd.conf.old
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.0.0.0 netmask 255.255.255.0 {
2022-08-22 23:03:04 +03:00
range 10.0.0.2 10.0.0.2;
default-lease-time 600;
max-lease-time 7200;
2020-08-07 21:07:43 +02:00
}
2021-08-30 15:10:03 -05:00
__EOF__
2020-08-07 21:07:43 +02:00
2021-09-19 10:56:45 +01:00
status_stage3 'Only listen on usb0'
2021-08-30 15:10:03 -05:00
sed -i -e 's/INTERFACES.*/INTERFACES="usb0"/g' /etc/default/isc-dhcp-server
2021-09-19 10:56:45 +01:00
status_stage3 'Enable dhcp server'
2021-08-30 15:10:03 -05:00
update-rc.d isc-dhcp-server enable
status_stage3 'Fixup wireless-regdb signature'
update-alternatives --set regulatory.db /lib/firmware/regulatory.db-upstream
2021-08-30 15:10:03 -05:00
EOF
# Run third stage
include third_stage
2021-08-30 15:10:03 -05:00
# Clean system
include clean_system
2020-08-07 21:07:43 +02:00
# Kernel section. If you want to use a custom kernel, or configuration, replace
2021-09-16 06:58:38 +01:00
# them in this section
2021-09-19 10:56:45 +01:00
status "Kernel stuff"
git clone --depth 1 -b linux-5.15.y git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git ${work_dir}/usr/src/kernel
2020-08-07 21:07:43 +02:00
cd ${work_dir}/usr/src/kernel
2022-08-22 23:03:04 +03:00
git rev-parse HEAD >${work_dir}/usr/src/kernel-at-commit
2020-08-07 21:07:43 +02:00
touch .scmversion
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
#patch -p1 --no-backup-if-mismatch < ${repo_dir}/patches/ARM-drop-cc-option-fallbacks-for-architecture-select.patch
2022-08-22 23:03:04 +03:00
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/kali-wifi-injection-5.15.patch
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/0001-wireless-carl9170-Enable-sniffer-mode-promisc-flag-t.patch
wget $githubraw/usbarmory/usbarmory/master/software/kernel_conf/usbarmory_linux-5.15.defconfig -O ../usbarmory_linux-5.15_defconfig
wget $githubraw/usbarmory/usbarmory/master/software/kernel_conf/mark-two/imx6ul-512M-usbarmory.dts -O arch/arm/boot/dts/imx6ul-usbarmory.dts
wget $githubraw/usbarmory/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-512M-usbarmory-tzns.dts -O arch/arm/boot/dts/imx6ulz-usbarmory-tzns.dts
wget $githubraw/usbarmory/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-512M-usbarmory.dts -O arch/arm/boot/dts/imx6ulz-usbarmory.dts
cp ../usbarmory_linux-5.15_defconfig arch/arm/configs/
make usbarmory_linux-5.15_defconfig
make LOADADDR=0x80000000 -j $(grep -c processor /proc/cpuinfo) uImage modules imx6ul-usbarmory.dtb imx6ulz-usbarmory-tzns.dtb imx6ulz-usbarmory.dtb
2020-08-07 21:07:43 +02:00
make modules_install INSTALL_MOD_PATH=${work_dir}
cp arch/arm/boot/zImage ${work_dir}/boot/
2021-08-30 15:10:03 -05:00
cp arch/arm/boot/dts/imx6*-usbarmory*.dtb ${work_dir}/boot/
2020-08-07 21:07:43 +02:00
make mrproper
2022-08-22 23:03:04 +03:00
2021-09-16 06:58:38 +01:00
# Since these aren't integrated into the kernel yet, mrproper removes them
cp ../usbarmory_linux-5.15_defconfig arch/arm/configs/
wget $githubraw/usbarmory/usbarmory/master/software/kernel_conf/mark-two/imx6ul-512M-usbarmory.dts -O arch/arm/boot/dts/imx6ul-usbarmory.dts
wget $githubraw/usbarmory/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-512M-usbarmory-tzns.dts -O arch/arm/boot/dts/imx6ulz-usbarmory-tzns.dts
wget $githubraw/usbarmory/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-512M-usbarmory.dts -O arch/arm/boot/dts/imx6ulz-usbarmory.dts
2020-08-07 21:07:43 +02:00
# Fix up the symlink for building external modules
# kernver is used so we don't need to keep track of what the current compiled
# version is
2021-09-19 10:56:45 +01:00
status "building external modules"
2020-08-07 21:07:43 +02:00
kernver=$(ls ${work_dir}/lib/modules/)
cd ${work_dir}/lib/modules/${kernver}
rm build
rm source
ln -s /usr/src/kernel build
ln -s /usr/src/kernel source
2021-08-30 15:10:03 -05:00
cd "${repo_dir}/"
2020-08-07 21:07:43 +02:00
2021-09-16 06:58:38 +01:00
# Calculate the space to create the image and create
2021-08-30 15:10:03 -05:00
make_image
2020-08-07 21:07:43 +02:00
# Create the disk partitions
2021-09-19 10:56:45 +01:00
status "Create the disk partitions"
2021-09-19 13:45:29 +01:00
parted -s "${image_dir}/${image_name}.img" mklabel msdos
parted -s -a minimal "${image_dir}/${image_name}.img" mkpart primary ext2 5MiB 100%
2020-08-07 21:07:43 +02:00
# Set the partition variables
2021-11-07 10:55:31 +01:00
make_loop
2022-08-22 23:03:04 +03:00
2020-08-07 21:07:43 +02:00
# Create file systems
2022-08-22 23:03:04 +03:00
# Force root partition ext2 filesystem
rootfstype="ext2"
2021-11-06 13:30:14 +01:00
mkfs_partitions
2022-08-22 23:03:04 +03:00
2021-11-04 18:19:00 +01:00
# Make fstab.
make_fstab
2020-08-07 21:07:43 +02:00
# Create the dirs for the partitions and mount them
2021-09-19 10:56:45 +01:00
status "Create the dirs for the partitions and mount them"
mkdir -p "${base_dir}"/root
2022-08-22 23:03:04 +03:00
if [[ $fstype == ext4 ]]; then
2022-08-22 23:03:04 +03:00
mount -t ext4 -o noatime,data=writeback,barrier=0 "${rootp}" "${base_dir}"/root
else
2022-08-22 23:03:04 +03:00
mount "${rootp}" "${base_dir}"/root
fi
2020-08-07 21:07:43 +02:00
2021-09-19 10:56:45 +01:00
status "Rsyncing rootfs into image file"
rsync -HPavz -q "${work_dir}"/ "${base_dir}"/root/
2021-08-30 15:10:03 -05:00
sync
2020-08-07 21:07:43 +02:00
2021-09-19 10:56:45 +01:00
status "u-Boot"
2021-08-30 15:10:03 -05:00
cd "${work_dir}"
2023-08-15 14:42:04 -05:00
wget ftp://ftp.denx.de/pub/u-boot/u-boot-2023.07.tar.bz2
tar xvf u-boot-2023.07.tar.bz2 && cd u-boot-2023.07
wget $githubraw/usbarmory/usbarmory/master/software/u-boot/0001-ARM-mx6-add-support-for-USB-armory-Mk-II-board.patch
2022-08-22 23:03:04 +03:00
patch -p1 --no-backup-if-mismatch <0001-ARM-mx6-add-support-for-USB-armory-Mk-II-board.patch
2020-08-07 21:07:43 +02:00
make distclean
make usbarmory-mark-two_config
2020-08-07 21:07:43 +02:00
make ARCH=arm
dd if=u-boot-dtb.imx of=${loopdevice} bs=512 seek=2 conv=fsync
cd "${repo_dir}/"
2020-08-07 21:07:43 +02:00
# Load default finish_image configs
include finish_image