Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
misc/pyjail-1 (#67)
Browse files Browse the repository at this point in the history
* chall

* fixes

Co-authored-by: mud-ali <[email protected]>
  • Loading branch information
Jack-Crowley and mud-ali authored Jun 3, 2024
1 parent 1cbd895 commit af5fc5e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pyjail-1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM gcc:14-bookworm AS builder

RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/* \
&& wget -O ynetd.c https://raw.githubusercontent.com/johnsonjh/ynetd/master/ynetd.c \
&& gcc -o ynetd ynetd.c && rm ynetd.c && chmod +x ./ynetd

FROM python:3.12-slim-bookworm AS runtime

WORKDIR /app

COPY --from=builder /ynetd /app/ynetd

COPY flag.txt /app/flag.txt
COPY deploy.py /app/deploy.py

EXPOSE 9030

ENTRYPOINT [ "./ynetd", "-p", "9030", "python3 deploy.py 2>&1" ]
20 changes: 20 additions & 0 deletions pyjail-1/chall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: PyJail-1
categories:
- misc
value: 75
flag:
file: flag.txt
description: |-
I cannot get the python file to print the flag, are you able to?
hints:
- How can you access variables in python?
files:
- src: ./deploy.py
dest: main.py
authors:
- Jack
visible: true
deploy:
nc:
build: .
expose: 9030/tcp
15 changes: 15 additions & 0 deletions pyjail-1/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def sanitize(letter):
print("Checking for contraband...")
return any([i in letter.lower() for i in BANNED_CHARS])

BANNED_CHARS = "gdvxftundmnt'~`@#$%^&*-/.{}"
flag = open('flag.txt').read().strip()

print("Welcome to the prison's mail center")
msg = input("Please enter your message: ")

if sanitize(msg):
print("Contraband letters found!\nMessage Deleted!")
exit()

exec(msg)
1 change: 1 addition & 0 deletions pyjail-1/flag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bcactf{PyTH0n_pR0_03ed78292b89c}
11 changes: 11 additions & 0 deletions pyjail-1/solve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This is what `PyJail` problems are built off of, where they restrict inputs, functions, or anything else to make it more challenging to get the flag.

Based off of the banned keys, `gdvxftundmn'~`\``@#$%^&*-/.{}`, there are only a few functions we can use, one of which is the key to solving the problem, `locals`.

`locals` is a function that has reference to all of the local parameters, including the `flag` variable which stores the flag. However, it is not as simple as just printing this out, as the `n` and `t` in `print` is blocked by the sanitizer.

To get around this, we can raise an error with a custom error message.

```py
raise OSError(locals()[chr(102)+chr(108)+chr(97)+chr(103)])
```

0 comments on commit af5fc5e

Please sign in to comment.