Integer Overflow (Web Applications)
Reading time: 4 minutes
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 지원하기
- 구독 계획 확인하기!
- **💬 디스코드 그룹 또는 텔레그램 그룹에 참여하거나 트위터 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
이 페이지는 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로 바꿀 수 있습니다.
일반적인 공격 표면:
- Numeric request parameters – 전형적인 id, offset, 또는 count 필드.
- Length / size headers – Content-Length, WebSocket frame length, HTTP/2 continuation_len 등.
- File-format metadata parsed server-side or client-side – 이미지 크기, 청크 크기, 폰트 테이블.
- Language-level conversions – PHP/Go/Rust FFI에서의 signed↔unsigned 캐스트, V8 내부의 JS Number → int32 truncations.
- Authentication & business logic – 쿠폰 값, 가격 또는 잔고 계산에서 조용히 발생하는 overflow.
2. Recent real-world vulnerabilities (2023-2025)
연도 | 컴포넌트 | 근본 원인 | 영향 |
---|---|---|---|
2023 | libwebp – CVE-2023-4863 | 디코딩된 픽셀 크기를 계산할 때 발생한 32-bit multiplication overflow | Chrome 0-day(BLASTPASS on iOS)를 트리거했고, renderer sandbox 내부에서 remote code execution를 허용했습니다. |
2024 | V8 – CVE-2024-0519 | JSArray를 확장할 때 32-bit로의 truncation이 backing store에 대한 OOB write로 이어짐 | 단 한 번의 방문으로 Remote code execution이 발생했습니다. |
2025 | Apollo 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 체인
- Integer overflow in V8는 arbitrary read/write를 가능하게 한다.
- 두 번째 버그로 sandbox를 탈출하거나 native APIs를 호출해 payload를 배치한다.
- 그 payload는 origin context에 악성 스크립트를 주입 → stored XSS.
5. 방어 지침
- Use wide types or checked math – e.g., size_t, Rust checked_add, Go math/bits.Add64.
- Validate ranges early: 산술 연산 전에 비즈니스 도메인 밖의 값은 거부하라.
- Enable compiler sanitizers: -fsanitize=integer, UBSan, Go race detector.
- Adopt fuzzing in CI/CD – coverage feedback과 boundary corpora를 결합하라.
- Stay patched – 브라우저의 integer overflow 버그는 몇 주 내에 자주 악용된다.
참고 자료
- NVD CVE-2023-4863 – libwebp Heap Buffer Overflow
- Google Project Zero – "Understanding V8 CVE-2024-0519"
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 지원하기
- 구독 계획 확인하기!
- **💬 디스코드 그룹 또는 텔레그램 그룹에 참여하거나 트위터 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.