> For the complete documentation index, see [llms.txt](https://666isildur.gitbook.io/ethical-hacking/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://666isildur.gitbook.io/ethical-hacking/protostar/stack-1.md).

# Stack 1

## About

![](/files/-M7uWdmodOyJ5DwGTcIV)

## Source Code

```c
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
  volatile int modified;
  char buffer[64];

  if(argc == 1) {
      errx(1, "please specify an argument\n");
  }

  modified = 0;
  strcpy(buffer, argv[1]);

  if(modified == 0x61626364) {
      printf("you have correctly got the variable to the right value\n");
  } else {
      printf("Try again, you got 0x%08x\n", modified);
  }
}

```

## Analysing the Source Code

This program is similar to then one in stack0 but with some minor differences. The first one is that this program gets the input as `argv` instead of `stdin`. The second on is that instead of using the `gets` function, it now uses `strcpy`.

Looking at the `strcpy` man page we see that this function copies the string pointed to by source (`argv[1]`) to the buffer pointed to by the destination. Going a little bit further down to the bugs section we can see that if the destination is not large enough, then it is possible to overflow it.

![](/files/-M7uXzSswHsHj4T1ziT7)

The next thing to notice on the program is that `modified` is now compared to `0x61626364`.

Looking at the hints, we already know that we will need to convert this hex value to its ASCII equivalent. But what about the `little endian`?

![](/files/-M7uYrZUmWgUc-YejqdU)

So basically this means the little endian will flip the bytes so that the least significant byte is placed first and the most significant byte places last. If `0x61626364` is big endian, then as little endian it will become `0x64636261`.

If we look on the ASCII table we can see that `"` translates to `dcba`.

![](/files/-M7u_1uUgfyqRNISdtLW)

We can also use python to find out the ASCII values, which comes more in handy if we have bigger value to analyse.&#x20;

![](/files/-M7uagPSs5OP4v7OhliM)

## Solving the Challenge

![](/files/-M7ubOPA7BnSEEz4y4of)
