Lab 16: Business Logic Flaws

Objective

Exploit business logic vulnerabilities in a live e-commerce API from Kali Linux using four distinct attacks:

  1. Negative quantity order — order -5 units of a £864 product to receive £4,320 instead of paying

  2. Coupon stacking — apply three single-use coupons simultaneously in one request to stack discounts

  3. Payment workflow skip — set status=paid in the checkout payload to bypass the payment gateway entirely

  4. Refund abuse — request a refund of £9,999 with no validation against the original purchase amount

Business logic flaws can't be caught by WAFs or automated scanners — they require understanding what the application should do and testing what it actually does.


Background

Business logic flaws exist in the application's own rules — not in input validation or memory safety. They are often invisible to automated security tools because they don't produce error messages; the application behaves as designed, just against the designer's intent.

Real-world examples:

  • 2022 Slope Finance — a DeFi protocol accepted negative quantities in its swap function; an attacker minted $80M in tokens through repeated negative swaps.

  • 2021 Poly Network hack ($611M) — business logic flaw in cross-chain relay contracts allowed an attacker to call a privileged function from an unprivileged context. No SQLi, no buffer overflow — just a logic error.

  • Amazon Price Manipulation (recurring) — merchants have historically used $0.01 pricing with free shipping, then refunded only the item but kept the shipping fee; or used negative-price order exploits.

  • Airline loyalty abuse — booking then cancelling flights to harvest miles; rules checked total earned miles but not the relationship between booking and cancellation.

OWASP coverage: A04:2021 (Insecure Design) — "design flaws that cannot be fixed by a perfect implementation"


Architecture

Time

40 minutes

Tools

Tool
Purpose

curl

Send crafted API requests

python3

Automate multi-step attack chains


Lab Instructions

Step 1: Environment Setup


Step 2: Launch Kali and Reconnaissance

📸 Verified Output:


Step 3: Attack 1 — Negative Quantity (Money Printer)

📸 Verified Output:

💡 The server multiplies price × qty without checking qty > 0. A negative result means the user's balance increases — the app literally pays the attacker. This is the same class of bug that allowed DeFi protocols to be drained through negative-amount swaps. Fix: if qty <= 0: return 400. Always validate business constraints at the API layer, not just the frontend.


Step 4: Attack 2 — Coupon Stacking

📸 Verified Output:


Step 5: Attack 3 — Payment Workflow Skip

📸 Verified Output:

💡 State should never be client-controlled. The client cannot be trusted to report its own payment status — that's the payment gateway's job. The server must call the payment provider and receive a webhook/callback confirming payment before marking an order paid. If the client can set status=paid, you have no payment security at all.


Step 6: Attack 4 — Refund Abuse

📸 Verified Output:


Step 7: Combined Attack Chain


Step 8: Cleanup


Remediation

Flaw
Fix

Negative quantity

if qty <= 0: return 400 Bad Request

Coupon stacking

Apply and mark used in atomic transaction; one coupon per order

Payment status from client

Server-side state machine; only payment gateway webhooks change status

Uncapped refund

if amount > original_purchase_amount: return 400

Further Reading

Last updated