> 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/dom/low.md).

# Low

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

```php
vulnerabilities/xss_d/source/low.php
<?php
​
# No protections, anything goes
​
?> 
```

## Information Gathering <a href="#information-gathering" id="information-gathering"></a>

Jika dilihat dari *source code*-nya, developer belum membuat validasi apa pun, sehingga kita bisa dengan mudah melakukan serangan.

Oke, seperti biasa, pertama-tama kita akan melakukan *recon* terlebih dahulu pada website target. Terdapat menu *select* untuk pemilihan bahasa. Dan jika kita *view source* akan terlihat bahwa pilihan dari menu tersebut menggunakan JavaScript.

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-LzgbM1FuyQgmjmyzl0g%2F-LzgeCvVQFk1Mrpv-Y9H%2Fimage.png?alt=media\&token=0b33b132-4f52-4312-bba1-f53e707024ee)

Singkatnya, fungsi [`document.write()`](https://www.w3schools.com/jsref/met_doc_write.asp) adalah untuk membuat [Document Object Model.](https://www.w3schools.com/js/js_htmldom.asp)​

Perhatikan, form ini menggunakan method `GET` dan menggunakan parameter **default**. Jika kita mencoba melakukan *request* dengan menekan **select**, maka yang kita akses adalah link seperti berikut:

```http
http://172.17.0.2/vulnerabilities/xss_d/?default=English
```

Tetapi apa yang terjadi jika kita membuat mengganti nilai dari parameter **default** tersebut menjadi *"Test"*?

```http
http://172.17.0.2/vulnerabilities/xss_d/?default=Test
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-LzjWm7ooXqMX6HDi6yo%2F-LzjbnynnWelT9UPBVcw%2Fimage.png?alt=media\&token=5c4e8ad7-d671-4646-80ab-5f0fa8b4b74d)

Terlihat bahwa teks tersebut akan ter-*print* di halaman web tersebut.

## Exploit <a href="#exploit" id="exploit"></a>

Sekarang kita akan melakukan *inject* pada parameter tersebut agar menjalankan *script* yang kita inginkan seperti berikut:

```markup
?default=<script>alert("Hacked")</script>
```

Kita sisipkan menjadi link seperti berikut:

```markup
http://172.17.0.2/vulnerabilities/xss_d/?default=<script>alert("Hacked")</script>
```

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-LzjWm7ooXqMX6HDi6yo%2F-LzjdVw7anUVZ7UfmjnA%2Fimage.png?alt=media\&token=feabb4f6-9bea-472e-8cc0-3c4980c58327)

Dan BOOM! *Script* tersebut tampil!

Pada *"kejahatan yang sebenarnya"* peretas akan mengirim link XSS tersebut ke victim untuk menjalankan *script* yang telah ia buat.

Kita jika bisa mendapatkan *cookie* dengan *payload* berikut ini:

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

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-LzjWm7ooXqMX6HDi6yo%2F-LzjdjwGPtgk7CgsoY2q%2Fimage.png?alt=media\&token=ab308fae-37aa-401f-87d4-71c42f0a0f8b)

Jika kalian melihat *view source* , maka kalian tidak akan menemukan *script* tersebut.

![](https://gblobscdn.gitbook.com/assets%2F-LzH5Vfe8_AlGL8KPrs2%2F-M-yraRijg69tsjuWU8U%2F-M-z-BMI__CqDtUp6vEI%2Fimage.png?alt=media\&token=09556b5a-2445-4549-a273-7b4fd1013ab4)

Ini karena *script* tersebut menjadi *Document Object Model* bukan menjadi halaman HTML. Ini lah yang membuatnya sulit untuk dideteksi.

Gimana sampai saat ini sudah mengerti tentang DOM-based XSS? Cukup mudahkan? Coba kita lanjut ke tahap selanjutnya.

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/dom/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.
