Skip to content

Commit

Permalink
kernelCTF: add local runner
Browse files Browse the repository at this point in the history
  • Loading branch information
koczkatamas committed Oct 9, 2023
1 parent 0db1d83 commit 80f0262
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernelctf/simulator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releases/
ramdisk*.img
rootfs*.img
qemu*.sh
flag
40 changes: 40 additions & 0 deletions kernelctf/simulator/local_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
set -e

usage() {
echo "Usage: $0 <release-name> [--root]";
exit 1;
}

INIT_FN="/home/user/run.sh"

ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
--root) INIT_FN="/bin/bash"; shift;;
-*|--*) echo "Unknown option $1"; exit 1;;
*) ARGS+=("$1"); shift;;
esac
done
set -- "${ARGS[@]}"

RELEASE_NAME="$1"
if [ -z "$RELEASE_NAME" ]; then usage; fi

if [ ! -f "qemu_v2.sh" ]; then wget https://storage.googleapis.com/kernelctf-build/files/qemu_v2.sh; fi
chmod u+x qemu_v2.sh

if [ ! -d "releases/$RELEASE_NAME" ]; then mkdir -p "releases/$RELEASE_NAME"; fi
if [ ! -f "releases/$RELEASE_NAME/bzImage" ]; then
wget -O "releases/$RELEASE_NAME/bzImage" "https://storage.googleapis.com/kernelctf-build/releases/$RELEASE_NAME/bzImage"
fi

if [ ! -f "rootfs_v1.img" ]; then
wget https://storage.googleapis.com/kernelctf-build/files/rootfs_v1.img.gz
gzip -d rootfs_v1.img.gz
fi

if [ ! -f "ramdisk_v1.img" ]; then wget https://storage.googleapis.com/kernelctf-build/files/ramdisk_v1.img; fi
if [ ! -f "flag" ]; then echo "kernelCTF{example_flag}" > flag; fi

exec ./qemu_v2.sh "releases/$RELEASE_NAME" flag "$INIT_FN"

0 comments on commit 80f0262

Please sign in to comment.