Low-level logic flaw

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 lets us pile on huge quantities, and the back-end stores the running total in a signed 32-bit integer. push the total past that type's maximum and it wraps around to a large negative number, the classic integer overflow. so we deliberately overshoot to flip the total negative, then fine-tune the quantities so the number climbs back up and settles between $0 and our $100 of remaining store credit, letting us check out.

why the overflow happens#

a signed 32-bit integer can only hold values up to 2,147,483,647, and the shop keeps the price in cents in exactly that kind of variable. the jacket is 133700 cents, so each one we add moves the total toward that ceiling. once the total would exceed 2,147,483,647 it does not error, it silently wraps to the minimum, −2,147,483,648, and continues counting up from there. that is the bug, the code trusts the arithmetic never to overflow and never bounds the quantity. we exploit it by overshooting on purpose to make the total negative, then adding a carefully chosen number of units so it lands in the narrow positive window we can afford.

Step 1 - confirm the normal block#

we log in and try to buy the jacket. the order is rejected for insufficient store credit, so there is a price barrier to defeat.

11111

Step 2 - find the cart request#

in the proxy history we study the order process and send the POST /cart request to Repeater.

22222

Step 3 - overflow the total with Intruder#

we send the request to Intruder and set the quantity parameter to 99. in the payloads panel we pick Null payloads, and under payload configuration choose Continue indefinitely, then start the attack so it keeps adding 99 jackets per request.

33333

while it runs we watch the cart, refreshing the total now and then. eventually the price suddenly flips to a large negative integer and starts counting back up toward 0. that confirms the total has exceeded the 32-bit maximum (2,147,483,647) and wrapped around to the minimum (−2,147,483,648).

Step 4 - land the total in the affordable window#

now we aim precisely. the jacket is stored at 133700 cents, and we need the wrapped-around total to settle between $0 and our $100 of credit. that is not reachable with jackets alone, so we do it in two parts.

we recreate the same Intruder attack but this time generate exactly 323 null payloads, and in the Resource pool tab set maximum concurrent requests to 1 so the additions apply one at a time in order. we start it and let it finish.

then in Repeater we send a single POST /cart for 47 jackets. the total now reads −$1221.96.

44444

Step 5 - offset with another item#

from Repeater we add a suitable quantity of another, cheaper item so its positive price cancels the negative total and brings it up into the $0–$100 window our credit can cover.

55555

Step 6 - place the order#

with the total now inside our budget we place the order.

66666

with this, the lab is solved!