> For the complete documentation index, see [llms.txt](https://thamizhiniyancs.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thamizhiniyancs.gitbook.io/writeups/overthewire/natas/level-9-level-10.md).

# Level 9 - Level 10

```
Username: natas10
Password: D44EcsFkLxPIkAAKLosx8z3hxX1Z4MCE
URL:      http://natas10.natas.labs.overthewire.org
```

## Overview

Again an input field with a link to the source code.

<figure><img src="https://1858660820-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrGZ5yoqZSj85T6vq2w3c%2Fuploads%2FUjJxv00hVzCERkKq8PZw%2Fimage.png?alt=media&amp;token=b4ffa429-5552-4d3f-84d8-4ad88b515c6e" alt=""><figcaption></figcaption></figure>

***

## Source Code Analysis

This time,  the source code logic contains input validation using Regular Expression.

<figure><img src="https://1858660820-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrGZ5yoqZSj85T6vq2w3c%2Fuploads%2Fo8sKscuUR4xJF1sQx9Od%2Fimage.png?alt=media&amp;token=d4e2643b-6241-4aa4-b63d-580c1a690346" alt=""><figcaption></figcaption></figure>

Breaking down the RegExp pattern:

<figure><img src="https://1858660820-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrGZ5yoqZSj85T6vq2w3c%2Fuploads%2FL6X8odKyvM3iwbLpr0TS%2Fimage.png?alt=media&amp;token=f8e42d00-5c02-4bed-85a6-4f8751bf9582" alt=""><figcaption></figcaption></figure>

This time also, the input field is vulnerable to command injection, since the input is directly substituted in the command. But this time we have to bypass the input validation.

Grep will return the entire content if we give an empty string ( "" ) as a filter. We can leverage this feature to bypass the validation by using the payload: `"" /etc/natas_webpass/natas11 #`.

If we give the above payload as the input the resultant command on the server would be:

`grep -i "" /etc/natas_webpass/natas11 #`` `~~`dictionary.txt`~~

where:

* `/etc/natas_webpass/natas11` - location of the password file.
* `#` is used to comment out the remaining command ( [PHP Comments](https://www.w3schools.com/php/php_comments.asp) )

Direct link to solution: <http://natas10.natas.labs.overthewire.org/?needle=+%22%22+%2Fetc%2Fnatas_webpass%2Fnatas11+%23&submit=Search>

<figure><img src="https://1858660820-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrGZ5yoqZSj85T6vq2w3c%2Fuploads%2FpMEY17RYoZ3RCrRGhXkm%2Fimage.png?alt=media&amp;token=0f658520-7e91-490b-baa1-aaffa8a2c17e" alt=""><figcaption></figcaption></figure>
