# Medium

Di bawah ini adalah *source-code* dari *command injection* level medium di DVWA.

```php
vulnerabilities/exec/source/medium.php
<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
    // Get input
    $target = $_REQUEST[ 'ip' ];

    // Set blacklist
    $substitutions = array(
        '&&' => '',
        ';'  => '',
    );

    // Remove any of the charactars in the array (blacklist).
    $target = str_replace( array_keys( $substitutions ), $substitutions, $target );

    // Determine OS and execute the ping command.
    if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
        // Windows
        $cmd = shell_exec( 'ping  ' . $target );
    }
    else {
        // *nix
        $cmd = shell_exec( 'ping  -c 4 ' . $target );
    }

    // Feedback for the end user
    echo "<pre>{$cmd}</pre>";
}

?>
```

## Mencari Informasi <a href="#mencari-informasi" id="mencari-informasi"></a>

Terlihat dibaris ke-7 sampai 11, terdapat *blacklist* untuk string `&&` dan `;` pada inputan. Tetapi seperti yang telah di bahas sebelumnya terdapat alternatif lain yaitu `|`. 😁

## Melakukan Serangan <a href="#melakukan-serangan" id="melakukan-serangan"></a>

Cukup ganti inputan menjadi menggunakan tanda `|`, dan hasilnya akan seperti berikut:

{% hint style="info" %}
Jika menggunakan `|` maka hasil dari perintah **ping** tidak akan muncul. Karena pipeline akan melakukan perintah terakhir apabila perintah-perintah sebelumnya tidak terkait atau tidak dapat menjadi input untuk perintah berikutnya.
{% endhint %}


---

# 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://notes.anggipradana.com/tutorial/dvwa/command-injection/medium.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.
