> For the complete documentation index, see [llms.txt](https://ir0nstone.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ir0nstone.gitbook.io/notes/binexp/stack/exploiting-over-sockets/socat.md).

# Socat

`socat` is a "multipurpose relay" often used to serve binary exploitation challenges in CTFs. Essentially, it transfers `stdin` and `stdout` to the socket and *also* allows simple forking capabilities. The following is an example of how you could host a binary on port `5000`:

```
socat tcp-l:5000,reuseaddr,fork EXEC:"./vuln",pty,stderr
```

Most of the command is fairly logical (and the rest you can look up). The important part is that in this scenario we don't have to [redirect file descriptors](/notes/binexp/stack/exploiting-over-sockets.md), as `socat` does it all for us.

What **is** important, however, is `pty` mode. Because `pty` mode allows you to communicate with the process as if you were a user, it takes in input literally - **including DELETE characters**. If you send a `\x7f` - a `DELETE` - it will **literally** delete the previous character (as shown shortly in my [*Dream Diary: Chapter 1*](https://ir0nstone.gitbook.io/hackthebox/challenges/dream-diary-chapter-1/unlink-exploit#moving-to-remote) writeup). This is incredibly relevant because in 64-bit the `\x7f` is almost always present in glibc addresses, so it's not quite so possible to avoid (although you *could* keep rerunning the exploit until the rare occasion you get an `0x7e...` libc base).

To bypass this we use the `socat` `pty` escape character `\x16` and prepend it to any `\x7f` we send across.


---

# 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://ir0nstone.gitbook.io/notes/binexp/stack/exploiting-over-sockets/socat.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.
