|
|
| Zeile 1: |
Zeile 1: |
| = HTTP-Protokoll (Hypertext Transfer Protocol) =
| | ==Schwachstellen== |
| | | ===Sprachmodell=== |
| == Überblick == | | * [https://airiskdatabase.com AI Risk Database] – Eine Datenbank mit Risiken und Schwachstellen im Bereich Künstliche Intelligenz. |
| * HTTP ist ein zustandsloses Protokoll zur Übertragung von Hypertext (z. B. HTML) im Internet.
| | * [https://github.com/advisories GitHub CVE & Security Advisories] – Offizielle Sicherheitswarnungen und CVE-Meldungen von GitHub für Open-Source-Projekte. |
| * Client-Server-Modell: Der Client (z. B. Browser) sendet Anfragen, der Server antwortet.
| | * [https://cve.mitre.org/ MITRE CVE Database] – Zentrale Datenbank für öffentlich bekannte Schwachstellen (Common Vulnerabilities and Exposures, CVE). |
| * Jede Anfrage ist unabhängig von vorherigen (stateless).
| | * [https://nvd.nist.gov/ National Vulnerability Database (NVD)] – Die US-amerikanische nationale Datenbank für Schwachstellen, gepflegt vom NIST. |
| | | * [https://www.cvedetails.com/ CVE Details] – Eine benutzerfreundliche Übersicht und Analyse von CVE-Einträgen. |
| == Anfragemodell == | | * [https://www.exploit-db.com/ Exploit Database] – Sammlung von Exploits und Proof-of-Concept-Code für bekannte Schwachstellen. |
| * '''Client Request''': Der Client sendet eine HTTP-Anfrage.
| | * [https://www.securityfocus.com/vulnerabilities SecurityFocus Vulnerability Database] – Archiv von Schwachstellen und Sicherheitsmeldungen. |
| * '''Server Response''': Der Server verarbeitet die Anfrage und antwortet mit Ressourcen oder Fehlermeldungen.
| | * [https://www.openwall.com/lists/oss-security/ Open Source Security (oss-security)] – Mailingliste und Archiv zu Schwachstellen in Open-Source-Software. |
| | | * [https://vuldb.com VulDB] – Community-basierte Schwachstellendatenbank mit aktuellen Informationen und Analysen. |
| == HTTP-Server == | | * [https://www.zerodayinitiative.com/advisories/published/ Zero Day Initiative Advisories] – Veröffentlichte Schwachstellen und Exploits aus dem Zero Day Initiative Programm. |
| '''Definition''': Software, die HTTP-Anfragen verarbeitet und Antworten liefert.
| |
| | |
| '''Beispiele''':
| |
| * Apache HTTP Server | |
| * Nginx
| |
| * Microsoft IIS
| |
| * Kestrel (ASP.NET Core)
| |
| | |
| '''Kestrel''':
| |
| * Cross-Platform Webserver in ASP.NET Core
| |
| * Leichtgewichtig und leistungsfähig
| |
| | |
| == Ablauf von Anfrage und Antwort mit Kestrel ==
| |
| # Client sendet Anfrage
| |
| # Kestrel empfängt und leitet sie an Middleware weiter
| |
| # Middleware verarbeitet Anfrage
| |
| # Anwendung erzeugt Antwort
| |
| # Kestrel sendet Antwort zurück an den Client
| |
| | |
| == Browser & HTTP ==
| |
| * Browser fordern HTML, CSS, JS, Bilder über HTTP an
| |
| * Klick auf Link → HTTP-Request → Server → Response → Darstellung im Browser
| |
| | |
| == HTTP-Anfragen in Chrome Dev Tools beobachten ==
| |
| * Öffnen: F12 oder Ctrl+Shift+I (Cmd+Option+I auf Mac) | |
| * Reiter „Network“ → Details zu:
| |
| ** Headers
| |
| ** Response
| |
| ** Timing
| |
| | |
| == Aufbau einer HTTP-Antwort ==
| |
| '''Format''':
| |
| HTTP/1.1 200 OK
| |
| Content-Type: text/html
| |
| Content-Length: 137
| |
| | |
| <html>
| |
| <body>
| |
| <h1>Hello, World!</h1>
| |
| </body>
| |
| </html>
| |
| | |
| '''Wichtige Header''':
| |
| * Content-Type: Typ der Ressource (z. B. text/html)
| |
| * Content-Length: Größe der Antwort
| |
| * Server: Infos zum Server
| |
| * Set-Cookie: Setzt Cookies im Client
| |
| * Cache-Control: Caching-Strategie
| |
| | |
| == Kestrel Standard-Header ==
| |
| * Content-Type: z. B. text/html, application/json | |
| * Server: „Kestrel“
| |
| * Date: Zeitstempel der Antwort
| |
| | |
| == HTTP-Statuscodes ==
| |
| === Kategorien ===
| |
| * '''1xx''': Information
| |
| * '''2xx''': Erfolg
| |
| * '''3xx''': Weiterleitung
| |
| * '''4xx''': Clientfehler
| |
| * '''5xx''': Serverfehler
| |
| | |
| === Gängige Codes ===
| |
| * 200 OK
| |
| * 201 Created
| |
| * 204 No Content
| |
| * 400 Bad Request
| |
| * 401 Unauthorized
| |
| * 403 Forbidden
| |
| * 404 Not Found
| |
| * 500 Internal Server Error
| |
| * 503 Service Unavailable
| |
| | |
| == ASP.NET Core Codebeispiele ==
| |
| === Beispiel 1: Antwort-Header setzen ===
| |
| <syntaxhighlight lang="csharp">
| |
| var builder = WebApplication.CreateBuilder(args);
| |
| var app = builder.Build();
| |
| | |
| app.Run(async (HttpContext context) =>
| |
| {
| |
| context.Response.Headers["MyKey"] = "my value";
| |
| context.Response.Headers["Server"] = "My server";
| |
| context.Response.Headers["Content-Type"] = "text/html";
| |
| await context.Response.WriteAsync("<h1>Hello</h1>");
| |
| await context.Response.WriteAsync("<h2>World</h2>");
| |
| });
| |
| | |
| app.Run();
| |
| </syntaxhighlight>
| |
| | |
| === Beispiel 2: Statuscode setzen ===
| |
| <syntaxhighlight lang="csharp">
| |
| app.Run(async (HttpContext context) =>
| |
| {
| |
| context.Response.StatusCode = 200;
| |
| await context.Response.WriteAsync("Hello");
| |
| await context.Response.WriteAsync(" World");
| |
| });
| |
| </syntaxhighlight>
| |
| | |
| == HTTP-Request-Aufbau ==
| |
| * '''Startzeile''': Methode, URI, HTTP-Version
| |
| * '''Header''': z. B. User-Agent, Accept, Authorization
| |
| * '''Leerzeile''' | |
| * '''Body (optional)''': z. B. JSON, Formulardaten
| |
| | |
| === Beispiel: GET-Anfrage ===
| |
| GET /products?category=electronics&brand=apple HTTP/1.1
| |
| Host: example.com
| |
| | |
| === Beispiel: POST-Anfrage ===
| |
| POST /login HTTP/1.1
| |
| Host: example.com
| |
| Content-Type: application/x-www-form-urlencoded
| |
| | |
| username=john&password=secret
| |
| | |
| == Query Strings ==
| |
| * Parameter in URL übergeben | |
| * Beispiel:
| |
| https://example.com/products?category=electronics&brand=apple
| |
| | |
| == Zugriff auf Request-Details in ASP.NET Core ==
| |
| === Beispiel: Pfad und Methode auslesen ===
| |
| <syntaxhighlight lang="csharp">
| |
| app.Run(async (HttpContext context) =>
| |
| {
| |
| string path = context.Request.Path;
| |
| string method = context.Request.Method;
| |
| context.Response.Headers["Content-type"] = "text/html";
| |
| await context.Response.WriteAsync($"<p>{path}</p>");
| |
| await context.Response.WriteAsync($"<p>{method}</p>");
| |
| });
| |
| </syntaxhighlight>
| |
| | |
| === Beispiel: Query-Parameter auslesen ===
| |
| <syntaxhighlight lang="csharp">
| |
| app.Run(async (HttpContext context) =>
| |
| {
| |
| if (context.Request.Method == "GET" &&
| |
| context.Request.Query.ContainsKey("id"))
| |
| {
| |
| string id = context.Request.Query["id"];
| |
| await context.Response.WriteAsync($"<p>ID: {id}</p>");
| |
| }
| |
| });
| |
| </syntaxhighlight>
| |
| | |
| === Beispiel: User-Agent anzeigen ===
| |
| <syntaxhighlight lang="csharp">
| |
| app.Run(async (HttpContext context) =>
| |
| {
| |
| if (context.Request.Headers.ContainsKey("User-Agent"))
| |
| {
| |
| string agent = context.Request.Headers["User-Agent"];
| |
| await context.Response.WriteAsync($"<p>{agent}</p>");
| |
| }
| |
| });
| |
| </syntaxhighlight>
| |
| | |
| == HTTP-Methoden ==
| |
| * '''GET''': Daten abfragen, sichtbar in URL, cachebar, sicher
| |
| * '''POST''': Daten senden (z. B. Formulare), im Body, nicht idempotent
| |
| | |
| == GET vs POST ==
| |
| '''GET''':
| |
| * Daten in URL
| |
| * cachebar, idempotent
| |
| * nicht für sensible Daten
| |
| | |
| '''POST''':
| |
| * Daten im Body
| |
| * sicherer für Passwörter
| |
| * nicht idempotent
| |
| | |
| == Tool: Postman ==
| |
| '''Verwendung''':
| |
| * HTTP-Requests (GET, POST, usw.) erstellen
| |
| * Header & Body anpassen | |
| * Antwort inspizieren: Statuscode, Header, Body
| |
| | |
| '''Ablauf''':
| |
| # Öffnen → Neue Anfrage
| |
| # Methode + URL eingeben (z. B. https://localhost:7070/api/products)
| |
| # Optional: Header / Body hinzufügen
| |
| # "Send" klicken → Antwort wird unten angezeigt
| |
| | |
| == Zusammenfassung ==
| |
| * HTTP = Grundlage der Webkommunikation
| |
| * Zustandslos, Anfrage-Antwort-Modell
| |
| * Statuscodes geben Antwortstatus an
| |
| * ASP.NET Core erlaubt präzise Steuerung von Anfragen & Antworten
| |
| * Tools wie Postman helfen beim Testen von APIs
| |