> 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 lógica de baixo nível

Notas sobre falha lógica de baixo nível para os laboratórios do PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payload, validação no Burp Suite e contexto de remediação.

### Aplicação incorreta 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 comércio, é 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
```

Esse parâmetro pode ser enviado **um grande número de vezes** sem controle rigoroso do valor cumulativo.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-57d0ee5542db45b8f8a17c1c1128fad304658679%2Fimage%20(3101).png?alt=media" alt=""><figcaption></figcaption></figure>

A consulta é enviada para **Intruder** com uma carga nula configurada em **Continuar indefinidamente** modo e um máximo de **1 requisição concorrente**.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e6f606e8d1b9d1655ebf921062dbe505ec34876a%2Fimage%20(3102).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9625ca79563b6a9a4c4b7b16de0b8b894016e9b1%2F%7B9260219F-93F4-425E-972E-02CE1FAE4B8F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Causa do problema**

A vulnerabilidade vem de um overflow assinado **overflow**. / A aplicação 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 **é recalculado em valores negativos** devido a um estouro aritmético.

**Controles inadequados**

Mesmo que a aplicação 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, mas bem baixo.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-39d129b1f470ca28aadbd71a1c9f9acb94653aa6%2Fimage%20(3104).png?alt=media" alt=""><figcaption></figcaption></figure>

**Ajuste do cálculo final**

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

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