> 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/business-logic/bypassing-authentication-via-encryption-oracle.md).

# Bypassing Authentication via Encryption Oracle

Bypassing Authentication via Encryption Oracle notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Authentication Bypass via Encryption Oracle

**Description of lab**

This lab has a logical flaw exposing a \*\*server-side encryption \*\*oracle. By exploiting this weakness, it is possible to forge a valid encrypted value in order to bypass authentication, access the admin panel and delete user **carlos**.

Identifier provided:

* User: `wiener`
* Password: `peter`

**Initial observation**

On the login page, the **Stay logged in** option is available.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1c8f2b6704708a6182e65cff57da7ca746fc47ca%2F%7B3E36DA00-915F-4E99-A834-06AC0A639BAC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

When used, a cookie encrypted in **Base64** is generated and stored on the customer side.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-06479314aece8e4eae54a0445e0bf7e609922eb5%2F%7B45D84F5E-FC68-4377-AE0C-264F6B775F2D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```bash
echo '0HE6oMYJL//S1fLwttqR7WMF3EX4KJmvfFRI53qpVnk=' | base64 -d

# The decoded value is binary ciphertext, not readable text.
```

### Identification of Encryption Oracle

When a valid comment is submitted, no specific response is observed.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-df90ea91b514f51d437eb3dba0cdaabe68d82b75%2F%7BCA4664B4-97B1-454D-BAF5-98D4D7777D0E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

However, if a comment causes an application error (e.g. an invalid email address), the server:

* returns an error message displayed on the screen;

{% code overflow="wrap" %}

```bash
csrf=cFMQUjAyzETtEr8TLsoir7V5p4C3m4ZG&postId=4&comment=test&name=test&email=test&website=https://localhost
```

{% endcode %}

* generates a new cookie `notification`\*\*, encrypted.

The content displayed is for example:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8773a3dd5c9ca7ffa97fa91971e0f8bc47bbe38c%2F%7B98731CE0-7072-4F6F-820E-A8ABAAFFE738%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This shows that:

* the server \*\*decrypts the content of the `notification` cookie;

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-170f9cd9ea3b411e2911b413fd030255fc7344f8%2F%7BA516BF0D-8173-48BA-9854-D8E725E90EF8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The server therefore acts as a **oracle of encryption and decryption**.

* the deciphered text is **reinjected in HTML response**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-16c05cc800cb2d282e9caf9ed7058823d79f5741%2F%7B6FA85698-84B5-498A-B262-9B0CAF4181DA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Correlation with the Cookie

By injecting the encrypted value of the cookie \*\*

The observed format is:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-da4fa9c84fc71b8d2faf60d1ca2fb080634116b5%2F%7B2E30F536-1AB8-430A-9F77-F7E116B0D862%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This clearly corresponds to:

* a user name;
* a timestamp.

#### Forgery of an Administrator Identity

The objective is to have the server encrypt the following string:

```bash
administrator:1766913113564
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3594dd843ec91657d6fd3109c0b8caf088cf6df8%2F%7BB99DE7CF-7BCE-4058-9E02-DF9F6A451DF9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

To do this, this value is injected into the vulnerable field (invalid comment/email), causing:

* display the error message containing this string;

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-71b56cb8b65bd1996936e932e33fc8d8de9c0d99%2F%7BF469F5A4-6D70-41BA-9326-889C2BC22AFA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

the generation of a new `notification` cookie, including the text injected.

{% code overflow="wrap" %}

```bash
Set-Cookie: notification=VQbs3ex4CbvKjTm0LM5wuZa79pnAzKI9MEsa1O0MbX%2fJpfl9baj6yL3ryxh4u6nyiWHVwxP7%2fVDPyft%2f1qAbbQ%3d%3d; HttpOnly
```

{% endcode %}

### Encryption Algorithm Identification

By arbitrarily truncating the encrypted value, the server returns the following error

```bash
PTBLGtTtDG1/yaX5fW2o%2bsi968sYeLup8olh1cMT%2b/1Qz8n7f9agG20%3d
```

`Input length must be multiple of 16 when decrypting with padded cipher`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6edc2449f91bef9d278bd1e005590eaf0fc64ca7%2F%7B86526481-7898-40D5-8113-809AAE3C7710%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This clearly indicates the use of **AES with padding**, operating in blocks of **16 bytes**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-921a3d43ea0db8951b4b6ffbee9ae35a884766ff%2F%7BA6A7EDD6-E0F9-4DDC-99CE-CA4AFBE3E432%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Cipher Block Manipulation

The problem encountered is the presence of invalid padding characters at the end of the message. / To remedy this, the injected chain is preceded by filling characters to align the blocks correctly:

```
xxxxxxxxxadministrator:1766913113564
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-db48f1a39a887b49244698967f194e57043ef5d4%2F%7B3FB22BF1-1A82-41BE-966D-0E22EFD0D949%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

A new encrypted cookie is then generated.

VQbs3ex4CbvKjTm0LM5wuZJqwlVboMZ2IzNuiTfVH6iHj9RZUT59d5kGoS64tVE5wWiEfmp6VbJG%2bb%2fNW5%2bblA%3d%3d

### Cutting and Recomposing the Cookie

By deleting the first **two encrypted blocks** (corresponding to filling), only blocks containing:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-53b11c36be65a667931372eed1d9916d85e8d95c%2F%7BB155871E-4388-4A10-BEB4-7B2665F6EF57%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a85d9e6c8504608250675b0e1e0a6c2633a84516%2F%7BC52B4886-B120-45A9-B85C-755072EB80DD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This final encrypted value is accepted by the server.

```
h4/UWVE%2bfXeZBqEuuLVROcFohH5qelWyRvm/zVufm5Q%3d
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0b23a0e83ce8947384e9e367f5fe9fe3b619ac7e%2F%7B9B975810-3156-49D5-BBE6-87F32FCBF48B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Contouring Authentication

Final steps:

1. Delete the existing session cookie.
2. Replace the value of the cookie \*\*
3. Refresh the page.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cb818e32f157dec337db5f2539aeb3f9668ba4d7%2F%7BF7D93958-A273-4244-8FE3-5A0243528964%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/business-logic/bypassing-authentication-via-encryption-oracle.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.
