First, it is packed by upx. so just unpack binary.
then, because of undefined instruction(0F 0B), it starts exception handler.
So, strcmp with "oh_nasty_boy!you_hacked_me:(hehe" is just fake.
exception handler is in 0x4010d0.
At 0x4010d0, insert keys and encode input. and finally compare with another real answer
routine is as follow.
1. exception handler starts
2. insert key to stack
3. xor key with some value in 0x4011C3
4. encode input using key (function 0x401000)
5. compare encoded value to answer
but, I didn't know xor key with what value in third step.
So, it is just brute-force.
script is as follow in python
- from struct import *
- import sys
- key1 = "86DE9AF8DFF585E9DD85EF".decode('hex')
- def encode(data,n):
- global key1
- zero_to_100 = []
- i =0
- while i<0x100:
- zero_to_100.append(i)
- i+=1
- temp_key1 = list(key1)
- temp_key = [chr(ord(i) ^ n) for i in key1]
- calc_key1 = "".join(temp_key)
- i = 0
- v4 = 0
- v8 = 0
- v3 = 0
- while i<0x100:
- v3 += (zero_to_100[i] + ord(calc_key1[i % 0xB]))
- v3 = v3 & 0xFF
- v8 = zero_to_100[i]
- zero_to_100[i] = zero_to_100[v3]
- zero_to_100[v3] = v8
- i+=1
- i=0
- v9 = 0
- v10 = 0
- answer = ""
- while i < 0x20:
- v12 = v10+1
- v17 = v12
- v9 += zero_to_100[v12]
- v9 = v9 & 0xFF
- v13 = zero_to_100[v12]
- v15 = zero_to_100[v9]
- zero_to_100[v12] = v15
- zero_to_100[v9] = v13
- k = zero_to_100[(v13 + v15) & 0xFF]
- answer += chr(ord(data[i]) ^ k)
- v10 = v17
- i+=1
- return answer
- def check(data):
- data = list(data)
- for i in data:
- if ord(i) < 0x20 or ord(i) >= 0x80:
- return False
- return True
- compare = ""
- compare += pack('<L', 0x03C7C8CA)
- compare += pack('<L', 0x1F2810FC)
- compare += pack('<L', 0x948C7F7A)
- compare += pack('<L', 0x2469F92E)
- compare += pack('<L', 0xC1277D9F)
- compare += pack('<L', 0x7F4509C4)
- compare += pack('<L', 0x9745EE75)
- compare += pack('<L', 0x1F79AF8D)
- for n in range(0,0x100):
- xored = encode("1"*32,n)
- key = ""
- for i in xored:
- key += chr(ord(i) ^ ord('1'))
- i=0
- answer = ""
- while i< 32:
- answer += chr(ord(key[i]) ^ ord(compare[i]))
- i+=1
- if check(answer):
- print answer
- sys.exit()
'Computer Security > CTF' 카테고리의 다른 글
[Defcon 2014] HJ(2) byhd write up (31) | 2014.05.19 |
---|---|
[Defcon 2014] 100 lines exploit (0) | 2014.05.19 |
[Codegate 2014 quals] Web 500 write up (0) | 2014.02.24 |
[secuinside 2013] debugd exploit (2) | 2013.11.28 |
[Secuinside 2013] angry danbi exploit (3) | 2013.11.27 |