본문 바로가기

ctf

[DEFCON 2018 CTF] ELF Crumble

처음에 정상적으로 동작하지 않는 바이너리와 파일명이 "fragment~" 인 8개의 파일이 제공된다.

파일명으로 미루어보아 fragment 파일들을 이용해 정상적으로 동작시켜야 하는 것임을 추측할 수 있다.

 

직접 fragment 파일을 디어셈블하여 순서를 각각 맞춰 동작시킬 수도 있지만, 

파이썬의 itertools 모듈을 이용하면 이러한 작업을 훨씬 쉽게 수월하게 할 수 있다.

 

itertools 에서 permutations() 를 이용해 순열을 만들 수 있다.

모든 순열의 바이너리를 생성하여 실행하는 코드를 짜고 결과 값을 출력하도록 하면 플래그가 나온다..

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import itertools
import subprocess
 
file = "FINDFLAG"
 
# read the excutable
broken = open("broken""rb")
bin  = broken.read()
 
broken.close()
 
bin = bin.split('X'*807)
 
if len(broken_list) != 2:
    print "ERROR: binary incorrectly"
 
 
bin_1 = bin[0]
bin_2 = bin[1]
 
fragments = []
 
for i in xrange(19):
 
    frag = open("fragment_" + str(i)+ ".dat""rb")
    fragments.append(frag.read())
 
    frag.close()
 
for order in itertools.permutations(fragments):
 
    order = "".join(order)
 
    f = open(file"wb")
    f.write(bin_1 + bin_2 + fragments)
    f.close()
 
    try:
        res = subprocess.check_output([file], shell=True)
        print res
 
    except:
        continue
 
cs

 

'ctf' 카테고리의 다른 글

[Codegate 2018 CTF] Super Marimo  (0) 2018.02.08
[Codegate 2018 CTF] RedVelvet  (0) 2018.02.08
[Codegate 2018 CTF] BaskinRobins31  (0) 2018.02.08
[BKP 2016 CTF] cookbook  (0) 2017.06.01
[HUST 2017 CTF] pwnable writeup  (0) 2017.06.01