Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PORT ?= 31345
IMG_NAME ?= challenge07
CONT_NAME ?= $(IMG_NAME)-container

build:
cd .. && docker build -f src/Dockerfile -t $(IMG_NAME) .

run: stop build
docker run -d --rm -p $(PORT):31345 --name $(CONT_NAME) -t $(IMG_NAME)
docker cp $(CONT_NAME):/app/vuln ./vuln

exploit: run
python3 exploit.py

stop:
-docker stop $(CONT_NAME) 2>/dev/null || true
-docker rm -f $(CONT_NAME) 2>/dev/null || true
-rm -f ./vuln 2>/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line isn't required, is it?


clean: stop
@echo "Cleanup complete"

.PHONY: build run exploit stop clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Building and running

**Using the provided Makefile**

Make sure you are in the `sol` directory and run the following commands:

```console
# Build the Docker image
make build

# Run the container and copy the binary
make run

# Execute the exploit
make exploit

# Clean up when finished
make clean
```

The Makefile automates the process of building the Docker image, running the
container, copying the binary and executing the exploit script.
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Makefile automates the process of building the Docker image, running the
container, copying the binary and executing the exploit script.
The Makefile automates the process of building the Docker image, running the container, copying the binary and executing the exploit script.

One sentence per line.

The `make clean` command will remove all resources when you're done.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Build the Docker image from the correct directory

Check failure on line 2 in chapters/exploitation-techniques/shellcodes/drills/07-challenge-shellcode-on-stack/sol/run.sh

View workflow job for this annotation

GitHub Actions / Checkpatch

WARNING:SPDX_LICENSE_TAG: Missing or malformed SPDX-License-Identifier tag in line 2
cd ..
docker build -f src/Dockerfile -t challenge07 .

# Run container in background
docker run -d --name challenge07 -p 31345:31345 challenge07

# Copy the binary from the container for local analysis
docker cp challenge07:/app/vuln sol/vuln

# Navigate to the sol directory and run the exploit
cd sol
python3 exploit.py

# Cleanup: Remove the local copy of the binary and stop the container
rm -f vuln
docker stop challenge07
docker rm -f challenge07

Check failure on line 19 in chapters/exploitation-techniques/shellcodes/drills/07-challenge-shellcode-on-stack/sol/run.sh

View workflow job for this annotation

GitHub Actions / Checkpatch

WARNING:MISSING_EOF_NEWLINE: adding a line without newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ending newline.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Build Stage
FROM gcc AS builder
WORKDIR /build

# Copy only the content from the src directory
COPY src/ .

RUN make

# Runtime Stage
FROM python:3.9-slim
WORKDIR /app

RUN apt-get update && \
apt-get install -y --no-install-recommends binutils cpp && \
rm -rf /var/lib/apt/lists/* && \
pip install --no-cache-dir pwntools

ENV TERM=xterm

COPY --from=builder /build/vuln /app/vuln
COPY sol/exploit.py /app/exploit.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you copy the exploit?


# Expose port 31345
EXPOSE 31345

# Run the vulnerable binary
CMD ["/app/vuln"]