keyboard_arrow_up

title: Writeup ShieldsCTF 2021 - Leonard
date: Jun 05, 2021
tags: ShieldsCTF Writeups Prog


Shields CTF - Leonard

I'm blue, da ba dee da ba daa Da ba dee da ba daa, da ba dee da ba daa

File : moialaplage.txt

In this file we can see that we've got a bunch of instructions that looks like that :

R = 75, G = 98, B = 46 
R = 66, G = 89, B = 37 
R = 71, G = 94, B = 40 
R = 82, G = 105, B = 51 
R = 87, G = 108, B = 52 
R = 91, G = 112, B = 56 
R = 94, G = 113, B = 57 
R = 88, G = 105, B = 50 

As soon as I saw the content of the file, I saw pixel colors with the 3 values Red Yellow and Green.

So I started by removing the unnecessary instructions: R = , G = and B =. To keep only the values

sed -i -e 's/R = //g' moialaplage.txt;sed -i -e 's/ G = //g' moialaplage.txt;sed -i -e 's/ B = //g' moialaplage.txt 

output:

75,98,46 
66,89,37 
71,94,40 
82,105,51 
87,108,52 
91,112,56 
94,113,57 
88,105,50

Now that I've isolated all the pixel values, all that's left is to code in python a way to display them and render them as one image.

from PIL import Image

list_of_pixels = list()
with open('moialaplage.txt', 'r') as file:
    lines = file.readlines()
    for rgb in lines:
        rgb = rgb.replace(' \n','')
        tuples = tuple(map(int, rgb.split(',')))
        list_of_pixels.append(tuples)

image = Image.new('RGB',(1000,1000))
image.putdata(list_of_pixels)
image.show()

leonard-wrong-size

I don't know the dimensions of the image, so I have something that is displayable but it is not readable. I immediately thought I had the right track with the white pixels on the image which for me corresponded to the text of the flag. So I decided to "brute force" the image dimensions to save time. And as soon as something looking like a flag or text is displayed this would be the solution.

from PIL import Image

list_of_pixels = list()
with open('moialaplage.txt', 'r') as file:
    lines = file.readlines()
    for rgb in lines:
        rgb = rgb.replace(' \n','')
        tuples = tuple(map(int, rgb.split(',')))
        list_of_pixels.append(tuples)

for size in range(655360):
    try:
        image = Image.new('RGB',(size,size))
        image.putdata(list_of_pixels)
        image.show()
    except:
        pass

Here we go, after 15 seconds and a few images displayed I have something that is starting to look more like a flag.

leonard-bruteforce

The image is the wrong way round and inverted. A quick photoshop and we've got our flag ! :heart:

leonard-flag

SHIELDS{Gr34t_Pa1nT1ng}