-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: gbionescu <[email protected]>
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |