# Medium

| Problem         | Difficulty |
| --------------- | ---------- |
| Forbidden paths | Medium     |
| Login           | Medium     |
| Matchtheregex   | Medium     |
| More sqli       | Medium     |
| Soap            | Medium     |

{% stepper %}
{% step %}

### Forbidden Paths <a href="#forbidden-paths" id="forbidden-paths"></a>

> **Description**
>
> Can you get the flag?We know that the website files live in `/usr/share/nginx/html/` and the flag is at `/flag.txt` but the website is filtering absolute file paths. Can you get past the filter to read the flag?Here's the [website](http://saturn.picoctf.net:63193/).

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FIbqN9K2GK9ulpW0dlMGe%2Fimage.png?alt=media&#x26;token=0afe7129-4f4c-41ad-9018-10d16c2ad7e7" alt=""><figcaption></figcaption></figure>

seems like it was a page to read files so knowing that my mind was telling me what if we could do path traversal so i tried reading ../../../../../flag.txt

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FktZZuGgh2PEgod7zYgHG%2Fimage.png?alt=media&#x26;token=9746cc9e-341f-4dfc-8cc2-f323e217f9d5" alt=""><figcaption></figcaption></figure>

easy solve :smile:
{% endstep %}

{% step %}

### Login

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FC0D1M1hAZgrj7MKQpHCy%2Fimage.png?alt=media&#x26;token=60d9f40d-a93c-4b4d-beb6-e84d2d9491ee" alt=""><figcaption></figcaption></figure>

When enumerating the page source i found something interesting

{% code overflow="wrap" %}

```javascript
(async()=>{await new Promise((e=>window.addEventListener("load",e))),document.querySelector("form").addEventListener("submit",(e=>{e.preventDefault();
const r={u:"input[name=username]",p:"input[name=password]"},t={};
for(const e in r)
t[e]=btoa(document.querySelector(r[e]).value).replace(/=/g,"");
return"YWRtaW4"!==t.u?alert("Incorrect Username"):
"cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ"!==t.p?alert("Incorrect Password"):
void alert(`Correct Password! Your flag is ${atob(t.p)}.`)}))})();
```

{% endcode %}

you can see that it checks if the username is `YWRtaW4`in base64 it translates to admin

<div data-full-width="true"><figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2F7KJtDKu9ShbW7eCF51b2%2Fimage.png?alt=media&#x26;token=17d0c780-89b6-4d6d-8d83-db047b5450a4" alt="" width="514"><figcaption></figcaption></figure></div>

after we gain the username and password we can login and get the flag :thumbsup:
{% endstep %}

{% step %}

### Match the regex

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FHfVhRmdnZLJZ8r4wIrDl%2Fimage.png?alt=media&#x26;token=0e9dd4dc-6524-460c-9240-2c57a57ef25e" alt=""><figcaption></figcaption></figure>

after enumerating the page source code&#x20;

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FF0Srripj9BteXmTAKUaQ%2Fimage.png?alt=media&#x26;token=032383a9-6d03-401f-8ad7-e3f19406960c" alt=""><figcaption></figcaption></figure>

we found a function that just so happens to have a suspicious comment im pretty sure that means we can submit anything that starts with p and has any element per dot then ends with F

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2Fm3tsNXdpiEhMatfrQqfb%2Fimage.png?alt=media&#x26;token=e668d2b7-cf64-4539-990a-ff62ad33431c" alt=""><figcaption></figcaption></figure>

easily solved :smile:
{% endstep %}

{% step %}

### More sqli

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FDfZDl7BxGRNfgFJiuOGc%2Fimage.png?alt=media&#x26;token=4fe768b0-0aac-419f-810b-1b9f2c8ea83a" alt=""><figcaption></figcaption></figure>

when i try to login with random creds

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FOUOuiuBJNHavm7UOHG6e%2Fimage.png?alt=media&#x26;token=90981b5f-4431-48cd-82b3-224d2e4fdf8d" alt=""><figcaption></figcaption></figure>

the website actually shows the sql query that it did so this challenge becomes very easy!

we can just use&#x20;

```
' or 1=1 --
```

to bypass the login

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FiIGXFFwQsr1ZGoNqa3zT%2Fimage.png?alt=media&#x26;token=5f94a421-b894-4e3f-88aa-e83db4ecfc45" alt="" width="388"><figcaption></figcaption></figure>

the challenge is not over yet!

we got another website now where could that flag be :thinking:

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2Ff2jBYQf1jC5HPIU01rZU%2Fimage.png?alt=media&#x26;token=0cae2420-c5b4-4f0f-a9e7-b71c5f0cbf7c" alt=""><figcaption></figcaption></figure>

anything familiar?

yup we solved the challenged very easily :sunglasses:
{% endstep %}

{% step %}

### Soap&#x20;

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FufuHCHNo6orHzhyMsqyq%2Fimage.png?alt=media&#x26;token=e1dfdc45-7094-416b-81bb-22b66e7e61cd" alt="" width="507"><figcaption></figcaption></figure>

while casually playing around with the website i found something interesting

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2Fmkw3qNAqLKA7o2Rgwe2O%2Fimage.png?alt=media&#x26;token=112dde81-494a-4c09-8bc8-d7e936b6b0af" alt=""><figcaption></figcaption></figure>

the website seems to use xml after studying about xml i suspected that the website might be vulnerable to XXE injection

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [
  <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<data>
  <ID>&xxe;</ID>
</data>
```

<figure><img src="https://2781327171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMuMceEGBvWN37BjlZKgv%2Fuploads%2FdrRDiKspHfVWECOPn4BV%2Fimage.png?alt=media&#x26;token=734aac75-9e60-451b-ad70-4d995d495651" alt=""><figcaption></figcaption></figure>

Solved the challenge easily again :laughing:
{% endstep %}
{% endstepper %}
