Integer Overflow (Web Applications)

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ

์ด ํŽ˜์ด์ง€๋Š” integer overflows/truncations๊ฐ€ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์–ด๋–ป๊ฒŒ ์•…์šฉ๋  ์ˆ˜ ์žˆ๋Š”์ง€์— ์ดˆ์ ์„ ๋งž์ถฅ๋‹ˆ๋‹ค. ๋„ค์ดํ‹ฐ๋ธŒ ๋ฐ”์ด๋„ˆ๋ฆฌ ๋‚ด๋ถ€์˜ exploitation primitives์— ๋Œ€ํ•ด์„œ๋Š” ์ „์šฉ ํŽ˜์ด์ง€๋ฅผ ๊ณ„์† ์ฝ์œผ์„ธ์š”:

{{#ref}}

../../binary-exploitation/integer-overflow-and-underflow.md {{#endref}}


1. Why integer math still matters on the web

๋Œ€๋ถ€๋ถ„์˜ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ์ตœ์‹  ์Šคํƒ์—์„œ memory-safe ์–ธ์–ด๋กœ ์ž‘์„ฑ๋˜๋”๋ผ๋„, ๊ธฐ์ € ๋Ÿฐํƒ€์ž„(๋˜๋Š” ์„œ๋“œํŒŒํ‹ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ)์€ ๊ฒฐ๊ตญ C/C++๋กœ ๊ตฌํ˜„๋ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž ์ œ์–ด ์ˆซ์ž๊ฐ€ ๋ฒ„ํผ ํ• ๋‹น, ์˜คํ”„์…‹ ๊ณ„์‚ฐ, ๋˜๋Š” ๊ธธ์ด ๊ฒ€์‚ฌ์— ์‚ฌ์šฉ๋  ๋•Œ, 32-bit ๋˜๋Š” 64-bit์˜ ๋ž˜ํ•‘(๋ž˜ํผ์–ด๋ผ์šด๋“œ)์€ ์™ธ๊ฒฌ์ƒ ๋ฌดํ•ดํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚œ ์ฝ๊ธฐ/์“ฐ๊ธฐ, ๋…ผ๋ฆฌ ์šฐํšŒ ๋˜๋Š” DoS๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ผ๋ฐ˜์ ์ธ ๊ณต๊ฒฉ ํ‘œ๋ฉด:

  1. Numeric request parameters โ€“ ์ „ํ˜•์ ์ธ id, offset, ๋˜๋Š” count ํ•„๋“œ.
  2. Length / size headers โ€“ Content-Length, WebSocket frame length, HTTP/2 continuation_len ๋“ฑ.
  3. File-format metadata parsed server-side or client-side โ€“ ์ด๋ฏธ์ง€ ํฌ๊ธฐ, ์ฒญํฌ ํฌ๊ธฐ, ํฐํŠธ ํ…Œ์ด๋ธ”.
  4. Language-level conversions โ€“ PHP/Go/Rust FFI์—์„œ์˜ signedโ†”unsigned ์บ์ŠคํŠธ, V8 ๋‚ด๋ถ€์˜ JS Number โ†’ int32 truncations.
  5. Authentication & business logic โ€“ ์ฟ ํฐ ๊ฐ’, ๊ฐ€๊ฒฉ ๋˜๋Š” ์ž”๊ณ  ๊ณ„์‚ฐ์—์„œ ์กฐ์šฉํžˆ ๋ฐœ์ƒํ•˜๋Š” overflow.

2. Recent real-world vulnerabilities (2023-2025)

์—ฐ๋„์ปดํฌ๋„ŒํŠธ๊ทผ๋ณธ ์›์ธ์˜ํ–ฅ
2023libwebp โ€“ CVE-2023-4863๋””์ฝ”๋”ฉ๋œ ํ”ฝ์…€ ํฌ๊ธฐ๋ฅผ ๊ณ„์‚ฐํ•  ๋•Œ ๋ฐœ์ƒํ•œ 32-bit multiplication overflowChrome 0-day(BLASTPASS on iOS)๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ–ˆ๊ณ , renderer sandbox ๋‚ด๋ถ€์—์„œ remote code execution๋ฅผ ํ—ˆ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
2024V8 โ€“ CVE-2024-0519JSArray๋ฅผ ํ™•์žฅํ•  ๋•Œ 32-bit๋กœ์˜ truncation์ด backing store์— ๋Œ€ํ•œ OOB write๋กœ ์ด์–ด์ง๋‹จ ํ•œ ๋ฒˆ์˜ ๋ฐฉ๋ฌธ์œผ๋กœ Remote code execution์ด ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.
2025Apollo GraphQL Server (unreleased patch)first/last pagination args์— 32-bit signed integer๋ฅผ ์‚ฌ์šฉ; ์Œ์ˆ˜ ๊ฐ’์ด ํฐ ์–‘์ˆ˜๋กœ ๋žฉ๋ฉ๋‹ˆ๋‹คLogic bypass & memory exhaustion (DoS).

3. Testing strategy

3.1 Boundary-value cheat-sheet

์ •์ˆ˜๊ฐ€ ์˜ˆ์ƒ๋˜๋Š” ๋ชจ๋“  ๊ณณ์— extreme signed/unsigned values๋ฅผ ์ „์†กํ•˜์„ธ์š”:

-1, 0, 1,
127, 128, 255, 256,
32767, 32768, 65535, 65536,
2147483647, 2147483648, 4294967295,
9223372036854775807, 9223372036854775808,
0x7fffffff, 0x80000000, 0xffffffff

๋‹ค๋ฅธ ์œ ์šฉํ•œ ํ˜•์‹:

  • Hex (0x100), octal (0377), scientific (1e10), JSON big-int (9999999999999999999).
  • ๋งค์šฐ ๊ธด ์ˆซ์ž ๋ฌธ์ž์—ด(>1kB)๋กœ ์ปค์Šคํ…€ ํŒŒ์„œ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด.

3.2 Burp Intruder ํ…œํ”Œ๋ฆฟ

ยงINTEGERยง
Payload type: Numbers
From: -10 To: 4294967300 Step: 1
Pad to length: 10, Enable hex prefix 0x

3.3 Fuzzing ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐ ๋Ÿฐํƒ€์ž„

  • AFL++/Honggfuzz with libFuzzer ํ•˜๋‹ˆ์Šค๋กœ ํŒŒ์„œ๋ฅผ ๋Œ€์ƒ์œผ๋กœ (์˜ˆ: WebP, PNG, protobuf).
  • Fuzzilli โ€“ ๋ฌธ๋ฒ• ์ธ์‹ํ˜• fuzzing์œผ๋กœ JavaScript ์—”์ง„์˜ V8/JSC ์ •์ˆ˜ ์ ˆ๋‹จ์„ ๊ณต๋žต.
  • boofuzz โ€“ ๋„คํŠธ์›Œํฌ ํ”„๋กœํ† ์ฝœ fuzzing (WebSocket, HTTP/2)์—์„œ ๊ธธ์ด ํ•„๋“œ์— ์ง‘์ค‘.

4. Exploitation patterns

4.1 Logic bypass in ์„œ๋ฒ„์ธก ์ฝ”๋“œ (PHP ์˜ˆ์ œ)

$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 ์ด๋ฏธ์ง€ ๋””์ฝ”๋” (libwebp 0-day)

The WebP lossless decoder multiplied image width ร— height ร— 4 (RGBA) inside a 32-bit int. A crafted file with dimensions 16384 ร— 16384 overflows the multiplication, allocates a short buffer and subsequently writes ~1GB of decompressed data past the heap โ€“ leading to RCE in every Chromium-based browser before 116.0.5845.187.

4.3 ๋ธŒ๋ผ์šฐ์ € ๊ธฐ๋ฐ˜ XSS/RCE ์ฒด์ธ

  1. Integer overflow in V8๋Š” arbitrary read/write๋ฅผ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•œ๋‹ค.
  2. ๋‘ ๋ฒˆ์งธ ๋ฒ„๊ทธ๋กœ sandbox๋ฅผ ํƒˆ์ถœํ•˜๊ฑฐ๋‚˜ native APIs๋ฅผ ํ˜ธ์ถœํ•ด payload๋ฅผ ๋ฐฐ์น˜ํ•œ๋‹ค.
  3. ๊ทธ payload๋Š” origin context์— ์•…์„ฑ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ฃผ์ž… โ†’ stored XSS.

5. ๋ฐฉ์–ด ์ง€์นจ

  1. Use wide types or checked math โ€“ e.g., size_t, Rust checked_add, Go math/bits.Add64.
  2. Validate ranges early: ์‚ฐ์ˆ  ์—ฐ์‚ฐ ์ „์— ๋น„์ฆˆ๋‹ˆ์Šค ๋„๋ฉ”์ธ ๋ฐ–์˜ ๊ฐ’์€ ๊ฑฐ๋ถ€ํ•˜๋ผ.
  3. Enable compiler sanitizers: -fsanitize=integer, UBSan, Go race detector.
  4. Adopt fuzzing in CI/CD โ€“ coverage feedback๊ณผ boundary corpora๋ฅผ ๊ฒฐํ•ฉํ•˜๋ผ.
  5. Stay patched โ€“ ๋ธŒ๋ผ์šฐ์ €์˜ integer overflow ๋ฒ„๊ทธ๋Š” ๋ช‡ ์ฃผ ๋‚ด์— ์ž์ฃผ ์•…์šฉ๋œ๋‹ค.

์ฐธ๊ณ  ์ž๋ฃŒ

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ