Skip to content

Commit

Permalink
update base.img with raspbian-lite
Browse files Browse the repository at this point in the history
  • Loading branch information
VertexC committed Jun 5, 2019
1 parent ae5d2b3 commit a113877
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
26 changes: 15 additions & 11 deletions bin/create_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
echo "Total runtime: ${SECONDS}" >> "${LOG}" 2>&1
13 changes: 9 additions & 4 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a113877

Please sign in to comment.