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
|
2022-01-27 18:41:32 +00:00
|
|
|
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"}
|
|
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
# 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
|
2021-09-17 16:02:12 +01:00
|
|
|
|
2020-08-07 21:07:43 +02:00
|
|
|
# Third stage
|
2022-08-22 23:03:04 +03:00
|
|
|
cat <<EOF >>"${work_dir}"/third-stage
|
*: Enable ssh, ext4 filesystem default now. Use growpart for growing the partition.
We use growpart from the cloud-guest-utils package (actually from Canonical's repo on github), and this allows us to resize all of the filesystem without random dropping journals.
Tested on rpi0w, rpi4 (32bit and 64bit), pinebook, pinebook-pro, nanopi neoplus2, rpi2, odroid-c2. So I am thinking it's in a spot to make it available everywhere.
Also, somehow enabling ssh was dropped, likely due to misreading the purpose of "enable-ssh" service, which is a feature parity thing from raspbian where you could drop a "ssh" or "ssh.txt" file on /boot and it would enable ssh. We decided long ago however, to always eable ssh on the arm images.
2021-09-23 12:19:35 -05:00
|
|
|
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
|
2021-10-13 20:10:29 -05:00
|
|
|
|
|
|
|
|
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
|
2021-10-12 20:56:41 +00:00
|
|
|
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"
|
2022-04-09 18:05:47 -05:00
|
|
|
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-
|
2021-11-21 11:02:40 -06:00
|
|
|
#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
|
2022-04-13 22:20:24 -05:00
|
|
|
wget $githubraw/f-secure-foundry/usbarmory/master/software/kernel_conf/usbarmory_linux-5.15.defconfig -O ../usbarmory_linux-5.15_defconfig
|
2021-11-13 16:54:25 -06:00
|
|
|
wget $githubraw/f-secure-foundry/usbarmory/master/software/kernel_conf/mark-two/imx6ul-usbarmory.dts -O arch/arm/boot/dts/imx6ul-usbarmory.dts
|
2022-04-09 18:05:47 -05:00
|
|
|
wget $githubraw/f-secure-foundry/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-usbarmory-tzns.dts -O arch/arm/boot/dts/imx6ulz-usbarmory-tzns.dts
|
2021-11-13 16:54:25 -06:00
|
|
|
wget $githubraw/f-secure-foundry/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-usbarmory.dts -O arch/arm/boot/dts/imx6ulz-usbarmory.dts
|
2022-04-13 22:20:24 -05:00
|
|
|
cp ../usbarmory_linux-5.15_defconfig arch/arm/configs/
|
|
|
|
|
make usbarmory_linux-5.15_defconfig
|
2022-04-09 18:05:47 -05:00
|
|
|
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
|
2022-04-13 22:20:24 -05:00
|
|
|
cp ../usbarmory_linux-5.15_defconfig arch/arm/configs/
|
2021-11-13 16:54:25 -06:00
|
|
|
wget $githubraw/f-secure-foundry/usbarmory/master/software/kernel_conf/mark-two/imx6ul-usbarmory.dts -O arch/arm/boot/dts/imx6ul-usbarmory.dts
|
2022-04-09 18:05:47 -05:00
|
|
|
wget $githubraw/f-secure-foundry/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-usbarmory-tzns.dts -O arch/arm/boot/dts/imx6ulz-usbarmory-tzns.dts
|
2021-11-13 16:54:25 -06:00
|
|
|
wget $githubraw/f-secure-foundry/usbarmory/master/software/kernel_conf/mark-two/imx6ulz-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
|
|
|
|
2021-10-12 17:04:33 -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
|
|
|
|
2021-09-17 16:02:12 +01: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"
|
2021-09-19 10:11:39 +01:00
|
|
|
mkdir -p "${base_dir}"/root
|
2022-08-22 23:03:04 +03:00
|
|
|
|
2022-07-21 14:34:30 -05: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
|
|
|
|
|
|
2022-07-21 14:34:30 -05:00
|
|
|
else
|
2022-08-22 23:03:04 +03:00
|
|
|
mount "${rootp}" "${base_dir}"/root
|
|
|
|
|
|
2022-07-21 14:34:30 -05:00
|
|
|
fi
|
2020-08-07 21:07:43 +02:00
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Rsyncing rootfs into image file"
|
2021-09-19 10:11:39 +01:00
|
|
|
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}"
|
2022-06-15 14:58:16 -05:00
|
|
|
wget ftp://ftp.denx.de/pub/u-boot/u-boot-2022.04.tar.bz2
|
|
|
|
|
tar xvf u-boot-2022.04.tar.bz2 && cd u-boot-2022.04
|
2021-11-13 16:54:25 -06:00
|
|
|
wget $githubraw/inversepath/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
|
2021-11-13 16:54:25 -06:00
|
|
|
make usbarmory-mark-two_config
|
2020-08-07 21:07:43 +02:00
|
|
|
make ARCH=arm
|
2021-11-13 16:54:25 -06:00
|
|
|
dd if=u-boot-dtb.imx of=${loopdevice} bs=512 seek=2 conv=fsync
|
2021-10-13 13:58:07 -05:00
|
|
|
cd "${repo_dir}/"
|
2020-08-07 21:07:43 +02:00
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
# Load default finish_image configs
|
|
|
|
|
include finish_image
|