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

misc/jailbreak #9

Merged
merged 7 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions jailbreak/chall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: JailBreak
categories:
- misc
value: 75
flag: camp{PYth0n_M4steR_M2!f45}
description: |-
After a recent prison escape due to hidden messages in letters, the facility has tightened security. Can you find a way around these new measures?
hints:
- How can you access variables in python?
files:
- src: ./main.py
authors:
- Jack Crowley
visible: true
Copy link
Member

Choose a reason for hiding this comment

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

TODO: deploy

23 changes: 23 additions & 0 deletions jailbreak/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def sanitize(letter):
print("Checking for contraband...")
return any([i in letter.lower() for i in BANNED_CHARS])

def end():
print("Contraband letters found!\nMessage Deleted!")
exit()

BANNED_CHARS = "gdvxftundmn'~`@#$%^&*-/.{}"
flag = "camp{PYth0n_M4steR_M2!f45}"

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

if sanitize(msg):
end()

try:
x = eval(msg)
if len(x) != len(flag): end()
print(x)
except Exception as e:
print(f'Error occured: {str(e)}; Message could not be sent.')
23 changes: 23 additions & 0 deletions jailbreak/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def sanitize(letter):
print("Checking for contraband...")
return any([i in letter.lower() for i in BANNED_CHARS])

def end():
print("Contraband letters found!\nMessage Deleted!")
exit()

BANNED_CHARS = "gdvxftundmn'~`@#$%^&*-/.{}"
flag = "REDACTED"

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

if sanitize(msg):
end()

try:
x = eval(msg)
if len(x) != len(flag): end()
print(x)
except Exception as e:
print(f'Error occured: {str(e)}; Message could not be sent.')
15 changes: 15 additions & 0 deletions jailbreak/solve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# JailBreak

The `exec` function in python is very dangerous, especially with it executing an input given by the user.
Copy link
Member

Choose a reason for hiding this comment

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

this seems irrelevant, since the eval function is used rather than exec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops i changed it after writing the solve path


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. But since the `flag` has banned characters, we must use `chr()` function with the ascii value of each letter and join them together.

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

Using this input, the flag will be printed out.
Loading