> For the complete documentation index, see [llms.txt](https://notes.anggipradana.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.anggipradana.com/tutorial/dvwa/cross-site-scripting-xss/stored/low.md).

# Low

Di bawah ini adalah *source-code* dari XSS (Stored) level low di DVWA.

```php
vulnerabilities/xss_s/source/low.php
<?php
​
if( isset( $_POST[ 'btnSign' ] ) ) {
    // Get input
    $message = trim( $_POST[ 'mtxMessage' ] );
    $name    = trim( $_POST[ 'txtName' ] );
​
    // Sanitize message input
    $message = stripslashes( $message );
    $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
​
    // Sanitize name input
    $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
​
    // Update database
    $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
    $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );
​
    //mysql_close();
}
```

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

Terdapat form yang ketika saya coba menginputkan *"test<'>"* , maka hasilnya akan tersimpan di halaman tersebut.

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M-nX-buHPf2O5F5U5ij%2F-M-n_rPIfpysGcPJ5hZC%2Fimage.png?alt=media\&token=4ede71d2-b4b3-44ad-b31b-4219fa87b1b5)

Dari informasi yang bisa kita dapatkan dari *view source*, kita bisa mengetahui bahwa tidak ada validasi untuk HTML spesial karakter di sini, sehingga kita bisa dengan mudah melakukan serangan XSS.

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M-nX-buHPf2O5F5U5ij%2F-M-n_iH5bVKGX6-YSV7C%2Fimage.png?alt=media\&token=e0607b57-3650-4431-be2d-8b19fd1d50f9)

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

Kita coba dengan *payload* yang pertama, yaitu:

```markup
<script>alert('Hacked')</script>
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-LzpgZF_KC4sPanQSj0r%2F-LzptT9P5ahFBIoCh03i%2Fimage.png?alt=media\&token=66363ca0-a30b-4cda-930e-b39b65ede063)

Dan berhasil!😊​

Jika dilihat menggunakan *view source*, maka akan terlihat seperti berikut:

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-LzpgZF_KC4sPanQSj0r%2F-LzptgeOaQqcRi_wPL6o%2Fimage.png?alt=media\&token=6740a9cc-8369-4c7a-acb3-da7d762be6b1)

Seperti biasa kita juga bisa mengambil *cookie* dengan *payload* berikut:

```php
<script>alert(document.cookie)</script>
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-LzpgZF_KC4sPanQSj0r%2F-Lzpu2PDcA8d6B84hqDy%2Fimage.png?alt=media\&token=96d81d3b-6ece-42ef-88ec-58db4106317f)

Yup! Jika halaman ini di-*refresh*, maka *payload* tersebut akan dijalankan lagi karena sekarang *payload* tersimpan (*stored*) pada halaman web tersebut.

Happy Hacking! 🍻


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://notes.anggipradana.com/tutorial/dvwa/cross-site-scripting-xss/stored/low.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
