Integer Overflow (Web Applications)
Reading time: 5 minutes
tip
Učite i vežbajte AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Učite i vežbajte GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Učite i vežbajte Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Podržite HackTricks
- Proverite planove pretplate!
- Pridružite se 💬 Discord grupi ili telegram grupi ili pratite nas na Twitteru 🐦 @hacktricks_live.
- Podelite hakerske trikove slanjem PR-ova na HackTricks i HackTricks Cloud github repozitorijume.
Ova stranica se fokusira na to kako integer overflows/truncations can be abused in web applications and browsers. Za exploitation primitives inside native binaries možete nastaviti čitanje posvećene stranice:
{{#ref}}
../../binary-exploitation/integer-overflow-and-underflow.md {{#endref}}
1. Why integer math still matters on the web
Iako je većina business-logic u modernim stack-ovima napisana u memory-safe jezicima, underlying runtime (ili third-party libraries) je na kraju implementiran u C/C++. Kad god se korisnički kontrolisani brojevi koriste za alokaciju buffera, računanje ofseta ili proveru dužine, a 32-bit or 64-bit wrap-around may transform an apparently harmless parameter into an out-of-bounds read/write, a logic bypass or a DoS.
Tipična površina napada:
- Numeric request parameters – klasična id, offset ili count polja.
- Length / size headers – Content-Length, WebSocket frame length, HTTP/2 continuation_len, itd.
- File-format metadata parsed server-side or client-side – dimenzije slike, chunk sizes, font tables.
- Language-level conversions – signed↔unsigned casts u PHP/Go/Rust FFI, JS Number → int32 truncations inside V8.
- Authentication & business logic – vrednost kupona, cena ili proračuni stanja koji se tiho overflow-uju.
2. Recent real-world vulnerabilities (2023-2025)
Year | Component | Root cause | Impact |
---|---|---|---|
2023 | libwebp – CVE-2023-4863 | 32-bit multiplication overflow when computing decoded pixel size | Triggered a Chrome 0-day (BLASTPASS on iOS), allowed remote code execution inside the renderer sandbox. |
2024 | V8 – CVE-2024-0519 | Truncation to 32-bit when growing a JSArray leads to OOB write on the backing store | Remote code execution after a single visit. |
2025 | Apollo GraphQL Server (unreleased patch) | 32-bit signed integer used for first/last pagination args; negative values wrap to huge positives | Logic bypass & memory exhaustion (DoS). |
3. Testing strategy
3.1 Boundary-value cheat-sheet
Pošaljite extreme signed/unsigned values gde god se očekuje integer:
-1, 0, 1,
127, 128, 255, 256,
32767, 32768, 65535, 65536,
2147483647, 2147483648, 4294967295,
9223372036854775807, 9223372036854775808,
0x7fffffff, 0x80000000, 0xffffffff
Ostali korisni formati:
- Hex (0x100), octal (0377), scientific (1e10), JSON big-int (9999999999999999999).
- Veoma dugački nizovi cifara (>1kB) da bi pogodili prilagođene parsere.
3.2 Burp Intruder šablon
§INTEGER§
Payload type: Numbers
From: -10 To: 4294967300 Step: 1
Pad to length: 10, Enable hex prefix 0x
3.3 Biblioteke i runtime-ovi za fuzzing
- AFL++/Honggfuzz sa libFuzzer harness-om oko parsera (npr. WebP, PNG, protobuf).
- Fuzzilli – grammar-aware fuzzing JavaScript engine-a da bi pogodio V8/JSC truncacije celobrojnih vrednosti.
- boofuzz – fuzzing mrežnih protokola (WebSocket, HTTP/2) fokusiran na polja dužine.
4. Obrasci eksploatacije
4.1 Logic bypass in server-side code (PHP primer)
$price = (int)$_POST['price']; // expecting cents (0-10000)
$total = $price * 100; // ← 32-bit overflow possible
if($total > 1000000){
die('Too expensive');
}
/* Sending price=21474850 → $total wraps to ‑2147483648 and check is bypassed */
4.2 Heap overflow via image decoder (libwebp 0-day)
WebP lossless decoder je pomnožio image width × height × 4 (RGBA) unutar 32-bit int-a. Specijalno konstruisan fajl sa dimenzijama 16384 × 16384 izaziva overflow pri množenju, alocira premali buffer i potom upisuje ~1GB dekompresovanih podataka izvan heap-a – što dovodi do RCE u svim Chromium-based browserima pre 116.0.5845.187.
4.3 Browser-based XSS/RCE chain
- Integer overflow in V8 gives arbitrary read/write.
- Escape the sandbox with a second bug or call native APIs to drop a payload.
- The payload then injects a malicious script into the origin context → stored XSS.
5. Odbrambene smernice
- Use wide types or checked math – e.g., size_t, Rust checked_add, Go math/bits.Add64.
- Validate ranges early: odbacite svaku vrednost van business domain pre aritmetike.
- Enable compiler sanitizers: -fsanitize=integer, UBSan, Go race detector.
- Adopt fuzzing in CI/CD – kombinuje coverage feedback sa boundary corpora.
- Stay patched – browser integer overflow bugs se često iskorišćavaju u roku od nekoliko nedelja.
References
- NVD CVE-2023-4863 – libwebp Heap Buffer Overflow
- Google Project Zero – "Understanding V8 CVE-2024-0519"
tip
Učite i vežbajte AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Učite i vežbajte GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Učite i vežbajte Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Podržite HackTricks
- Proverite planove pretplate!
- Pridružite se 💬 Discord grupi ili telegram grupi ili pratite nas na Twitteru 🐦 @hacktricks_live.
- Podelite hakerske trikove slanjem PR-ova na HackTricks i HackTricks Cloud github repozitorijume.