PicoCTF Writeup – fixme2.py
# Information:
CTF Name: PicoCTF
CTF Challenge: fixme2.py
Challenge Category: General Skills
Challenge Points: 100
Beginner picoMini 2022.
# Used Tools:
- Python3
# Challenge Description:
Fix the syntax error in the Python script to print the flag. Download Python script
Hints:
# Writeup:
This is a challenge to help learn how to read python code.
As you probably know, in most programming languages to check if 2 values are equal you have to use the symbol ‘==’ and to assign a value to a variable you have to use ‘=’.
Below you have the python3 code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import random def str_xor(secret, key): #extend key to secret length new_key = key i = 0 while len(new_key) < len(secret): new_key = new_key + key[i] i = (i + 1) % len(key) return "".join([chr(ord(secret_c) ^ ord(new_key_c)) for (secret_c,new_key_c) in zip(secret,new_key)]) flag_enc = chr(0x15) + chr(0x07) + chr(0x08) + chr(0x06) + chr(0x27) + chr(0x21) + chr(0x23) + chr(0x15) + chr(0x58) + chr(0x18) + chr(0x11) + chr(0x41) + chr(0x09) + chr(0x5f) + chr(0x1f) + chr(0x10) + chr(0x3b) + chr(0x1b) + chr(0x55) + chr(0x1a) + chr(0x34) + chr(0x5d) + chr(0x51) + chr(0x40) + chr(0x54) + chr(0x09) + chr(0x05) + chr(0x04) + chr(0x57) + chr(0x1b) + chr(0x11) + chr(0x31) + chr(0x5f) + chr(0x51) + chr(0x52) + chr(0x46) + chr(0x00) + chr(0x5f) + chr(0x5a) + chr(0x0b) + chr(0x19) flag = str_xor(flag_enc, 'enkidu') # Check that flag is not empty if flag = "": print('String XOR encountered a problem, quitting.') else: print('That is correct! Here\'s your flag: ' + flag) |
After a quick read, I could find in line 22 that there is an equal sign missing.
You could also find out the line of the error by running:
After fixing the problem, the program worked fine.
And the flag is:
Code scripts:
If you want to checkout the code for the python 3 script with me solution, take a look here.
Thank you very much for reading!
Cheers,
MRegra