> 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/pt-br/web/business-logic/low-level-logic-flaw.md).

# Falha de lógica de baixo nível

### Aplicação defeituosa das regras de negócio

**Descrição do laboratório**

Este laboratório contém um \*\*defeito lógico no processo de compra\*\*. Devido à aplicação inadequada das regras de negócio, é possível manipular o cálculo do carrinho para comprar uma "Lightweight l33t leather jacket" por um preço inesperado.

Identificador fornecido:

* **Usuário:** wiener
* **Senha:** peter

**Análise comportamental**

Ao adicionar um produto ao carrinho, a seguinte consulta é usada:

```bash
productId=1&redir=PRODUCT&quantity=99
```

Este parâmetro pode ser enviado **um grande número de vezes** sem controle rígido do valor cumulativo.

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

A consulta é enviada para **Intruder** com um payload nulo configurado em **Continuar indefinidamente** e um máximo de **1 solicitação concorrente**.

<figure><img src="/files/8337e32a3bcd1bc1f7f56ea113bd51c420df0567" alt=""><figcaption></figcaption></figure>

Após iterações suficientes, o **preço total do carrinho torna-se negativo**.

<figure><img src="/files/27dd3c062a2ebe91603c7ffecd13eaa7409e3851" alt=""><figcaption></figcaption></figure>

**Causa do problema**

A vulnerabilidade vem de um overflow com sinal **overflow**. / O aplicativo usa um **inteiro com sinal de 32 bits**, cujos limites são:

* Valor mínimo : `-2 147 483 648`
* Valor máximo : `2 147 483 647`

Quando o total excede o valor máximo permitido, ele **recalcula em valores negativos** devido a estouro aritmético.

**Controles inadequados**

Mesmo que o aplicativo impeça o pagamento quando o total for menor que 0, **nenhuma verificação correta é feita durante os cálculos intermediários**.

Isso permite ajustar o carrinho até obter um valor final positivo, porém muito baixo.

<figure><img src="/files/4240df7b8f8633a30e3fd65d60ab72af7a1820dc" alt=""><figcaption></figcaption></figure>

**Ajuste do cálculo final**

Para obter um valor \*\* acima de $0 e abaixo de $100\*\*, é feito o seguinte cálculo:

* Custo da jaqueta: **$1,337**
* Valor necessário para causar overflow: \**14 018 329* \*
* Cálculo:

  ```bash
  14 018 329 / 1337 ≈ 10 484 vezes
  ```

Envio em lote (`quantidade = 99`):

```bash
10,484 / 99 ≈ 105 solicitações
```

**Composição final do carrinho**

Para obter um total válido após o overflow:

* **32 123** jaquetas a $1337
* **21** sapatos Baby minding a $60.79
* **Total final:** **$54.63**


---

# 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/pt-br/web/business-logic/low-level-logic-flaw.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.
