Skip to content

Instantly share code, notes, and snippets.

@kos0ng
Created February 22, 2021 04:43
Show Gist options
  • Save kos0ng/f20e0d09108f680361753b8924ce8cd9 to your computer and use it in GitHub Desktop.
Save kos0ng/f20e0d09108f680361753b8924ce8cd9 to your computer and use it in GitHub Desktop.
darkCON CTF 2021 - (Not) Easy [ RE ]
import struct
import string
key = [0x34, 0x65, 0x33, 0x30, 0x33, 0x37, 0x35, 0x38, 0x37, 0x38, 0x33, 0x37, 0x33, 0x33, 0x33, 0x34]
key = struct.unpack('<4I', bytes(key))
enc = [
0xef, 0xd0, 0x58, 0x66, 0xa2, 0x12, 0x23, 0x7a, 0x3a, 0x8b, 0x31, 0x66, 0x56, 0x40, 0x79, 0x4e, 0xff, 0x12, 0x6b, 0xa0, 0x29, 0xa0, 0xc5, 0x16, 0x47, 0x80, 0xb5, 0xa1,
0xb8, 0x87, 0xaf, 0x92, 0xb2, 0x39, 0xeb, 0x85, 0xd8, 0x3d, 0x10, 0x09, 0xf7, 0x0f, 0x80, 0x69, 0x77, 0x60, 0xd7, 0x2d, 0x24, 0x49, 0xb3, 0xc9, 0xec, 0x23, 0xcb, 0xdc,
0xa6, 0x94, 0x05, 0x49, 0xca, 0xdd, 0x1d, 0xab, 0x5b, 0x36, 0x63, 0xf6, 0x57, 0xe5, 0x42, 0x43, 0x34, 0xdd, 0xd4, 0x56, 0x36, 0xbe, 0x88, 0xdd, 0x3c, 0xdf, 0x1d, 0x2a
]
enc = [(bytes(enc[i:i+12])) for i in range(0,len(enc),12)]
flag = b""
for block in enc:
count = len(block) // 4
data = list(struct.unpack(f'<{count}I', block))
loop = 0x34 // len(data) + 6
t = 2604932717
for i in range(loop-1,-1,-1):
tmp = (t >> 2) & 3
for j in range(len(data)-1, -1, -1):
prev = data[(j - 1) % len(data)]
next = data[(j + 1) % len(data)]
data[j] -= (((prev >> 5) ^^ (next << 2)) + ((prev << 4) ^^ (next >> 3))) ^^ ((key[(j & 3) ^^ tmp] ^^ prev) + (t ^^ next))
data[j] = data[j] % 2**32
x = int(str(factorial(0x800 + 10*i*i))[:10])
t = (t - x) % 2^32
flag += struct.pack(f'<{len(data)}I', *data)
flag=flag.decode()
result=""
for i in flag:
if(i in string.printable[:-6]):
result+=i
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment