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 8, 2019
1 parent ae5d2b3 commit 36a6770
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
24 changes: 13 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,13 @@ 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
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 +60,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 +70,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 +93,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
20 changes: 15 additions & 5 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ echo "* Installing nginx, python & pip "

apt-get -q -y install virtualenv dnsutils nginx python python-dev python-pip >> "$install_log" 2>&1

if [ $(arch) != arm* ]; then
echo "This is not arm machine, install qemu-user-static and binfmt-support for image chroot" >> "${LOG}" 2>&1
apt-get -q -y install qemu qemu-user-static binfmt-support >> "$install_log" 2>&1
fi

if [[ "$OSTYPE" == "linux-gnu" ]]; then
apt-get -q -y install build-essential libffi-dev libssl-dev >> "$install_log" 2>&1
fi
Expand Down Expand Up @@ -95,7 +100,7 @@ fi
server_ip=`dig +short myip.opendns.com @resolver1.opendns.com`
read -e -p "Server IP: " -i "${server_ip}" config_server_ip
read -e -p "Server interface (SSL): " -i "443" config_server_port
read -e -p "Application root (if not a whole (sub)domain, enter the path. None if whole (sub)domain): " -i "'/'" config_application_root
read -e -p "Application root (if not a whole (sub)domain, enter the path. None if whole (sub)domain): " -i "None" config_application_root
read -e -p "Instance name: " -i "PiPot Command & Control" config_instance_name
read -e -p "Path to SSL certificate: " -i "/usr/src/pipot/server/cert/pipot.crt" config_ssl_cert
read -e -p "Path to SSL key: " -i "/usr/src/pipot/server/cert/pipot.key" config_ssl_key
Expand Down Expand Up @@ -147,10 +152,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 36a6770

Please sign in to comment.