# Cookie Hacking

## Cookie Tampering

El contenido de algunas cookies puede estar en texto sin formato, y es obvio lo que hacen. Tomemos, por ejemplo, si estas fueran las cookies configuradas después de un inicio de sesión exitoso:

```
Establecer-Cookie: login_in=true; Max-Edad=3600; Ruta=/
Establecer-Cookie: admin=false; Max-Edad=3600; Ruta=/
```

Vemos una cookie (logged\_in), que parece controlar si el usuario está conectado o no, y otra (admin), que controla si el visitante tiene privilegios de administrador. Usando esta lógica, si tuviéramos que cambiar el contenido de las cookies y realizar una solicitud, podremos cambiar nuestros privilegios.

Estás pruebas las voy a realizar con curl:

**Ejemplo**

En esta primera petición no tenemos login entonces no tenemos cookie.

```
curl http://<ip>/
```

En esta segunda, veremos le especificamos que queremos estar logueados, como admin false.

```
curl -H "Cookie: logged_in=true; admin=false" http://<ip>/
```

Y aquí estariamos logeados como admin true.

```
curl -H "Cookie: logged_in=true; admin=true" http://<ip>/
```

### Tipo de hash cookie

Las cookies a veces pueden estar representadas como hash, estos son tipos de hash que podemos encontrarnos en las cookies.

| Método hash | Output                                                                                                                                    |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| md5         | <h4>0a3b42068660154f8ca055e89b4d91e7</h4>                                                                                                 |
| sha-256     | <h4>e77f14a269b7bdd6dca1f647aec84c793486f26cb50ac80c705bc64c6859366a</h4>                                                                 |
| sha-512     | <h4>71ae4a70bf9946d7e8e90c896061d5c955b51d37f0ca0d0ab8f6461bb51014c95242b67030ab4ebc75e25f31546d01927a543afcfe66e88741ef4dfca8c19b85</h4> |
| sha1        | <h4>3e81ec65075ef8471d31d28bafd3a6ea701881e0</h4>                                                                                         |

Hay páginas como [crackstation](https://crackstation.net/) que podemos des encriptar los hashes.

<figure><img src="/files/uUHvsy92pkJrPID5GQIb" alt=""><figcaption><p>Ejemplo de des encriptar hash</p></figcaption></figure>

## Padding Oracle Attack

### ¿Qué es y cómo funciona?

En el modo CBC, el bloque cifrado anterior se usa como IV para XOR con el siguiente bloque:

<figure><img src="/files/ksc97J70vrnZepV7I0J9" alt=""><figcaption></figcaption></figure>

Para descifrar CBC se realizan las operaciones opuestas:

<figure><img src="/files/X6vIv6LxoazTtxqCjEXq" alt=""><figcaption></figcaption></figure>

### ¿Como se explota?

```
padbuster http://example.com/login.php<cookie> <numero de bytes(1,2,3…) -cookie “auth/PHPSESSID=<cookie>” # esto buscara la id que es vulnerable
padbuster http://example.com/login.php <cookie> <numero de bytes(1-8)> -cookie “auth/PHPSESSID=<cookie>” -encoding 0 -plaintext “user=admin” # buscara la cookie del usuario admin para asi hacer un cookie hijacking
```

### Con BurpSuite

Sesión de registro

Cuando te vas a registrar en el campo username, si ponemos admin= o admin== nos logueamos automáticamente al usuario admin

Interceptar petición de tu panel iniciado, mandarlo al intruder, seleccionar cookie → Payloads→ Payload type → Bit Flipper Attack → Format of original data - Literal value (Select 1-8) → Start Attack.

Una vez conseguida la cookie, realizamos un cookie hijacking para iniciar sesión con la cookie robada.


---

# 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://j4ckie0x17.gitbook.io/notes-pentesting/pentesting-web/cookie-hacking.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.
