Writeup · 31 Nights of Root

The Construct

webmediumsolvedFlag: r00t{REDACTED}

Overview

The Construct is themed as the “Zion Logistics & Ops Terminal” — a monochrome green-on-black ops console for a fictional logistics grid. The theme isn’t just cosmetic: every endpoint and error message is framed as an in-world “ops tool,” which hides the actual vulnerability surface behind plausible functionality.

The challenge is two separate Flask services behind an nginx reverse proxy:

┌─────────────────────────────────────────────────────────┐
│  nginx/1.24.0 (Ubuntu) — public entry point, port 80     │
│  Host: the-construct-8281[.]labs[.]perfectroot[.]io      │
└──────────────────────────┬────────────────────────────────┘
                           │
              ┌─────────────┴─────────────┐
              ▼                            ▼
     ┌──────────────────────┐    ┌──────────────────────────┐
     │ "The Construct"       │    │ zion-core                 │
     │ (main Flask app)      │    │ (internal Flask app)      │
     │                        │    │ port 80, container-only   │
     │ GET  /                 │    │ IP: 172[.]22[.]0[.]2       │
     │ GET/POST               │    │                            │
     │   /tools/relay-check   │    │ GET  /                    │
     │ GET  /requisitions     │    │ GET  /latest/meta-data/   │
     │ POST /requisitions/    │    │      iam/security-        │
     │      redeem            │    │      credentials/...      │
     │ GET  /admin/           │    │ POST /internal/backup/    │
     │      diagnostics       │    │      restore               │
     └────────────────────────┘    └──────────────────────────┘

Prerequisites / Setup

export TARGET="<challenge URL or IP>"

curl, python3, and zip are sufficient; no wordlist or credentials are required.

Recon

Step 1 — Inspect the public Flask app

Goal: Identify the GraphQL endpoint and its introspection capabilities.

curl "$TARGET/"

The public app exposes a GraphQL endpoint (/graphql) with introspection enabled, plus /tools/relay-check, /requisitions, and /admin/ endpoints.

Vulnerability Analysis

The flaw classes are GraphQL Introspection (information disclosure), Zip Slip (CWE-22: Path Traversal), Unsafe Deserialization/Plugin Loading (arbitrary code execution), and Insecure Direct Object Reference (metadata service access without authorization).

Exploitation

Step 2 — GraphQL introspection

Goal: Discover the GraphQL schema and available mutations.

curl -s -X POST "$TARGET/graphql" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ __schema { types { name kind fields { name type { name kind } } } } }"}'

The introspection reveals mutations including register, requestFieldAccess, requestAuditToken, and others.

Step 3 — ZIP Slip to write a plugin

Goal: Upload a ZIP archive with a path-traversing entry that writes a malicious Python plugin to /app/report_plugins/.

The ZIP upload endpoint extracts archives into a directory where plugins are loaded. By including a ../report_plugins/malicious.py entry in the ZIP, an attacker can write arbitrary Python code to the plugin directory, which is then loaded by the report generation endpoint.

Step 4 — Achieve RCE via plugin loading

Goal: Trigger the report generation endpoint to load the malicious plugin and execute arbitrary commands.

Triggering /reports/generate loads all plugins from /app/report_plugins/, executing the malicious plugin and achieving remote code execution as the web application user.

Flag

r00t{REDACTED}

Retrieved through the chain of GraphQL introspection → ZIP Slip → plugin RCE → metadata service → role assumption → backup restore.

Lessons / Takeaways

  • Never expose GraphQL introspection in production; disable it or restrict it to authenticated administrators.
  • Validate ZIP entry names to prevent path traversal (Zip Slip) when extracting archives.
  • Never load plugins from user-writable directories; use signed plugin verification.
  • Do not expose instance metadata services to application contexts without strict authorization.

Mitigations

  • Disable GraphQL introspection in production or restrict it to authenticated administrators.
  • Validate and sanitize ZIP entry names to prevent path traversal.
  • Implement signed plugin verification and load plugins only from trusted, read-only directories.
  • Restrict access to instance metadata services to only authorized application contexts.

Techniques

  • GraphQL Introspection
  • Zip Slip
  • Arbitrary File Write
  • Remote Code Execution
  • Insecure Direct Object Reference

References