From e22a7f16ce334d2f45a7bd6b5cde5e3b158da2e1 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 5 Jan 2025 00:49:40 +0100 Subject: [PATCH] Adapt scripts to podman. Additionally add script which pushes image to registry. --- README.md | 14 +++++++++++++- build.sh | 40 +++++++++++++++++++++++++++++++++++++++- push.sh | 24 ++++++++++++++++++++++++ run.sh | 20 +++++++++++++++++++- shell.sh | 15 ++++++++++++++- 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 push.sh diff --git a/README.md b/README.md index e24ac64..610c141 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# docker-binaryexploitation +# podman-binexp Create a docker container that is purpose-built for binary exploitation using Linux CLI tooling. It is a repeatable build process and I don't need to provision a virtual machine to have all this. It ticks off Docker purists too, which is an added bonus. @@ -15,10 +15,22 @@ Create a docker container that is purpose-built for binary exploitation using Li ## Usage Build the docker container: `./build.sh` +To build and push to the registry: `PUSH=true ./build.sh` Run the docker container: `./run.sh` Get a shell in the container: `./shell.sh` +### Push to registry +Adapt the script `push.sh` to a registry you're logged into and can push to. +Then, to push to with tag "latest": +```base +./push.sh +``` +or, you can add any tag you like +```bash +./push 2025-pwn-time +``` + ## Thanks Thanks to https://github.com/deadbeefmonster/docker-binaryexploitation. Your base repository helped a lot! diff --git a/build.sh b/build.sh index 4250e05..7a5dd71 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,40 @@ #!/bin/sh -docker build -t docker-binaryexploitation:ubuntu23.04 . + +# Static configuration +REGISTRY="gitea.slebba.net" +REPO="seb/podman-binexp-img" +TAG=$(date -u +%Y-%m-%d-%H%M) +PUSH=true # Set to 'true' to push the image after build + +IMAGE="$REGISTRY/$REPO:$TAG" +LATEST_IMAGE="$REGISTRY/$REPO:latest" +echo "Building image: $IMAGE" + +# Ensure Containerfile exists +if [ ! -f Containerfile ]; then + echo "Error: Containerfile not found!" >&2 + exit 1 +fi + +# Build the image +if podman build -t "$IMAGE" -f Containerfile .; then + echo "Build successful: $IMAGE" + + # Tag the image as latest + podman tag "$IMAGE" "$LATEST_IMAGE" + echo "Tagged $IMAGE as $LATEST_IMAGE" + + # Push the image if PUSH is enabled + if [ "$PUSH" = "true" ]; then + echo "Pushing image: $IMAGE and $LATEST_IMAGE" + if podman push "$IMAGE" && podman push "$LATEST_IMAGE"; then + echo "Images pushed successfully: $IMAGE, $LATEST_IMAGE" + else + echo "Failed to push images!" >&2 + exit 1 + fi + fi +else + echo "Build failed!" >&2 + exit 1 +fi diff --git a/push.sh b/push.sh new file mode 100644 index 0000000..0fc4eaf --- /dev/null +++ b/push.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Static configuration +REGISTRY="gitea.slebba.net" +REPO="seb/podman-binexp-img" +TAG=${1:-latest} # Default to 'latest' if no tag is provided + +IMAGE="$REGISTRY/$REPO:$TAG" + +echo "Pushing image: $IMAGE" + +# Check if the image exists locally +if ! podman images | grep -q "$IMAGE"; then + echo "Error: Image '$IMAGE' not found locally!" >&2 + exit 1 +fi + +# Push the image to the registry +if podman push "$IMAGE"; then + echo "Image pushed successfully: $IMAGE" +else + echo "Failed to push image: $IMAGE" >&2 + exit 1 +fi diff --git a/run.sh b/run.sh index d8b6439..c7b8cce 100755 --- a/run.sh +++ b/run.sh @@ -1,2 +1,20 @@ #!/bin/sh -docker run --rm -v "$(pwd)/host:/host" -v "$(pwd)/logs:/logs" --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -d --name docker-binaryexploitation -i docker-binaryexploitation:ubuntu23.04 + +# Static configuration +IMAGE="gitea.slebba.net/seb/podman-binexp-img:latest" # Adjust to the desired image tag +CONTAINER_NAME="pwner" +HOST_DIR="$(pwd)/host" +LOGS_DIR="$(pwd)/logs" + +# Ensure host and logs directories exist +mkdir -p "$HOST_DIR" "$LOGS_DIR" + +# Run the container +podman run --rm \ + -v "$HOST_DIR:/host:z" \ + -v "$LOGS_DIR:/logs:z" \ + --cap-add=SYS_PTRACE \ + --security-opt seccomp=unconfined \ + -d \ + --name "$CONTAINER_NAME" \ + -i "$IMAGE" diff --git a/shell.sh b/shell.sh index 4afe8a3..ec3282d 100755 --- a/shell.sh +++ b/shell.sh @@ -1,2 +1,15 @@ #!/bin/sh -docker exec -it docker-binaryexploitation /bin/bash + +# Name of the running container +CONTAINER_NAME="pwner" + +# Check if the container is running +if podman ps --filter "name=$CONTAINER_NAME" --format "{{.Names}}" | grep -q "^$CONTAINER_NAME$"; then + # Attach interactively to the container + podman exec -it "$CONTAINER_NAME" /bin/bash +else + echo "Error: Container '$CONTAINER_NAME' is not running." >&2 + echo "You can start the container with ./run.sh" + + exit 1 +fi