メインコンテンツまでスキップ
非公開のページ
このページは非公開です。 検索対象外となり、このページのリンクに直接アクセスできるユーザーのみに公開されます。

[InterKosenCTF 2020] harmagedon

metarin

WTF of the large data! Enclose the flag with KosenCTF

解説

Ghidraで解析したコードを元に同じような動作のプログラムをPythonで書き直すとこうなる

ans = 0b101101110111110001111100

s = #sym.buf 長いので省略

n = 0
for _ in range(11):
c = input('which is your choice? [%s]' % s[n:n+4])
p = s[n:n+4].find(c)
if p == -1:
print("invalid choice")
exit()
n = (n + p + 1) << 2

if n == ans:
print('congratz. your choices are the flag')
else:
print('try harder')

1文字入力するごとに、nに1~4の値を足した後2bitシフトしている

桁上がりしない限り2bitずつ順に見るだけで入力を確定できる また、桁上がりも上の桁から1引くだけで対応できる

ソルバはこちら

#!/usr/bin/env python3
ans = 0b101101110111110001111100

s = open('./s.txt', 'r').read()

c = []
n = 0
i = 0
while i < 11:
x = (ans >> (11 - i) * 2 & 0x3)
if x != 0:
c.append([s[n:n+4], x-1])
else:
c[-1][1] -= 1
n = ((n >> 2) - 1) << 2
c.append([s[n:n+4], x-1])

p = s[n:n+4].find(c[-1][0][c[-1][1]])
if p == -1:
print("invalid choice")
exit()
n = (n + p + 1) << 2
print(bin(n))
i += 1

if n == ans:
print('congratz. your choices are the flag')
else:
print('try harder')

flag = ""
for l, i in c:
flag += l[i]

print("KosenCTF{%s}" % flag)

KosenCTF{Ruktun0rDi3}

平沢進してますね