Skip to content

Commit

Permalink
safe animation level
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Nov 3, 2024
1 parent 50cb530 commit 0ec410c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions reverse-engineering/cimg-animate/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Okay, the previous level was embarrassing, but those sorts of bugs happen all the time!
We fixed that issue in this level and, because we feel somewhat contrite about the bug, we're giving you the flag again... in an animated cIMG!
Good luck.
26 changes: 26 additions & 0 deletions reverse-engineering/cimg-animate/_0/generate_flag_cimg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/opt/pwn.college/python

import subprocess
import random
import struct
import os

raw_flag_lines = subprocess.check_output("/usr/bin/figlet < /flag", shell=True).split(b"\n")
max_line_length = max(len(line) for line in raw_flag_lines)
flag_lines = [ line.ljust(max_line_length) for line in raw_flag_lines ]

flag_pixels = [ ]
for y,line in enumerate(flag_lines):
for x,c in enumerate(line):
flag_pixels += [ (x, y, c) ]
random.shuffle(flag_pixels)

operations = [ ]
for p in flag_pixels:
operations += [ struct.pack("<HBBBBBBBB", 2, p[0], p[1], 1, 1, 0x8c, 0x1d, 0x40, p[2]) ]
operations += [ struct.pack("<HB", 6, 1) ]
operations += [ struct.pack("<HI", 7, 733_331) ]

img = b"cIMG" + struct.pack("<HBBI", 4, max_line_length, len(flag_lines), len(operations)) + b"".join(operations)
with open("/challenge/the_flag.cimg", "wb") as o:
o.write(img)

0 comments on commit 0ec410c

Please sign in to comment.