diff --git a/type-ubuntu24.04/init-rootfs.sh b/type-ubuntu24.04/init-rootfs.sh new file mode 100755 index 0000000..dee74a2 --- /dev/null +++ b/type-ubuntu24.04/init-rootfs.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Create the rootfs and format it +if [[ "$SPARSE" -eq 1 ]]; then + dd if=/dev/zero of="$1" bs=1 count=0 seek=800M > /dev/null +else + dd if=/dev/zero of="$1" bs=1M count=800 > /dev/null +fi +yes | mkfs.ext4 "$1" > /dev/null diff --git a/type-ubuntu24.04/inside-container.sh b/type-ubuntu24.04/inside-container.sh new file mode 100755 index 0000000..51c8814 --- /dev/null +++ b/type-ubuntu24.04/inside-container.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e +### Customize me! +DEBIAN_FRONTEND="noninteractive" apt-get install -y \ + openssh-server \ + openssh-client \ + iproute2 \ + net-tools strace + +# Enable SSH +echo "PermitRootLogin yes" >> /etc/ssh/sshd_config + +# Set password +echo "root:root" | chpasswd + +# Set up serial +systemctl enable getty@ttyS0 +systemctl start getty@ttyS0 + +# Then, copy the newly configured system to the rootfs image: +mkdir /my-rootfs +mount /rootfs.ext4 /my-rootfs + +for d in bin etc lib lib64 root run sbin usr var; do tar c "/$d" | tar x -C /my-rootfs; done +for dir in dev proc run sys var tmp; do mkdir -p /my-rootfs/${dir}; done +umount /my-rootfs + +# All done, exit docker shell +exit diff --git a/type-ubuntu24.04/run-container.sh b/type-ubuntu24.04/run-container.sh new file mode 100755 index 0000000..7c6c9aa --- /dev/null +++ b/type-ubuntu24.04/run-container.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -e +SCRIPT_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" + +# Launch the container +cont_id=$(docker run -td --rm --privileged -v $1:/rootfs.ext4 ubuntu:24.04) + +# Install systemd +docker exec -t "$cont_id" /bin/bash -c "apt-get update && DEBIAN_FRONTEND='noninteractive' apt-get install -y systemd" + +# Restart the container +docker commit "$cont_id" "temp-build-ubuntu" +docker stop "$cont_id" +new_cont_id=$(docker run -td --rm --privileged -v $1:/rootfs.ext4 temp-build-ubuntu /usr/bin/systemd) + +# Run the payload +set +e +docker exec -t "$new_cont_id" /bin/sh -c "`cat $SCRIPT_DIR/inside-container.sh`" + +rval=$? +set -e + +# Stop the container +docker stop "$new_cont_id" +docker rmi -f "temp-build-ubuntu" + +if [[ "$rval" != 0 ]]; then + echo "Error running the payload" + exit 1 +fi \ No newline at end of file