p4wnp1: Not yet working, only partially ported.
This needs work since the repos have moved while mame82 is on break. Unfortunately, before he went on break, the build setup changed a bunch. Hopefully we can bring it back in 2020.4?
This commit is contained in:
@@ -6,45 +6,79 @@ set -e
|
||||
#
|
||||
##########
|
||||
|
||||
# Doesn't currently work, so lets just exit.
|
||||
echo "This script is currently in need of work, porting to the new URLs, as well as the new setup."
|
||||
exit 1
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
# Uncomment to activate debug
|
||||
# debug=true
|
||||
|
||||
if [ "$debug" = true ]; then
|
||||
exec > >(tee -a -i "${0%.*}.log") 2>&1
|
||||
set -x
|
||||
fi
|
||||
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
echo "Please pass version number, e.g. $0 2.0"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
basedir=`pwd`/rpi0w-nexmon-p4wnp1-aloa-$1
|
||||
TOPDIR=`pwd`
|
||||
|
||||
# Architecture
|
||||
architecture=${architecture:-"armel"}
|
||||
# Generate a random machine name to be used.
|
||||
machine=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c16 ; echo)
|
||||
# Custom hostname variable
|
||||
hostname=${2:-kali}
|
||||
# Custom image name variable - MUST NOT include .img at the end.
|
||||
imagename=${3:-kali-linux-$1-rpi0w-nexmon-p4wnp1-aloa}
|
||||
# Size of image in megabytes (Default is 4500=4.5GB)
|
||||
size=6000
|
||||
# Suite to use.
|
||||
# Valid options are:
|
||||
# Custom image file name variable - MUST NOT include .img at the end.
|
||||
imagename=${3:-kali-linux-$1-rpi0w-p4wnp1}
|
||||
# Suite to use, valid options are:
|
||||
# kali-rolling, kali-dev, kali-bleeding-edge, kali-dev-only, kali-experimental, kali-last-snapshot
|
||||
# A release is done against kali-last-snapshot, but if you're building your own, you'll probably want to build
|
||||
# kali-rolling.
|
||||
suite=kali-rolling
|
||||
suite=${suite:-"kali-rolling"}
|
||||
# Free space rootfs in MiB
|
||||
free_space="300"
|
||||
# /boot partition in MiB
|
||||
bootsize="128"
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
mirror="http://kali.download/kali"
|
||||
# Gitlab url Kali repository
|
||||
kaligit="https://gitlab.com/kalilinux"
|
||||
# Github raw url
|
||||
githubraw="https://raw.githubusercontent.com"
|
||||
|
||||
# Generate a random machine name to be used.
|
||||
machine=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
|
||||
# Check EUID=0 you can run any binary as root.
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Package installations for various sections.
|
||||
# This will build a minimal Kali system with the top 10 tools.
|
||||
# This is the section to edit if you would like to add more packages.
|
||||
# See http://www.kali.org/new/kali-linux-metapackages/ for meta packages you can
|
||||
# use. You can also install packages, using just the package name, but keep in
|
||||
# mind that not all packages work on ARM! If you specify one of those, the
|
||||
# script will throw an error, but will still continue on, and create an unusable
|
||||
# image, keep that in mind.
|
||||
# Pass version number
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
echo "Please pass version number, e.g. $0 2.0, and (if you want) a hostname, default is kali"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check exist bsp directory.
|
||||
if [ ! -e "bsp" ]; then
|
||||
echo "Error: missing bsp directory structure"
|
||||
echo "Please clone the full repository ${kaligit}/build-scripts/kali-arm"
|
||||
exit 255
|
||||
fi
|
||||
|
||||
# Current directory
|
||||
current_dir="$(pwd)"
|
||||
# Base directory
|
||||
basedir=${current_dir}/rpi0w-p4wnp1-"$1"
|
||||
# Working directory
|
||||
work_dir="${basedir}/kali-${architecture}"
|
||||
|
||||
# Check directory build
|
||||
if [ -e "${basedir}" ]; then
|
||||
echo "${basedir} directory exists, will not continue"
|
||||
exit 1
|
||||
elif [[ ${current_dir} =~ [[:space:]] ]]; then
|
||||
echo "The directory "\"${current_dir}"\" contains whitespace. Not supported."
|
||||
exit 1
|
||||
else
|
||||
echo "The basedir thinks it is: ${basedir}"
|
||||
mkdir -p ${basedir}
|
||||
fi
|
||||
|
||||
components="main,contrib,non-free"
|
||||
arm="fake-hwclock ntpdate u-boot-tools"
|
||||
tools="aircrack-ng crunch cewl dnsrecon dnsutils ethtool exploitdb hydra medusa metasploit-framework ncrack nmap passing-the-hash proxychains recon-ng sqlmap tcpdump theharvester tor tshark usbutils whois windows-binaries winexe wpscan"
|
||||
base="apt-transport-https apt-utils console-setup e2fsprogs firmware-linux firmware-realtek firmware-atheros ifupdown initramfs-tools iw kali-defaults man-db mlocate netcat-traditional net-tools parted psmisc rfkill screen snmpd snmp tftp tmux unrar usbutils vim wget zerofree"
|
||||
@@ -60,10 +94,6 @@ services="apache2 atftpd openssh-server openvpn"
|
||||
extras="autossh avahi-daemon bash-completion bluez bluez-firmware dhcpcd5 dnsmasq dosfstools genisoimage golang haveged hostapd i2c-tools iodine policykit-1 python3-configobj python3-dev python3-pip python3-requests python3-smbus wpasupplicant"
|
||||
|
||||
packages="${arm} ${base} ${services} ${extras}"
|
||||
architecture="armel"
|
||||
# If you have your own preferred mirrors, set them here.
|
||||
# After generating the rootfs, we set the sources.list to the default settings.
|
||||
mirror=http.kali.org
|
||||
|
||||
# Check to ensure that the architecture is set to ARMEL since the RPi is the
|
||||
# only board that is armel.
|
||||
@@ -72,31 +102,45 @@ if [[ ${architecture} != "armel" ]] ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Set this to use an http proxy, like apt-cacher-ng, and uncomment further down
|
||||
# to unset it.
|
||||
#export http_proxy="http://localhost:3142/"
|
||||
|
||||
mkdir -p "${basedir}"
|
||||
cd "${basedir}"
|
||||
# Automatic configuration to use an http proxy, such as apt-cacher-ng.
|
||||
# You can turn off automatic settings by uncommenting apt_cacher=off.
|
||||
# apt_cacher=off
|
||||
# By default the proxy settings are local, but you can define an external proxy.
|
||||
# proxy_url="http://external.intranet.local"
|
||||
apt_cacher=${apt_cacher:-"$(lsof -i :3142|cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
||||
if [ -n "$proxy_url" ]; then
|
||||
export http_proxy=$proxy_url
|
||||
elif [ "$apt_cacher" = "apt-cacher-ng" ] ; then
|
||||
if [ -z "$proxy_url" ]; then
|
||||
proxy_url=${proxy_url:-"http://127.0.0.1:3142/"}
|
||||
export http_proxy=$proxy_url
|
||||
fi
|
||||
fi
|
||||
|
||||
# create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
||||
debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring --arch ${architecture} ${suite} kali-${architecture} http://${mirror}/kali
|
||||
debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring \
|
||||
--components=${components} --include=${arm// /,} --arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
||||
|
||||
cp /usr/bin/qemu-arm-static kali-${architecture}/usr/bin/
|
||||
# systemd-nspawn enviroment
|
||||
systemd-nspawn_exec(){
|
||||
qemu_bin=/usr/bin/qemu-aarch64-static
|
||||
LANG=C systemd-nspawn -q --bind-ro ${qemu_bin} -M ${machine} -D ${work_dir} "$@"
|
||||
}
|
||||
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /debootstrap/debootstrap --second-stage
|
||||
# debootstrap second stage
|
||||
systemd-nspawn_exec /debootstrap/debootstrap --second-stage
|
||||
|
||||
mkdir -p kali-${architecture}/etc/apt/
|
||||
cat << EOF > kali-${architecture}/etc/apt/sources.list
|
||||
deb http://${mirror}/kali ${suite} main contrib non-free
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
deb ${mirror} ${suite} ${components//,/ }
|
||||
#deb-src ${mirror} ${suite} ${components//,/ }
|
||||
EOF
|
||||
|
||||
# Set hostname
|
||||
echo "${machine}" > kali-${architecture}/etc/hostname
|
||||
echo "${hostname}" > ${work_dir}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add $hostname to hosts
|
||||
cat << EOF > kali-${architecture}/etc/hosts
|
||||
127.0.0.1 ${machine} localhost
|
||||
# So X doesn't complain, we add kali to hosts
|
||||
cat << EOF > ${work_dir}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
@@ -104,57 +148,41 @@ ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
# added wlan0 configuration to allow copying of wpa_supplicant.conf to work
|
||||
mkdir -p kali-${architecture}/etc/network/
|
||||
cat << EOF > kali-${architecture}/etc/network/interfaces
|
||||
# Disable IPv6
|
||||
cat << EOF > ${work_dir}/etc/modprobe.d/ipv6.conf
|
||||
# Don't load ipv6 by default
|
||||
alias net-pf-10 off
|
||||
EOF
|
||||
|
||||
cat << EOF > ${work_dir}/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
allow-hotplug eth0
|
||||
iface eth0 inet dhcp
|
||||
EOF
|
||||
|
||||
cat << EOF > kali-${architecture}/etc/resolv.conf
|
||||
nameserver 8.8.8.8
|
||||
EOF
|
||||
# DNS server
|
||||
echo "nameserver 8.8.8.8" > ${work_dir}/etc/resolv.conf
|
||||
|
||||
# Copy directory bsp into build dir.
|
||||
cp -rp bsp ${work_dir}
|
||||
|
||||
export MALLOC_CHECK_=0 # workaround for LP: #520465
|
||||
export LC_ALL=C
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
#mount -t proc proc kali-$architecture/proc
|
||||
#mount -o bind /dev/ kali-$architecture/dev/
|
||||
#mount -o bind /dev/pts kali-$architecture/dev/pts
|
||||
# Enable the use of http proxy in third-stage in case it is enabled.
|
||||
if [ -n "$proxy_url" ]; then
|
||||
echo "Acquire::http { Proxy \"$proxy_url\" };" > ${work_dir}/etc/apt/apt.conf.d/66proxy
|
||||
fi
|
||||
|
||||
cat << EOF > kali-${architecture}/debconf.set
|
||||
console-common console-data/keymap/policy select Select keymap from full list
|
||||
console-common console-data/keymap/full select en-latin1-nodeadkeys
|
||||
EOF
|
||||
|
||||
# Create monitor mode start/remove
|
||||
# The script returns an error code if the monitor interface couldn't be started
|
||||
# Note: Removing this should be considered, as enabling the monitor interface once
|
||||
# and using wpa_supplicant afterwards, crashs the WiFi firmware (even if the monitor
|
||||
# interface is removed). Afterwards the 'brcmfmac' module has to be removed and
|
||||
# loaded again (the driver push the firmware and restarts the fmac chip on init).
|
||||
# Sometimes only a reboot works
|
||||
cp "${basedir}"/../bsp/scripts/monstart kali-${architecture}/usr/bin/
|
||||
cp "${basedir}"/../bsp/scripts/monstop kali-${architecture}/usr/bin/
|
||||
cp "${basedir}"/../bsp/scripts/rpi-resizerootfs kali-${architecture}/usr/sbin/
|
||||
|
||||
mkdir -p kali-${architecture}/usr/lib/systemd/system/
|
||||
cp "${basedir}"/../bsp/services/all/*.service kali-${architecture}/usr/lib/systemd/system/
|
||||
cp "${basedir}"/../bsp/services/rpi/*.service kali-${architecture}/usr/lib/systemd/system/
|
||||
|
||||
# Bluetooth enabling
|
||||
mkdir -p kali-${architecture}/usr/lib/udev/rules.d/
|
||||
cp "${basedir}"/../bsp/bluetooth/rpi/50-bluetooth-hci-auto-poweron.rules kali-${architecture}/usr/lib/udev/rules.d/50-bluetooth-hci-auto-poweron.rules
|
||||
cp "${basedir}"/../bsp/bluetooth/rpi/pi-bluetooth+re4son_2.2_all.deb kali-${architecture}/root/pi-bluetooth+re4son_2.2_all.deb
|
||||
|
||||
# Copy a default config, with everything commented out so people find it when
|
||||
# they go to add something when they are following instructions on a website.
|
||||
cp "${basedir}"/../bsp/firmware/rpi/config.txt "${basedir}"/kali-${architecture}/boot/config.txt
|
||||
cp "${basedir}"/../bsp/firmware/rpi/config.txt ${work_dir}/boot/config.txt
|
||||
|
||||
# move P4wnP1 in (change to release blob when ready)
|
||||
git clone -b 'v0.1.0-alpha2' --single-branch --depth 1 https://github.com/mame82/P4wnP1_aloa "${basedir}"/kali-${architecture}/root/P4wnP1
|
||||
git clone -b 'v0.1.0-alpha2' --single-branch --depth 1 https://github.com/mame82/P4wnP1_aloa ${work_dir}/root/P4wnP1
|
||||
|
||||
cat << EOF > kali-${architecture}/third-stage
|
||||
#!/bin/bash
|
||||
@@ -185,6 +213,23 @@ apt-get --yes --allow-change-held-packages -o dpkg::options::=--force-confnew au
|
||||
echo "Allow root login..."
|
||||
sed -i -e 's/^#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
|
||||
|
||||
# Create monitor mode start/remove
|
||||
# The script returns an error code if the monitor interface couldn't be started
|
||||
# Note: Removing this should be considered, as enabling the monitor interface once
|
||||
# and using wpa_supplicant afterwards, crashs the WiFi firmware (even if the monitor
|
||||
# interface is removed). Afterwards the 'brcmfmac' module has to be removed and
|
||||
# loaded again (the driver push the firmware and restarts the fmac chip on init).
|
||||
# Sometimes only a reboot works
|
||||
install -m755 /bsp/scripts/monstart /usr/bin/
|
||||
install -m755 /bsp/scripts/monstop /usr/bin/
|
||||
install -m755 /bsp/scripts/rpi-resizerootfs /usr/sbin/
|
||||
|
||||
install -m644 /bsp/services/all/*.service /etc/systemd/system/
|
||||
install -m644 /bsp/services/rpi/*.service /etc/systemd/system/
|
||||
|
||||
# Bluetooth enabling
|
||||
install -m644 /bsp/bluetooth/rpi/50-bluetooth-hci-auto-poweron.rules /etc/udev/rules.d/
|
||||
|
||||
# Regenerated the shared-mime-info database on the first boot
|
||||
# since it fails to do so properly in a chroot.
|
||||
systemctl enable smi-hack
|
||||
@@ -194,10 +239,11 @@ systemctl enable rpi-resizerootfs
|
||||
|
||||
# Generate SSH host keys on first run
|
||||
systemctl enable regenerate_ssh_host_keys
|
||||
# Enable sshd
|
||||
systemctl enable ssh
|
||||
|
||||
# Install and hold pi-bluetooth deb package from re4son
|
||||
dpkg --force-all -i /root/pi-bluetooth+re4son_2.2_all.deb
|
||||
dpkg --force-all -i /bsp/bluetooth/rpi/pi-bluetooth+re4son_2.2_all.deb
|
||||
apt-mark hold pi-bluetooth+re4son
|
||||
|
||||
# systemd version 232 and above breaks execution of above bluetooth rule, let's fix that
|
||||
@@ -246,9 +292,7 @@ echo "exit 0" >> /etc/rc.local
|
||||
cp /etc/skel/.bashrc /root/.bashrc
|
||||
|
||||
cd /root
|
||||
apt download ca-certificates
|
||||
apt download libgdk-pixbuf2.0-0
|
||||
apt download fontconfig
|
||||
apt download -o APT::Sandbox::User=root ca-certificates 2>/dev/null
|
||||
|
||||
# Fix startup time from 5 minutes to 15 secs on raise interface wlan0
|
||||
sed -i 's/^TimeoutStartSec=5min/TimeoutStartSec=15/g' "/lib/systemd/system/networking.service"
|
||||
@@ -283,9 +327,9 @@ chmod 755 kali-${architecture}/cleanup
|
||||
LANG=C systemd-nspawn -M ${machine} -D kali-${architecture} /cleanup
|
||||
|
||||
# Enable login over serial
|
||||
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> "${basedir}"/kali-${architecture}/etc/inittab
|
||||
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> ${work_dir}/etc/inittab
|
||||
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/etc/apt/sources.list
|
||||
cat << EOF > ${work_dir}/etc/apt/sources.list
|
||||
deb http://http.kali.org/kali kali-rolling main non-free contrib
|
||||
deb-src http://http.kali.org/kali kali-rolling main non-free contrib
|
||||
EOF
|
||||
@@ -300,9 +344,9 @@ cd ${TOPDIR}
|
||||
|
||||
# RPI Firmware
|
||||
git clone --depth 1 https://github.com/raspberrypi/firmware.git rpi-firmware
|
||||
cp -rf rpi-firmware/boot/* "${basedir}"/kali-${architecture}/boot/
|
||||
cp -rf rpi-firmware/boot/* ${work_dir}/boot/
|
||||
# copy over Pi specific libs (video core) and binaries (dtoverlay,dtparam ...)
|
||||
cp -rf rpi-firmware/opt/* "${basedir}"/kali-${architecture}/opt/
|
||||
cp -rf rpi-firmware/opt/* ${work_dir}/opt/
|
||||
rm -rf rpi-firmware
|
||||
|
||||
# Build nexmon firmware outside the build system, if we can (use repository with driver and firmware for P4wnP1).
|
||||
@@ -312,10 +356,10 @@ git clone https://github.com/mame82/nexmon_wifi_covert_channel.git -b p4wnp1 "${
|
||||
# Setup build
|
||||
cd ${TOPDIR}
|
||||
# Re4son kernel 4.14.80 with P4wnP1 patches (dwc2 and brcmfmac)
|
||||
git clone --depth 1 https://github.com/Re4son/re4son-raspberrypi-linux -b rpi-4.14.80-re4son-p4wnp1 "${basedir}"/kali-${architecture}/usr/src/kernel
|
||||
git clone --depth 1 https://github.com/Re4son/re4son-raspberrypi-linux -b rpi-4.14.80-re4son-p4wnp1 ${work_dir}/usr/src/kernel
|
||||
|
||||
|
||||
cd "${basedir}"/kali-${architecture}/usr/src/kernel
|
||||
cd ${work_dir}/usr/src/kernel
|
||||
|
||||
# Note: Compiling the kernel in /usr/src/kernel of the target file system is problematic, as the binaries of the compiling host architecture
|
||||
# get deployed to the /usr/src/kernel/scripts subfolder (in this case linux-x64 binaries), which is symlinked to /usr/src/build later on.
|
||||
@@ -351,13 +395,13 @@ make re4son_pi1_defconfig
|
||||
make -j $(grep -c processor /proc/cpuinfo)
|
||||
|
||||
# Make kernel modules
|
||||
make modules_install INSTALL_MOD_PATH="${basedir}"/kali-${architecture}
|
||||
make modules_install INSTALL_MOD_PATH=${work_dir}
|
||||
|
||||
# Copy kernel to boot
|
||||
perl scripts/mkknlimg --dtok arch/arm/boot/zImage "${basedir}"/kali-${architecture}/boot/kernel.img
|
||||
cp arch/arm/boot/dts/*.dtb "${basedir}"/kali-${architecture}/boot/
|
||||
cp arch/arm/boot/dts/overlays/*.dtb* "${basedir}"/kali-${architecture}/boot/overlays/
|
||||
cp arch/arm/boot/dts/overlays/README "${basedir}"/kali-${architecture}/boot/overlays/
|
||||
perl scripts/mkknlimg --dtok arch/arm/boot/zImage ${work_dir}/boot/kernel.img
|
||||
cp arch/arm/boot/dts/*.dtb ${work_dir}/boot/
|
||||
cp arch/arm/boot/dts/overlays/*.dtb* ${work_dir}/boot/overlays/
|
||||
cp arch/arm/boot/dts/overlays/README ${work_dir}/boot/overlays/
|
||||
|
||||
make mrproper
|
||||
make re4son_pi1_defconfig
|
||||
@@ -365,8 +409,8 @@ make re4son_pi1_defconfig
|
||||
# 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
|
||||
kernver=$(ls "${basedir}"/kali-${architecture}/lib/modules/)
|
||||
cd "${basedir}"/kali-${architecture}/lib/modules/${kernver}
|
||||
kernver=$(ls ${work_dir}/lib/modules/)
|
||||
cd ${work_dir}/lib/modules/${kernver}
|
||||
rm build
|
||||
rm source
|
||||
ln -s /usr/src/kernel build
|
||||
@@ -375,15 +419,15 @@ cd "${basedir}"
|
||||
|
||||
# Copy a default config, with everything commented out so people find it when
|
||||
# they go to add something when they are following instructions on a website.
|
||||
cp "${basedir}"/../bsp/firmware/rpi/config.txt "${basedir}"/kali-${architecture}/boot/config.txt
|
||||
cp "${basedir}"/../bsp/firmware/rpi/config.txt ${work_dir}/boot/config.txt
|
||||
|
||||
cat << EOF >> "${basedir}"/kali-${architecture}/boot/config.txt
|
||||
cat << EOF >> ${work_dir}/boot/config.txt
|
||||
dtoverlay=dwc2
|
||||
EOF
|
||||
|
||||
# systemd doesn't seem to be generating the fstab properly for some people, so
|
||||
# let's create one.
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/etc/fstab
|
||||
cat << EOF > ${work_dir}/etc/fstab
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
proc /proc proc defaults 0 0
|
||||
/dev/mmcblk0p1 /boot vfat defaults 0 2
|
||||
@@ -392,9 +436,9 @@ EOF
|
||||
|
||||
|
||||
# rpi-wiggle
|
||||
mkdir -p "${basedir}"/kali-${architecture}/root/scripts
|
||||
wget https://raw.github.com/steev/rpiwiggle/master/rpi-wiggle -O "${basedir}"/kali-${architecture}/root/scripts/rpi-wiggle.sh
|
||||
chmod 755 "${basedir}"/kali-${architecture}/root/scripts/rpi-wiggle.sh
|
||||
mkdir -p ${work_dir}/root/scripts
|
||||
wget https://raw.github.com/steev/rpiwiggle/master/rpi-wiggle -O ${work_dir}/root/scripts/rpi-wiggle.sh
|
||||
chmod 755 ${work_dir}/root/scripts/rpi-wiggle.sh
|
||||
|
||||
# git clone of nexmon moved in front of kernel compilation, to have poper brcmfmac driver ready
|
||||
cd "${basedir}"/nexmon
|
||||
@@ -416,45 +460,49 @@ make clean
|
||||
LD_LIBRARY_PATH=${NEXMON_ROOT}/buildtools/isl-0.10/.libs make ARCH=arm CC=${NEXMON_ROOT}/buildtools/gcc-arm-none-eabi-5_4-2016q2-linux-x86/bin/arm-none-eabi-
|
||||
# RPi0w->3B firmware
|
||||
# disable nexmon by default
|
||||
mkdir -p "${basedir}"/kali-${architecture}/lib/firmware/brcm
|
||||
cp ${NEXMON_ROOT}/patches/bcm43430a1/7_45_41_46/nexmon/brcmfmac43430-sdio.bin "${basedir}"/kali-${architecture}/lib/firmware/brcm/brcmfmac43430-sdio.nexmon.bin
|
||||
cp ${NEXMON_ROOT}/patches/bcm43430a1/7_45_41_46/nexmon/brcmfmac43430-sdio.bin "${basedir}"/kali-${architecture}/lib/firmware/brcm/brcmfmac43430-sdio.bin
|
||||
wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm/brcmfmac43430-sdio.txt -O "${basedir}"/kali-${architecture}/lib/firmware/brcm/brcmfmac43430-sdio.txt
|
||||
mkdir -p ${work_dir}/lib/firmware/brcm
|
||||
cp ${NEXMON_ROOT}/patches/bcm43430a1/7_45_41_46/nexmon/brcmfmac43430-sdio.bin ${work_dir}/lib/firmware/brcm/brcmfmac43430-sdio.nexmon.bin
|
||||
cp ${NEXMON_ROOT}/patches/bcm43430a1/7_45_41_46/nexmon/brcmfmac43430-sdio.bin ${work_dir}/lib/firmware/brcm/brcmfmac43430-sdio.bin
|
||||
wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm/brcmfmac43430-sdio.txt -O ${work_dir}/lib/firmware/brcm/brcmfmac43430-sdio.txt
|
||||
# Make a backup copy of the rpi firmware in case people don't want to use the nexmon firmware.
|
||||
# The firmware used on the RPi is not the same firmware that is in the firmware-brcm package which is why we do this.
|
||||
wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm/brcmfmac43430-sdio.bin -O "${basedir}"/kali-${architecture}/lib/firmware/brcm/brcmfmac43430-sdio.rpi.bin
|
||||
#cp "${basedir}"/kali-${architecture}/lib/firmware/brcm/brcmfmac43430-sdio.rpi.bin "${basedir}"/kali-${architecture}/lib/firmware/brcm/brcmfmac43430-sdio.bin
|
||||
wget https://raw.githubusercontent.com/RPi-Distro/firmware-nonfree/master/brcm/brcmfmac43430-sdio.bin -O ${work_dir}/lib/firmware/brcm/brcmfmac43430-sdio.rpi.bin
|
||||
#cp ${work_dir}/lib/firmware/brcm/brcmfmac43430-sdio.rpi.bin ${work_dir}/lib/firmware/brcm/brcmfmac43430-sdio.bin
|
||||
|
||||
cp "${basedir}"/../bsp/firmware/rpi/BCM43430A1.hcd "${basedir}"/kali-${architecture}/lib/firmware/brcm/BCM43430A1.hcd
|
||||
cp "${basedir}"/../bsp/firmware/rpi/BCM43430A1.hcd ${work_dir}/lib/firmware/brcm/BCM43430A1.hcd
|
||||
|
||||
cd "${basedir}"
|
||||
|
||||
sed -i -e 's/^#PermitRootLogin.*/PermitRootLogin yes/' "${basedir}"/kali-${architecture}/etc/ssh/sshd_config
|
||||
sed -i -e 's/^#PermitRootLogin.*/PermitRootLogin yes/' ${work_dir}/etc/ssh/sshd_config
|
||||
|
||||
# Calculate the space to create the image.
|
||||
free_space=$((${free_space}*1024))
|
||||
bootstart=$((${bootsize}*1024/1000*2*1024/2))
|
||||
bootend=$((${bootstart}+1024))
|
||||
rootsize=$(du -s --block-size KiB ${work_dir} --exclude boot | cut -f1)
|
||||
rootsize=$((${free_space}+${rootsize//KiB/ }/1000*2*1024/2))
|
||||
raw_size=$((${free_space}+${rootsize}+${bootstart}))
|
||||
|
||||
# Create the disk and partition it
|
||||
echo "Creating image file ${imagename}.img"
|
||||
dd if=/dev/zero of="${basedir}"/${imagename}.img bs=1M count=${size}
|
||||
parted ${imagename}.img --script -- mklabel msdos
|
||||
parted ${imagename}.img --script -- mkpart primary fat32 0 128
|
||||
parted ${imagename}.img --script -- mkpart primary ext3 128 -1
|
||||
dd if=/dev/zero of=${basedir}/${imagename}.img bs=1KiB count=0 seek=${raw_size} && sync
|
||||
parted "${basedir}"/${imagename}.img --script -- mklabel msdos
|
||||
parted "${basedir}"/${imagename}.img --script -- mkpart primary fat32 1MiB ${bootstart}KiB
|
||||
parted "${basedir}"/${imagename}.img --script -- mkpart primary ext3 ${bootend}KiB 100%
|
||||
|
||||
# Set the partition variables
|
||||
loopdevice=`losetup -f --show "${basedir}"/${imagename}.img`
|
||||
device=`kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1`
|
||||
sleep 5
|
||||
device="/dev/mapper/${device}"
|
||||
bootp=${device}p1
|
||||
rootp=${device}p2
|
||||
bootp="$(losetup -o 1MiB --sizelimit ${bootstart}KiB -f --show ${basedir}/${imagename}.img)"
|
||||
rootp="$(losetup -o ${bootend}KiB --sizelimit ${raw_size}KiB -f --show ${basedir}/${imagename}.img)"
|
||||
|
||||
# Create file systems
|
||||
mkfs.vfat ${bootp}
|
||||
mkfs.ext3 ${rootp}
|
||||
mkfs.vfat -n BOOT -F 32 -v ${bootp}
|
||||
mkfs.ext3 -L ROOTFS -O ^64bit,^flex_bg,^metadata_csum ${rootp}
|
||||
|
||||
# Create the dirs for the partitions and mount them
|
||||
mkdir -p "${basedir}"/root
|
||||
mount ${rootp} "${basedir}"/root
|
||||
mkdir -p "${basedir}"/root/boot
|
||||
mount ${bootp} "${basedir}"/root/boot
|
||||
mkdir -p ${basedir}/root/
|
||||
mount ${rootp} ${basedir}/root
|
||||
mkdir -p ${basedir}/root/boot
|
||||
mount ${bootp} ${basedir}/root/boot
|
||||
|
||||
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
||||
cat << EOF > kali-${architecture}/etc/resolv.conf
|
||||
@@ -463,10 +511,10 @@ EOF
|
||||
|
||||
# Because of the p4wnp1 script, we set the hostname down here, instead of using the machine name.
|
||||
# Set hostname
|
||||
echo "${hostname}" > "${basedir}"/kali-${architecture}/etc/hostname
|
||||
echo "${hostname}" > ${work_dir}/etc/hostname
|
||||
|
||||
# So X doesn't complain, we add $hostname to hosts
|
||||
cat << EOF > "${basedir}"/kali-${architecture}/etc/hosts
|
||||
cat << EOF > ${work_dir}/etc/hosts
|
||||
127.0.0.1 ${hostname} localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
@@ -476,20 +524,26 @@ ff02::2 ip6-allrouters
|
||||
EOF
|
||||
|
||||
echo "Rsyncing rootfs into image file"
|
||||
rsync -HPavz -q "${basedir}"/kali-${architecture}/ "${basedir}"/root/
|
||||
rsync -HPavz -q --exclude boot ${work_dir}/ ${basedir}/root/
|
||||
rsync -rtx -q ${work_dir}/boot ${basedir}/root
|
||||
sync
|
||||
|
||||
# Unmount partitions
|
||||
sync
|
||||
umount ${bootp}
|
||||
umount ${rootp}
|
||||
kpartx -dv ${loopdevice}
|
||||
losetup -d ${loopdevice}
|
||||
|
||||
# Don't pixz on 32bit, there isn't enough memory to compress the images.
|
||||
MACHINE_TYPE=`uname -m`
|
||||
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
pixz "${basedir}"/${imagename}.img "${basedir}"/../${imagename}.img.xz
|
||||
if [ $(arch) == 'x86_64' ]; then
|
||||
echo "Compressing ${imagename}.img"
|
||||
cd ${current_dir}
|
||||
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
||||
cgcreate -g cpu:/cpulimit-${rand} # Name of group
|
||||
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
||||
cgset -r cpu.cfs_quota_us=80000 cpulimit-${rand} # Max 100000
|
||||
cgexec -g cpu:cpulimit-${rand} pixz -p 2 "${basedir}"/${imagename}.img ${imagename}.img.xz # -p Nº cpu cores use
|
||||
cgdelete cpu:/cpulimit-${rand} # Delete group
|
||||
fi
|
||||
|
||||
# Clean up all the temporary build stuff and remove the directories.
|
||||
|
||||
Reference in New Issue
Block a user