Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
| modul:m183:learningunits:lu10:lu10a [2025/12/27 19:09] – [Types of XSS Attacks] dgaravaldi | modul:m183:learningunits:lu10:lu10a [2026/01/28 16:30] (aktuell) – dgaravaldi | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== LU10a - Cross-Site Scripting | + | ====== LU10a - Cross-Site Scripting ====== |
| - | + | < | |
| - | **Cross-site scripting | + | \\ |
| + | ===== Einleitung ===== | ||
| + | Cross-Site Scripting | ||
| - | A successful | + | Bei XSS wird Script-Code von außen in die aktuelle Webseite injiziert. Damit wird eine Autorisierungsbarriere überschritten, denn Sie können so einer Website vorgaukeln, der eingeschleuste Code sei Ihr eigener. |
| \\ | \\ | ||
| - | \\ | + | ===== Beispiel |
| - | ==== Types of XSS Attacks | + | Ein kleines Beispiel soll dies untermauern. Stellen Sie sich eine simple Gästebuch-Anwendung vor, wie Sie sie in diesem Buch öfters finden. Hier zunächst eine Gästebuch-Datenbank (mit MySQL). |
| - | There are **two major types** of cross-site scripting attacks commonly discussed: | ||
| - | * **Stored XSS (Persistent)** – A malicious script is permanently injected into an application and served to all users. | + | {{: |
| - | * **Reflected XSS (Non-Persistent)** – A malicious script is embedded in a URL or request, then reflected off the web server back to the user’s browser when the link is visited. | + | |
| + | Was passiert aber, wenn Sie HTML-Code eingeben? Dieser Code wird dann ungefiltert ausgegeben. Sie können das Layout des Gästebuches verschandeln, | ||
| - | \\ | + | {{: |
| - | \\ | + | |
| - | ===== What is Stored Cross-Site Scripting ===== | + | |
| + | {{: | ||
| - | To execute a **stored XSS attack**, the attacker must find a vulnerability in a web application where user input is stored without proper validation or escaping. A common example is when a comment field or form accepts HTML input and embeds it directly into pages viewed by other users. | + | Das allein ist ja schon schlimm genug, doch noch übler wird es, wenn statt HTML-Code JavaScript-Code eingeschleust wird. Da gibt es verschiedene Stufen der Grausamkeiten |
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| - | {{stored_xss_example.png?300}} | + | Aus guten Gründen wird dies nicht weiter ausgeführt, |
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| - | **Example**: | ||
| \\ | \\ | ||
| + | ===== XSS-Auditor ===== | ||
| + | Die Gefahr für '' | ||
| + | |||
| + | {{: | ||
| + | |||
| \\ | \\ | ||
| - | ===== Stored XSS Attack — Step by Step ===== | + | ===== Gegenmassnahmen |
| - | 1. The attacker discovers a page with an input field that allows HTML. | + | Wirkungsvoll gegen XSS ist |
| - | 2. They insert malicious JavaScript code into that field. | + | * gründliche Input-Validierung |
| - | 3. The application stores and later serves that code as part of normal content. | + | * Output-Escaping (in PHP mit der Funktion '' |
| - | 4. When other users visit the page, their browser executes the attack script. | + | |
| \\ | \\ | ||
| + | ===== Output-Escaping ===== | ||
| + | Ziel des Output-Escaping ist, dass im Webbrowser die Benutzereingaben niemals als Teil der Seite (d.h. mit deren HTML-Code) ausgeführt werden. Stattdessen werden die Benutzereingaben sozusagen entschärft und wie gewöhnliche Texte als ungefährlicher statischer Inhalt angezeigt. | ||
| + | In PHP wird h | ||
| + | |||
| \\ | \\ | ||
| - | ===== How Stored XSS Endangers Users ===== | + | ===== Beispiel |
| - | Stored XSS is especially dangerous because: | + | Im folgenden Beispiel wird die eigene Funktion '' |
| + | |||
| + | **Code-01: ohne Escaping -> unsicherer PHP-Code** | ||
| + | < | ||
| + | ... | ||
| + | /** | ||
| + | * Liest ein einfaches Textfeld aus dem Formular aus | ||
| + | * @param $feld - Datenfeld, welches ausgelesen wird | ||
| + | * @return string - ausgelesenes Datenfeld als String | ||
| + | */ | ||
| + | function leseFeld($feld) | ||
| + | { | ||
| + | if (!isset($_POST[$feld])) { | ||
| + | return LEER_STRING; | ||
| + | } | ||
| + | if (!is_string($_POST[$feld])) { | ||
| + | return LEER_STRING; | ||
| + | } | ||
| + | return $_POST[$feld]; | ||
| + | } | ||
| + | ... | ||
| + | </ | ||
| - | | + | **Code-02: mit Escaping -> sicherer PHP-Code** |
| - | * Attacker-controlled scripts can steal session credentials or redirect users to phishing sites. | + | < |
| - | * Malicious payloads can embed external JavaScript that reports user data back to the attacker. | + | ... |
| + | /** | ||
| + | * Liest ein einfaches Textfeld aus dem Formular aus | ||
| + | * @param $feld - Datenfeld, welches ausgelesen wird | ||
| + | | ||
| + | */ | ||
| + | function leseFeld($feld) | ||
| + | { | ||
| + | if (!isset($_POST[$feld])) { | ||
| + | return LEER_STRING; | ||
| + | } | ||
| + | if (!is_string($_POST[$feld])) { | ||
| + | return LEER_STRING; | ||
| + | } | ||
| + | return htmlspecialchars($_POST[$feld]); | ||
| + | } | ||
| + | ... | ||
| + | </ | ||
| + | ---- | ||
| - | ===== Related Topics ===== | + | [[https://creativecommons.org/licenses/by-nc-sa/4.0/|{{https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png}}]] Daniel Garavaldi |
| - | [1]: https://www.imperva.com/learn/application-security/ | + | |
| - | [2]: https://www.imperva.com/learn/application-security/ | + | |
| - | [3]: https://developer.mozilla.org/ | + | |