> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/de/web/xss/dom-xss-document-write-with-location-search.md).

# XSS DOM document.write mit location.search

### DOM-XSS in document.write-Senke unter Verwendung der Quelle location.search

Dieses Lab enthält eine XSS-seitige DOM-Schwachstelle in der Tracking-Funktion der Suchanfrage. Die Seite verwendet `document.write` um Daten aus `location.search` in das DOM zu schreiben, das über die URL gesteuert werden kann.

**Beschreibung der Schwachstelle**/ `document.write` wird mit dem `location.search` String ohne Bereinigung aufgerufen. Da die Eingabe direkt aus der URL stammt, kann ein Angreifer HTML/JS in die Seite einschleusen, indem er `location.search`.

<figure><img src="/files/abdbc1691337efd2c8cad37cd40f0f2b7f0efa83" alt=""><figcaption></figcaption></figure>

**Ziel zur Lösung** Führen Sie einen XSS-Angriff auf der DOM-Seite durch, der die `alert()` Funktion beim Laden der Seite aufruft.

**Kommentare/Hinweise**/ Der Code erzeugt etwas wie ein `<img>` Tag, der einen `searchTerms` in Anführungszeichen stehenden Parameter enthält, zum Beispiel:

```html
<img src="/resources/images/tracker.gif?searchTerms=Jordan">
```

<figure><img src="/files/8bf2a584c23dbe4026eaa9e17babd84814356070" alt=""><figcaption></figcaption></figure>

Wenn Sie das `<img>` Tag und die Anführungszeichen schließen, können Sie beliebigen HTML/JS-Inhalt einfügen.

**Beispiele getesteter Payloads (bereitgestellt)**/ Das Tag schließen und HTML einschleusen:

```html
"><h1>hack</h1>
```

<figure><img src="/files/e28df3baf4b89378c35987cea3f1734b3d4b57b1" alt=""><figcaption></figcaption></figure>

Das Tag schließen und ein Skript einschleusen, um `alert`:

```javascript
"><script>alert("xss")</script>
```

<figure><img src="/files/09e387e0b2b39efcfdde3266a3df9a981c5d361c" alt=""><figcaption></figcaption></figure>


---

# 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://hacking-notes.jord4n.pro/de/web/xss/dom-xss-document-write-with-location-search.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.
