본문 바로가기
# write-up/- ctf

[DEFCON 2017] witchcraft

by ddddh 2017. 5. 2.

DEFCON 2017 - CrackMe - witchcraft



역시 수 많은 바이너리가 존재한다.




역시 아무 바이너리를 킹갓툴 IDA로 분석한다. 


함수 목록을 살펴보다 보면 비슷하게 생긴 수상한 함수들이 여러 개 존재한다. 



계단인 줄...


더 자세히 보면 RDI 레지스터 값을 더하고, 빼고 하다가 마지막에 어떠한 값으로 비교를 한다.




흠흠,, 수상하니 소스를 짜서 값을 빼와보자!



소스 :


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
45
46
47
48
import os
import struct
 
for root,dirs, files in os.walk(r"C:\Users\ddddh\Desktop\Defcon\witchcraft_dist"):
    for file_name in files:
        file = open("C:\\Users\\ddddh\\Desktop\\Defcon\\\\"+file_name, "rb")
 
        data = file.read()[0x2120:]
        index = data.find("\x55\x48\x89\xe5\x48\x85\xff")
        index_ = data[index:].find("\x0f\x0b\x0f\x0b")
 
        input_ = ""
        for x in range(150):
            tmp = data[index:index_]
            if tmp.find("\xbf"+chr(x)+"\x00\x00\x00"== -1:
                break
            if tmp.find("\x48\x81\xff"!= -1:
                chrr = struct.unpack("<B", tmp[tmp.find("\x48\x81\xff")+3])[0]
            elif tmp.find("\x48\x83\xff"!= -1:
                chrr = struct.unpack("<B", tmp[tmp.find("\x48\x83\xff")+3])[0]
 
            #print hex(chrr & 0xff) 
            index__ = 0
            while(1):
                plus = tmp[index__:].find("\x48\x83\xc7")
                minus = tmp[index__:].find("\x48\x83\xef")
 
                #print plus, minus
                if plus == -1 and minus == -1:
                    break
                if (plus < minus and plus != -1or (minus == -1):
                    #print "plus ", struct.unpack("<B", tmp[index__+plus+3])[0]
                    chrr -= struct.unpack("<B", tmp[index__+plus+3])[0]
                    index__ += (plus+4)
                elif (minus < plus and minus != -1or (plus == -1):
                    #print "minus ", struct.unpack("<B", tmp[index__+minus+3])[0] 
                    chrr += struct.unpack("<B", tmp[index__+minus+3])[0
                    index__ += (minus+4)
            input_ += chr(chrr & 0xff)
            #print input_
            index += data[index+8:].find("\x55\x48\x89\xe5\x48\x85\xff"+ 8 
            if index == -1:
                break
            index_ = index + data[index:].find("\x0f\x0b\x0f\x0b")
 
        print file_name + " : " + input_
        file.close()
 
cs


아웃풋:




'# write-up > - ctf' 카테고리의 다른 글

[DEFCON 2017] - pegem  (2) 2017.05.10
[Plaid CTF 2017] zamboni  (0) 2017.05.02
[DEFCON 2017] sorcery  (0) 2017.05.02
[DEFCON 2017] alchemy  (0) 2017.05.02
[Plaid CTF 2017] no_mo_flo  (0) 2017.04.27