> For the complete documentation index, see [llms.txt](https://kos0ng.gitbook.io/ctfs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kos0ng.gitbook.io/ctfs/write-up/2024/hkcert-ctf-quals/binary-exploitation.md).

# Binary Exploitation

<table><thead><tr><th width="347">Challenge</th><th>Link</th></tr></thead><tbody><tr><td>ISH(1) (200 pts)</td><td><a href="#ish-1-200-pts">Here</a></td></tr></tbody></table>

## ISH(1) (200 pts)

### Description

Shell(a.k.a sh) is a text-based interface where users can type commands to interact with the operating system. I'm trying to implement a shell using ISA, I call it ISH.

Note: This challenge is the first part of the ISH fullchain, execute flag1 file in ish to get the flag.

Note: ISH (1), ISH (2) and ISH (3) share the same environment, and it is recommended to solve the ISH fullchain challenges in order.

Note: Here is the [full documentation](https://hackmd.io/@blackb6a/bauhinia-isa) and [ISA interpreter source code](https://github.com/blackb6a/ISA-Engine) if you need more references.

* Challenge: [https://c58a-ish-1.hkcert24.pwnable.hk?id=2](https://c58a-ish-1.hkcert24.pwnable.hk/?id=2)
* Playground: [https://c58b-ish-2.hkcert24.pwnable.hk?id=1](https://c58b-ish-2.hkcert24.pwnable.hk/?id=1)

### Solution

<figure><img src="/files/XRgjgsJIULjrRFWqyYJK" alt=""><figcaption></figcaption></figure>

There is a buffer overflow on URL in curl command. With the overflow we can overwrite the filename for the binary that will be executed by command game. So the idea is to find how to make the curl still valid with the overflow and then overwrite the filename with flag1. Below is my payload

```bash
curl g.co#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaflag1
game
```

Flag:&#x20;


---

# 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://kos0ng.gitbook.io/ctfs/write-up/2024/hkcert-ctf-quals/binary-exploitation.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.
