High-level logic vulnerability

2 min read Easy Portswigger
Business Logic
Contents

On this page

The lab

here is how portswigger describes it

This lab doesn't adequately validate user input. You can exploit a logic flaw in its purchasing workflow to buy items for an unintended price. To solve the lab, buy a "Lightweight l33t leather jacket". You can log in to your own account using the following credentials: wiener:peter

the cart takes a quantity parameter and never checks that it is positive. a negative quantity is accepted and subtracts from the total, so by adding a large negative amount of a cheap item we can drag the whole order total down below our store credit, while still having the expensive jacket in the cart. the flaw is not one tampered field this time, it is that the app's arithmetic was never meant to go negative and nobody enforced it.

why a negative quantity breaks this#

the price of a line item is quantity times unit price, and the checkout just sums those lines. the developer assumed quantity is always a sensible positive number, so they never bounded it. feed in a negative quantity and that line's contribution goes negative, pulling the order total down, even below zero. nothing rejects a negative subtotal, so we can offset the jacket's real cost with "negative" cheap items and pay whatever we want. this is a high-level logic flaw, each individual step works, but the workflow as a whole permits a state the business never intended, a cart worth less than nothing.

Step 1 - Add a cheap item#

we log in and add a cheap item to the cart, to have a line we can manipulate.

11

Step 2 - Find the quantity parameter#

in Proxy > HTTP history we study the messages and notice the quantity is set by a parameter in the POST /cart request.

22

Step 3 - Confirm quantity is attacker controlled#

we turn on Intercept, add another item, and in the intercepted POST /cart change the quantity to an arbitrary integer, then forward. the cart quantity updates to our value, confirming we control it.

33
44

Step 4 - go negative#

we request a negative quantity and see it is deducted from the cart quantity. we then request a large enough negative quantity to remove more units than the cart holds, forcing the cart into a negative quantity of that product. the cart total is now a negative amount.

55
66

Step 5 - offset the jacket's price#

we add the leather jacket to the cart as normal, then add a suitable negative quantity of the cheap item so the negative line cancels most of the jacket's cost, bringing the total below our remaining store credit.

77

Step 6 - place the order#

with the total now under our credit we place the order.

88

with this, the lab is solved!