DamoNeer@home:~$

ShaktiCon CTF 2021 - pillow | Forensics

pillow

Fix them up and get your flag!

Downloadable: 60x50 zip file that contains three thousand numbered jpg files that are 1 kb each.

Solution

The three thousand files are like the pieces of a puzzle with a 60 x 50 dimension or 50 x 60 dimension (depends on the perspective).

The files are ordered, so that’s nice. However, we need to consider how to place them.

It could be placed in a way that they go from left to right or from up to down. For both scenarios, I have assumed it to start at the top left corner.

I am not super great at Python so I wrote two scripts for this challenge. One for creating a list of tuples for the coordinates and one for looping/pasting each image into its designated positions.

//Python
for x in range (0, 600, 10):
    for y in range (0, 500, 10):
        print ('('+str(x)+','+str(y)+')')

This script will print tuples 3000 times from (0,0) -> (0,10) -> (0, 490) -> (590, 490). This will assume that the puzzle is completed from left to right and the height is 600px.

This script was run four different times since there are two possible orientations and two possible input directions; I simply switched ‘x’/’y’ and ‘600’/500’.

Next, I put each result into its own text document and appended each line to a list four different times.

Then, I converted their string-like tuple into just tuple.

//Python
from PIL import Image

new_im = Image.new('RGB', (60*10, 50*10), (250,250,250))

i = 0
#tuples1 = [(0, 0), (10, 0), (490,0),...(490, 590)]
#tuples2 = [(0, 0), (10, 0), (590, 0),... (590, 490)]
tuples3 = [(0 , 0), (0, 10), (0, 490),...(590, 490)]        <--- Correct choice
#tuples4 = [(0 , 0), (0, 10), (0, 590),...(490, 590)]

#tuples = []
#file = open('version2.txt', 'r')
#lines = file.readlines()
#for line in lines:
#    line = line.strip()
#    tuples.append(line)
#    res = [eval(ele) for ele in tuples]
#    print(res)

while i < 3000:
    string = str(i+1)+'.jpg'
    piece = Image.open(string)
    #print(str(i+1)+": "+str(piece.size))
    new_im.paste(piece, tuples3[i])
    i+=1

new_im.show()

Turns out the puzzle is completed from left to right and it was 600 x 500 (height x width).

flag