> For the complete documentation index, see [llms.txt](https://picoctf2021.haydenhousen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://picoctf2021.haydenhousen.com/binary-exploitation/binary-gauntlet-1.md).

# Binary Gauntlet 1

## Problem

> Okay, time for a challenge. gauntlet nc mercury.picoctf.net 32853

* [Program](https://github.com/HHousen/PicoCTF-2021/blob/master/Binary%20Exploitation/Binary%20Gauntlet%201/gauntlet/README.md)

## Solution

1. Decompile the binary using Ghidra:

   `main` function:

   ```
   undefined8 main(void)

   {
       char local_78 [104];
       char *local_10;
       
       local_10 = (char *)malloc(1000);
       printf("%p\n",local_78);
       fflush(stdout);
       fgets(local_10,1000,stdin);
       local_10[999] = '\0';
       printf(local_10);
       fflush(stdout);
       fgets(local_10,1000,stdin);
       local_10[999] = '\0';
       strcpy(local_78,local_10);
       return 0;
   }
   ```
2. Alright, so same program as "Binary Gauntlet 0" except the flag is not printed on a crash and the memory address of `local_78` is printed at the beginning of the program.
3. We can write some shellcode to `local_78`, pad out to the return address, and overwrite the return address with the address of `local_78` that is printed at the beginning.
4. Run the solution [script](https://github.com/HHousen/PicoCTF-2021/blob/master/Binary%20Exploitation/Binary%20Gauntlet%201/script.py) and then run `cat flag.txt` to get the flag.

### Flag

`c6e16a1b4182c2801ed657d4c482af88`


---

# 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:

```
GET https://picoctf2021.haydenhousen.com/binary-exploitation/binary-gauntlet-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.
