What is this special event ?
#The HackSecuReims organized a special event which called a CTF
(type Jeopardy) but what's it ?
Jeopardy-style CTFs present competitors with a set of questions that reveal clues that guide them in solving complex tasks in a specific order. By revealing clues, contestants learn the right direction regarding techniques and methodologies that are needed going forward.
My team
#With my brothers Alexis LEBEL and Corentin FREIRE, we've participed to this event with name Peignoir'Bros
and we came dressed in bathrobes
.
BECAUSE WE LOVE BATHROBES.
Atmoshpere
#In the room, we were about sixty may be seventy and seperated in team of 3 in table with 6blocks. We helped each other for the most hardest levels, and we've the opportunities to discuss with em and others like organizers.
Challenges
#The most interessant part because it's the heart of CTF. From scanning a qrcode to get a flag to writing a program in rust, this CTF have a huge panel of challenges. I'll expose you twos of em'.
First the GIF problem
.
You have a GIF with a sequence of +1000 frames which itself represents a qrcode. Each frame, when you scanned her, give you one letter from a base64 code which I've to decode him to get the flag. But to have the correct code, I was not going to scan every single frames. So I automatised the code with Python.
1from os import listdir2from PIL import Image3from pyzbar.pyzbar import decode45def get_index(x): #function to sort the list of images6 return(x[6:10])78message = ''9gifs = sorted(listdir('/home/hakka/Downloads/gifs/'), key=get_index)1011for gif in gifs:12 message += decode(Image.open(f'/home/hakka/Downloads/gifs/{gif}'))[0].data.decode('utf-8')1314print(message)
So when this script was executed, he returned to me the base 64 code, so I went to Base 64 Decoder to decode it and get the flag.
The second one was the OCR Reload
.
It was my first approach with OCRs. I spent 3 hours on it ahah but I was happy to pass it.
But what is OCR ? Optical character recognition or optical character reader is the electronic or mechanical conversion of images of typed, handwritten or printed text into machine-encoded text, whether from a scanned document, a photo of a document, a scene-photo or from subtitle text superimposed on an image.
I programmed twos differents codes to pass this challenge. First is with pytesseract whichis specialized in OCR.
1from os import listdir2from PIL import Image3import pytesseract45def get_index(x): #function to sort the list of images6 return(x[6:1O])78message = ''9imgs = sorted(listdir('/home/hakka/Downloads/imgs/'), key=get_index)10config = r'--oem 3 --psm 10' #config needed to OCR11for img in imgs:12 im = Image.open(f'/home/hakka/Downloads/imgs/{img}')13 character = pytesseract.image_to_string(im, config=config)14 message += stri.strip()[0]1516print(message)
The first one worked almost to the excpetion of 2-3 characters that were fighting, so I decided to retry with an another method.
The second one is with the hashes of images. For example if imgs folder contains 2 imgs with a inside, they'll have the same hashes. So I created a code to compare the hashes of images and I stored them in a dict. For doing that, I used ImageHash
1from os import listdir2from PIL import Image3import imagehash45def get_index(x):6 return(x[6:10])78hashes = {} # ex {'a': 'vreveve33klkn2'} key: character, value: hash9message=''10ims = sorted(listdir('/home/hakka/Downloads/imgs/'), key=get_index)11for img in imgs:12 im = Image.open(f'/home/hakka/Downloads/imgs/{img}')13 im_hash = imagehash.dhash(im) # can use phash too1415 if im_hash in hashes.values():16 for key, value in hashes.items():17 if im_hash == value:18 message += key19 break20 else:21 newKey = str(input(f'Enter one key for {img}: '))22 hashes[newKey] = im_hash23 message += newKey2425print(message)
And it's worked. The other challenges was cool too and some were unfortunately impossible because I had not the required skillset.
Conclusion
#Like everyone in this event, I am happy to have been able to participate in such an event. I don't regrets anything. I'm looking forward to next year's and this time coming back much stronger.
Thanks to all.