Skip to content

Commit

Permalink
add ubuntu24.04 target
Browse files Browse the repository at this point in the history
Signed-off-by: gbionescu <[email protected]>
  • Loading branch information
gbionescu committed Sep 4, 2024
1 parent b4e70cf commit 24fc638
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions type-ubuntu24.04/init-rootfs.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions type-ubuntu24.04/inside-container.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions type-ubuntu24.04/run-container.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 24fc638

Please sign in to comment.