# Hijacking to Shellcode

## Lecture

{% embed url="<https://youtu.be/lsY2g09Hjr0>" %}
Hijacking to Shellcode
{% endembed %}

## Example from the Shellcoding Module

```c
void bye1() { puts("Goodbye!"); }
void bye2() { puts("Farewell!"); }
void hello(char *name, void (*bye_func)())
{
    printf("Hello %s!\n", name);
    bye_func();
}
int main(int argc, char **argv)
{
    char name[1024];
    gets(name);
    srand(time(0));
    if (rand() % 2) hello(bye1, name);
    else hello(name, bye2);
}
```

* **Bug 1:** `hello(bye1, name)` should be `hello(name, bye1)`.
* **Bug 2:** `gets(name)` causes buffer overflow.


---

# 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://ret2basic.gitbook.io/ctfwriteup/web2-ctf/pwn.college/exploitation/hijacking-to-shellcode.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.
