Ringkasan

Race condition di web terjadi ketika dua atau lebih request concurrent memodifikasi resource yang sama secara bersamaan, menyebabkan state inconsistency yang bisa dieksploitasi. Vektor utama: coupon/diskon multiple redeem, ticket booking, vote manipulation, API rate limit bypass, dan TOCTOU (Time-of-Check-Time-of-Use) pada file operations.

Cross-link: web-hacking-exploitationapi-security-deep-diverequest-smuggling-deep-dive


Daftar Isi


1. Web Race Condition Vectors

VectorContohDampak
Coupon redeemKirim 20 request redeem bersamaanRedeem 1 coupon berkali-kali
Ticket bookingBooking seat concurrentOverbooking, double booking
Vote manipulationVote API concurrentVote berkali-kali
Rate limit bypassKirim request sebelum counter updateBypass rate limiting
Balance withdrawalWithdraw concurrentDouble withdrawal
TOCTOU fileCheck → race → useFile access kontrol bypass

2. Exploitation Techniques

Last-Byte Sync

# Send multiple requests, biarkan responses incomplete
# Complete last byte dari semua request secara simultan
GET /api/redeem-coupon?code=DISKON50 HTTP/1.1
GET /api/redeem-coupon?code=DISKON50 HTTP/1.1
GET /api/redeem-coupon?code=DISKON50 HTTP/1.1
# Kirim byte terakhir semua request dalam 1 TCP packet

Single-Packet Attack

# Kirim semua request dalam 1 packet — TCP stack server process bersamaan
# Gunakan Burp Turbo Intruder atau race-the-web

Time-of-Check-Time-of-Use (TOCTOU)

// Vulnerable:
if (fileExists(path)) {
  // TOCTOU window
  const data = readFile(path) // Attacker swap file here
  process(data)
}
 
// Race condition antara check dan use

3. Tools

ToolFungsi
Burp Turbo IntruderRace condition testing via HTTP pipelining
race-the-webPython tool untuk single-packet race attack
CaidoModern alternative to Burp dengan race feature

race-the-web

from race_the_web import racer
 
@racer(concurrent=20)
def attack():
    requests.post("http://target.com/api/redeem",
                  json={"coupon": "DISKON50"})

4. Defense

StrategyImplementasi
Database transactionAtomic operation — BEGIN TRANSACTION ... COMMIT
Distributed lockRedis lock via SETNX
Idempotency keyIdempotency-Key header untuk mencegah duplicate process
Optimistic lockingVersion column — cek versi sebelum update
Rate limitPer-user rate limiting untuk sensitive operations
Atomic decrementUPDATE stock SET qty = qty - 1 WHERE qty > 0

Contoh Redis Lock

const lock = await redis.setnx(`coupon:${code}`, "locked")
if (lock === 1) {
  // Process coupon
  await redis.del(`coupon:${code}`)
} else {
  return "Already processing"
}

Referensi: /mnt/data_d/Projects/Reference/PayloadsAllTheThings/Race Condition/