Challenge / Crypto

Mysterybox

Mysterybox is a sanitized challenge note from the local HTB archive, organized for quick review by category, difficulty, evidence flow, and reusable operator

MediumPublished 2024-04-14Sanitized local writeup

Scenario

Mysterybox attack path

Mysterybox is a sanitized challenge note from the local HTB archive, organized for quick review by category, difficulty, evidence flow, and reusable operator

Objective

Challenge walkthrough focused on Crypto evidence, validation, and reusable operator lessons.

Mysterybox sanitized attack graph

Walkthrough flow

01

The service implements textbook RSA signing and...

02

The sign oracle blocks only the exact forbidden admin...

03

The hidden modulus can be recovered from GCDs of...

04

After recovering n, choose an allowed factor a and...

05

Multiplying sig(a) and sig(b) modulo n gives a valid...

Source coverage

High source coverage

Status: complete. This article is generated from 4 sanitized Markdown sources and keeps raw flags, credentials, keys, cookies, and reusable secrets out of the rendered blog.

100% coverage
Evidence verdict

High confidence: the page is reconstructed from a primary walkthrough plus multiple supporting notes or evidence sources. Treat the chain as source-backed, while still checking the listed source files for sensitive values.

  • Crypto/Mysterybox/writeup.md
  • htb-challenge/Crypto/Mysterybox/notes.md
  • htb-challenge/Crypto/Mysterybox/memory-summary.md
  • htb-challenge/Crypto/Mysterybox/hypothesis-board.md

Technical Walkthrough

Writeup

Challenge

  • Name: Mysterybox
  • Category: Crypto
  • Difficulty: Medium
  • Mode: hybrid

Summary

Mysterybox is a raw RSA signing-oracle challenge. The server hides the public key but exposes signing and verification. It refuses to sign one specific admin message residue, but the implementation is textbook RSA, so signatures remain multiplicative.

The solve recovers the hidden modulus from signature relations, then forges a valid signature for the blocked admin message by multiplying signatures for two allowed residues.

Artifact Inventory

  • files/extracted/crypto_mysterybox/server.py: challenge source for the signing server.
  • analysis/artifact-inventory.json: archive inventory.
  • Remote service: <TARGET>:32087.

Analysis

The source in files/extracted/crypto_mysterybox/server.py shows:

  • sign(message) = pow(message, d, n)
  • verify(message, signature) checks pow(signature, e, n) == message
  • n and e are hidden from the user
  • signing is blocked only when msg % n == admin_message

Raw RSA is multiplicative:

text
sign(a) * sign(b) == sign(a * b) mod n

For signed messages a, b, and a*b, this means:

text
sign(a) * sign(b) - sign(a*b)

is a multiple of n. The solver asks for signatures on several small products and computes the GCD of those differences to recover the hidden modulus.

After recovering n, the solver chooses an allowed factor a = 2 and computes:

text
b = admin_message * inverse(a, n) mod n

The server signs both a and b, and multiplying those signatures modulo n creates a valid signature for the forbidden admin message.

The source-backed solve plan is in analysis/solve-plan.md. RAG was recorded as advisory and validated against current source before use.

Solve

Run:

bash
python3 solve/solve.py <TARGET> 32087 --output loot/flag-candidate.txt

The script keeps all operations in one connection, because the server generates a fresh RSA keypair per process. It writes the admin verification response to loot/flag-candidate.txt; the harness then extracts the flag into loot/flag.txt.

Flag

Raw flag is stored in loot/flag.txt and intentionally not reproduced here.

Lessons

  • Hiding n does not protect textbook RSA signing if multiplicative signature relations are exposed.
  • A “do not sign this exact message” check is insufficient when signatures for related residues are available.
  • For remote crypto challenges with per-connection key generation, keep modulus recovery and forgery inside the same session.

Source-Backed Dossier

The sections below are merged from companion Markdown notes for the same case. They are rendered after sanitization so the article stays precise without publishing raw flags, credentials, or target-specific secrets.

Notes

Scope

  • Challenge: Mysterybox
  • Category: Crypto
  • Difficulty: Medium
  • Mode: hybrid
  • Remote instance: <TARGET>:32087
  • Start time: 2026-06-13T10:29:34Z
  • Operator: harness
  • State file: challenge-state.json

Harness Status

  • Current phase: see challenge-state.json
  • Next allowed actions: see next-action.json
  • Raw flags and sensitive material stay in loot/ only. Do not paste them here.

Artifact Inventory

FileSizeSHA256TypeNotes
files/a12c7340-a70d-4dea-8c46-b733e53c142e.zip1225<hash redacted>Zip archive data, at least v1.0 to extract, compression method=storezip entries: 2 shown in artifact inventory JSON

Evidence Ledger

TimeActionOutput/FileFindingConfidenceNext
2026-06-13T10:29:34Zharness initchallenge-state.jsonWorkspace initialized with deterministic state fileHighInventory artifacts
2026-06-13T10:29:49Zartifact inventoryanalysis/artifact-inventory.json1 artifact(s) inventoriedHighBuild or update hypotheses
2026-06-13T10:30:41Zhypothesis recordedhypothesis-board.mdRecover the hidden RSA modulus from multiplicative signature relations, then forge the forbidden admin signature by asking for signatures on two allowed factors whose product is congruent to the admin message mod n.MediumSign 2,3,6 and compute gcd(sig2*sig3-sig6, ...); then test a forged signature for the admin message.
2026-06-13T10:30:41Zinstrumentation plananalysis/instrumentation-plan.mdBuild a reproducible solver that recovers n from signature multiplicativity and forges the admin signature without signing the forbidden message directly.HighStop after two failed remote forgery attempts without new modulus/parser evidence; record failure and reassess message encoding or modulus recovery.
2026-06-13T10:30:50Zresearch taskanalysis/research/task-20260613T103050435448Z-1e133dd2.mdResearch task created for advisory investigationMediumRecord research output
2026-06-13T10:31:04Zsource auditanalysis/source-audit.mdSource audit recordedHighGate before exploit
2026-06-13T10:31:21ZRAG queryanalysis/rag/rag-query-20260613T103104327004Z-7ba71097.txtRAG helper exited 0; output savedMediumRecord retrieval tag and validation
2026-06-13T10:32:37Zresearch recordanalysis/research/research-records.mdResearch tagged MATCHEDMediumValidate against current evidence
2026-06-13T10:32:37ZRAG recordanalysis/rag-records.mdRetrieved memory tagged PARTIALMediumValidate or reject with live evidence
2026-06-13T10:32:37Zcheckpoint recordedanalysis/checkpoint-analysis-20260613T103237295814Z-6e2f5954.mdCheckpoint for ANALYSISHighUse checkpoint to drive next decision
2026-06-13T10:32:47Zevaluatoranalysis/evaluator-20260613T103247734058Z-1214fc64.mdProceedHighGate before exploit, run solve.py, then capture loot/flag-candidate.txt.
2026-06-13T10:33:10Zflag captureloot/flag.txtHTB-format flag captured; raw value kept in loot onlyHighWrite solution and run completion gate
2026-06-13T10:34:07Zcompletion gatechallenge-state.jsonCompletion gate passed; state marked COMPLETEHighOptional sanitized memory summary approval

Key Findings

  • Remote endpoint: <TARGET>:32087.
  • The server uses raw RSA signatures and hides n/e.
  • Multiplicative signature relations leak the hidden modulus via GCD.
  • The forbidden admin message can be forged by signing two allowed residues whose product is congruent to the admin message.
  • Raw flag is stored only at loot/flag.txt.

RAG / Advisory Memory

RAG output is advisory only. Record evaluated retrievals with:

bash
scripts/challenge_harness.py rag-record <workspace> --query "..." --tag MATCHED|PARTIAL|MISSING|<secret redacted>|GENERIC --validation "..."

Secrets/Flags

Raw flags and sensitive material stay in loot/ only. Use scripts/challenge_harness.py capture-flag to validate and record flag capture without printing the value.

Memory Summary

Metadata

  • Platform: HackTheBox Challenges
  • Category: Crypto
  • Challenge: Mysterybox
  • Difficulty: Medium
  • Source workspace: <local workspace>

Validated Solve Chain

Concepts only. Do not include raw flags, reusable credentials, tokens, cookies, private keys, or live secrets.

  1. The service implements textbook RSA signing and verification while hiding n and e.
  2. The sign oracle blocks only the exact forbidden admin residue.
  3. The hidden modulus can be recovered from GCDs of multiplicative signature differences: sig(a) sig(b) - sig(ab).
  4. After recovering n, choose an allowed factor a and compute b = target * inverse(a, n) mod n.
  5. Multiplying sig(a) and sig(b) modulo n gives a valid signature for the forbidden target message.

Reusable Lessons

  • Hiding an RSA modulus does not prevent recovery when raw signing exposes multiplicative relations.
  • Direct forbidden-message checks do not stop blind multiplicative forgery in textbook RSA.
  • If a remote service regenerates keys per process/session, perform modulus recovery and forgery on the same connection.

Dead Ends

  • None material. The source-backed RSA multiplicativity path was direct.

Tool Quirks

  • No heavy math tooling was required; Python math.gcd and modular inverse were enough.
  • Solver writes raw remote flag response to loot/flag-candidate.txt and the harness extracts loot/flag.txt.

Evidence Paths

  • files/extracted/crypto_mysterybox/server.py
  • analysis/server.py.txt
  • analysis/solve-plan.md
  • solve/solve.py
  • loot/flag.txt

Ingestion Decision

  • Proposed for LightRAG: yes, sanitized technique only
  • Requires user approval before ingestion: yes

Hypothesis Board

Keep no more than 3 active hypotheses on Easy/Medium and 5 on Hard unless the user explicitly asks for breadth.

RankPathEvidenceMissing ProofCheapest ValidationConfidenceStatus
1Recover the hidden RSA modulus from multiplicative signature relations, then forge the forbidden admin signature by asking for signatures on two allowed factors whose product is congruent to the admin message mod n.server.py uses raw RSA signatures, hides n/e, signs arbitrary messages except msg % n == admin, and verify only checks pow(signature,e,n) == message.Sign 2,3,6 and compute gcd(sig2*sig3-sig6, ...); then test a forged signature for the admin message.MediumActive

Closed Branches

BranchEvidence TestedFailure OutputReason ClosedRevisit Condition

Technical analogy

How to remember this solve

Think of the challenge like a locked box where the lock is mathematical but slightly flawed. The goal is not to smash the box; it is to notice which part of the lock repeats, leaks, or trusts the wrong assumption.

For Mysterybox, keep the mental model simple: identify the trusted assumption, prove it with the smallest safe test, then automate or repeat only the part that directly leads to the flag.