# htaccess

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FRBfsjfZkZCjq9jqkCRP7%2Fimage.png?alt=media&#x26;token=ba9d1304-b5b5-47ce-a51d-2e788eb9f90d" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FQzFDurAQpeJ8vBQBawWH%2Fimage.png?alt=media&#x26;token=2ceacfd7-b0f3-41a1-a5c1-f477403efb6f" alt=""><figcaption></figcaption></figure></div>

The site tells us that there are `.htaccess files` that configure the permissions for `/one/flag.txt` and `/two/flag.txt`.

### <mark style="color:blue;">First Part of the Flag:</mark>&#x20;

The .htaccess file for **`/one/flag.txt`** looks like this:

> ```apacheconf
> RewriteEngine On
> RewriteCond %{HTTP_HOST} !^localhost$
> RewriteRule ".*" "-" [F]
> ```

That tells us if the Host header does not match the string **'localhost'** the request is rewritten to be forbidden. Luckily we can simply set the Host header in our request to a value of our choice. Why not use **'localhost'** then:

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FSB9SKQdHIWA5maT01sNa%2Fimage.png?alt=media&#x26;token=e29be39f-22f0-491c-9254-fc585f556a70" alt=""><figcaption></figcaption></figure></div>

### <mark style="color:blue;">Second Part of the Flag:</mark>

Let's examine the second .htaccess file:

> ```apacheconf
> RewriteEngine On
> RewriteCond %{THE_REQUEST} flag
> RewriteRule ".*" "-" [F]
> ```

This has a similar structure but contains a server variable: 'THE\_REQUEST. [Official apache documentation](https://httpd.apache.org/docs/current/mod/mod_rewrite.html) states:

```
THE_REQUEST
    The full HTTP request line sent by the browser to the server (e.g., "GET /index.html HTTP/1.1"). This does not include any additional headers sent by the browser. This value has not been unescaped (decoded), unlike most other variables below.
```

This means we are not allowed to request anything that has the string 'flag' in it. Thus we simply replace the 'flag' part of the url by an URL encoded string

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F3V1YwO2sLyYAHvPvQOnM%2Fimage.png?alt=media&#x26;token=704ec8c8-3dfa-41e2-898a-523a53947277" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FXljuHwsNCjtpywwPgIOJ%2Fimage.png?alt=media&#x26;token=d749ac37-b1f0-451a-a136-965650d9ae99" alt=""><figcaption></figcaption></figure></div>

### <mark style="color:red;">Full Flag</mark>

```
uctf{Sule_Dukol_waterfall}
```
