From a113877a5bc328cad042fde535989451189f2a24 Mon Sep 17 00:00:00 2001 From: VertexC Date: Sun, 26 May 2019 16:17:55 -0700 Subject: [PATCH] update base.img with raspbian-lite --- bin/create_image.sh | 26 +++++++++++++++----------- install/install.sh | 13 +++++++++---- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/bin/create_image.sh b/bin/create_image.sh index 2e97e21..99aeae8 100755 --- a/bin/create_image.sh +++ b/bin/create_image.sh @@ -10,7 +10,7 @@ # - wlan config (optional) DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) LOG="${DIR}/${1}_$(date +%d-%m-%Y-%H-%M-%S)_output.txt" -PROGRESS="${DIR}/${1}_progress.txt" +PROGRESS="${DIR}/${1}_$(date +%d-%m-%Y-%H-%M-%S)_progress.txt" IMAGE_DIR="${DIR}/../honeypot_images" echo "0" > "${PROGRESS}" echo "" > "${LOG}" @@ -26,8 +26,8 @@ if [ -a "${IMAGE_DIR}/${2}" ]; then rm "${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1 fi # Copy base to new name -echo "Creating 1.5GB image in ${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1 -dd bs=1M count=1536 if=/dev/zero of="${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1 +echo "Creating 3GB image in ${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1 +dd bs=1M count=3072 if=/dev/zero of="${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1 echo "5" > "${PROGRESS}" echo "Finished creation, creating loop devices" >> "${LOG}" 2>&1 losetup -f "${IMAGE_DIR}/base.img" >> "${LOG}" 2>&1 @@ -38,11 +38,15 @@ echo "Copy data from base (${ORIG_LD}) to new image (${NEW_LD}) using dd" >> "${ dd if="${ORIG_LD}" of="${NEW_LD}" >> "${LOG}" 2>&1 echo "10" > "${PROGRESS}" echo "Parted partition reorganisation" >> "${LOG}" 2>&1 -parted -s "${NEW_LD}" rm 2 >> "${LOG}" 2>&1 -parted -s "${NEW_LD}" mkpart primary 64 1611 >> "${LOG}" 2>&1 +# parted -s "${NEW_LD}" rm 2 >> "${LOG}" 2>&1 +# parted -s "${NEW_LD}" mkpart primary 64 1611 >> "${LOG}" 2>&1 +startSector=$(fdisk -lu ${IMAGE_DIR}/${2} | grep Linux | sed -r 's/.*\.img2 *([0-9]+).*/\1/') +printf "d\n2\nn\np\n2\n${startSector}\n\nw\n" | fdisk ${IMAGE_DIR}/${2} echo "20" > "${PROGRESS}" -echo "Creating loopback device for root partition" >> "${LOG}" 2>&1 -losetup -f -o 64028672 "${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1 +echo "Get the image size" >> "${LOG}" 2>&1 +rootOffset=$(expr ${startSector} \* 512) +echo "Creating loopback device for root partition with offset ${rootOffset}" >> "${LOG}" 2>&1 +losetup -f -o ${rootOffset} "${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1 ROOT_LD=$(losetup -a | grep "${2}" | grep "offset" | sed 's/\(.*\): .*/\1/') echo "Checking partition ${ROOT_LD}" >> "${LOG}" 2>&1 e2fsck -f -y "${ROOT_LD}" >> "${LOG}" 2>&1 @@ -58,7 +62,7 @@ if [ ! -d /mnt/tmp/ ]; then fi echo "Mounting image" >> "${LOG}" 2>&1 # Mount image on temp folder -mount -o loop,offset=64028672 "${IMAGE_DIR}/${2}" /mnt/tmp/ >> "${LOG}" 2>&1 +mount -o loop,offset=${rootOffset} "${IMAGE_DIR}/${2}" /mnt/tmp/ >> "${LOG}" 2>&1 echo "Mounting proc & sys" >> "${LOG}" 2>&1 # Assign proc & sysfs mount proc /mnt/tmp/proc -t proc >> "${LOG}" 2>&1 @@ -68,7 +72,7 @@ cp -r "${DIR}/../../client" /mnt/tmp/usr/src/client >> "${LOG}" 2>&1 echo "${3}" > /tmp/profile.json mv /tmp/profile.json /mnt/tmp/usr/src/client/honeypot_profile.json cp -r "${DIR}/../pipot/services" /mnt/tmp/usr/src/client/pipot >> "${LOG}" 2>&1 -cpuArch=$(python ${DIR}/getCpuArch.py) +cpuArch=$(lscpu | grep Architecture | sed 's/Architecture: *\(.*\)/\1/') if [ $(arch) != arm* ]; then echo "This is not arm machine, copy QemuUserEmulation binary to the chroot" >> "${LOG}" 2>&1 # Copy QemuUserEmulation binary to the chroot @@ -91,7 +95,7 @@ sleep 5 echo "Using fuser to kill any left processes" >> "${LOG}" 2>&1 fuser -k /mnt/tmp >> "${LOG}" 2>&1 echo "Unmount /mnt/tmp" >> "${LOG}" 2>&1 -umount /mnt/tmp >> "${LOG}" 2>&1 +umount -l /mnt/tmp >> "${LOG}" 2>&1 echo "Unmounted, created image should be ready now" >> "${LOG}" 2>&1 echo "100" > "${PROGRESS}" -echo "Total runtime: ${SECONDS}" >> "${LOG}" 2>&1 \ No newline at end of file +echo "Total runtime: ${SECONDS}" >> "${LOG}" 2>&1 diff --git a/install/install.sh b/install/install.sh index 69bd5f1..9cc270c 100755 --- a/install/install.sh +++ b/install/install.sh @@ -147,10 +147,15 @@ ln -s /etc/nginx/sites-available/pipot /etc/nginx/sites-enabled/pipot >> "$insta echo "* Reloading nginx" service nginx reload >> "$install_log" 2>&1 echo "* Downloading base image" -wget https://sourceforge.net/projects/minibian/files/2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1 -tar -xvf 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1 -rm 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1 -mv 2016-03-12-jessie-minibian.img "${dir}/../honeypot_images/base.img" >> "$install_log" 2>&1 +# wget https://sourceforge.net/projects/minibian/files/2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1 +# tar -xvf 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1 +# rm 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1 +# mv 2016-03-12-jessie-minibian.img "${dir}/../honeypot_images/base.img" >> "$install_log" 2>&1 +wget https://downloads.raspberrypi.org/raspbian_lite_latest >> "$install_log" 2>&1 +mv raspbian_lite_latest raspbian_lite_latest.zip +unzip -o raspbian_lite_latest.zip >> "$install_log" 2>&1 +rm raspbian_lite_latest.zip >> "$install_log" 2>&1 +mv *raspbian-stretch-lite.img "${dir}/../honeypot_images/base.img" >> "$install_log" 2>&1 echo "" echo "* Starting PiPot..." service pipot start