polished exploits

This commit is contained in:
2024-05-10 13:31:29 +02:00
parent f167e20cd4
commit f4494a73cc
9 changed files with 53 additions and 6 deletions

BIN
insomnihack24/misc/.DS_Store vendored Normal file

Binary file not shown.

BIN
insomnihack24/misc/puzzled/.DS_Store vendored Normal file

Binary file not shown.

25
insomnihack24/misc/puzzled/puzzled.py Normal file → Executable file
View File

@@ -1,7 +1,10 @@
#!/Users/cato/Code/Cato447/ctf/insomnihack24/misc/puzzled/.venv/bin/python3
from PIL import Image
import random
import itertools
from pyzbar.pyzbar import decode
import re
def cutPieces(image_path, output_name_scheme):
@@ -10,7 +13,7 @@ def cutPieces(image_path, output_name_scheme):
# Get the size of the image
width, height = original_image.size
assert (width == height)
assert width == height
# Calculate the size of each grid cell
cell_width = width // 3
@@ -60,7 +63,7 @@ def generateQRCodes(topLeft, topRight, bottomLeft, pieces):
i += 1
def decodeQRCode(image_path):
def decodeQRCode(image_path) -> str | None:
image = Image.open(image_path)
# Decode the QR code
@@ -70,8 +73,9 @@ def decodeQRCode(image_path):
if decoded_objects:
# Iterate through all the detected QR codes and print their data
for obj in decoded_objects:
print("Data:", obj.data.decode('utf-8'))
print("Type:", obj.type)
return obj.data.decode("utf-8")
else:
return None
def shuffle3x3GridImage(image_path, output_path):
@@ -80,7 +84,7 @@ def shuffle3x3GridImage(image_path, output_path):
# Get the size of the image
width, height = original_image.size
assert (width == 234 and height == 234)
assert width == 234 and height == 234
# Calculate the size of each grid cell
cell_width = width // 3
@@ -121,6 +125,15 @@ def shuffle3x3GridImage(image_path, output_path):
# cutPieces("puzzledVersion25QRcode.png", "puzzledVersion25QRcode_piece{}.png")
flag_pattern = r"INS{.*}"
pattern = re.compile(flag_pattern)
paths = [f"solutions/possible_qr{i}.png" for i in range(720)]
for path in paths:
decodeQRCode(path)
data = decodeQRCode(path)
if data is None:
continue
possible_flag = pattern.search(data)
if possible_flag:
print(possible_flag.group())
break