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,21 @@
# Build stage
FROM gcc:latest AS build

WORKDIR /app
COPY vuln.c .
COPY binsh_shellcode.nasm .
COPY Makefile.sol .
RUN apt-get update && apt-get install -y nasm binutils
RUN make -f Makefile.sol

# Runtime stage
FROM debian:bullseye-slim
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a blank line after FROM line.


WORKDIR /app
COPY --from=build /app/vuln .
COPY --from=build /app/binsh_shellcode.bin .

# Expose port 31344 for external connections
EXPOSE 31344
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a blank line after EXPOSE line.


CMD ["/app/vuln"]
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
CFLAGS = -Wall -fno-stack-protector -g -fno-PIC
LDFLAGS = -no-pie
PORT ?= 31344
IMG_NAME ?= challenge06
CONT_NAME ?= $(IMG_NAME)-cnt

.PHONY: all clean
build:
docker build -t $(IMG_NAME) -f Dockerfile .

all: vuln binsh_shellcode.bin
run: build
docker run -d --rm -p $(PORT):31344 --name $(CONT_NAME) -t $(IMG_NAME)

vuln: vuln.o
$(CC) $(LDFLAGS) $< -o $@
exploit:
python3 exploit.py

vuln.o: vuln.c
$(CC) $(CFLAGS) -c $< -o $@
@# We need an executable .bss
objcopy --set-section-flags .bss=code,alloc,data $@
stop:
-docker stop $(CONT_NAME)

binsh_shellcode.bin: binsh_shellcode.nasm
nasm $< -o $@


clean:
clean: stop
-docker rm $(CONT_NAME)
-rm -f vuln *.o binsh_shellcode.bin

.PHONY: build run stop clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CFLAGS = -Wall -fno-stack-protector -g -fno-PIC
LDFLAGS = -no-pie

.PHONY: all clean

all: vuln binsh_shellcode.bin

vuln: vuln.o
$(CC) $(LDFLAGS) $< -o $@

vuln.o: vuln.c
$(CC) $(CFLAGS) -c $< -o $@
@# We need an executable .bss
objcopy --set-section-flags .bss=code,alloc,data $@

binsh_shellcode.bin: binsh_shellcode.nasm
nasm $< -o $@

clean:
-rm -f vuln *.o binsh_shellcode.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Building and running

Here is how to use the provided Makefile:

- **Build the Docker image and compile binaries:**

```console
make build
```

- **Run the container:**

```console
make run
```

- **Stop the running container:**

```console
make stop
```

- **Run the exploit script:**

```console
make exploit
```

- **Clean up container state:**

```console
make clean
```