Challenge / Crypto

Twisted Entangelement

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

MediumPublished 2024-06-10Sanitized local writeup

Scenario

Twisted Entangelement attack path

Twisted Entangelement 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.

Twisted Entangelement sanitized attack graph

Walkthrough flow

01

Audit the source before remote interaction. The...

02

Use an invalid curve in the same a = 0 family with...

03

Submit known-order points to the scalar...

04

Combine residues with CRT until the private key is...

05

Validate the recovered scalar against the service...

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/Twisted-Entangelement/writeup.md
  • htb-challenge/Crypto/Twisted-Entangelement/notes.md
  • htb-challenge/Crypto/Twisted-Entangelement/memory-summary.md
  • htb-challenge/Crypto/Twisted-Entangelement/hypothesis-board.md

Technical Walkthrough

Writeup

Challenge

  • Name: Twisted-Entangelement
  • Category: Crypto
  • Difficulty: Medium
  • Mode: hybrid

Summary

The service combines an unsafe elliptic-curve scalar-multiplication oracle with a deterministic “quantum” key exchange. Option 1 multiplies the server private key by arbitrary user-supplied points without validating curve membership. Using points from an invalid curve with smooth subgroup factors recovers the bounded private key by subgroup discrete logs and CRT. The private key then seeds the option 2 basis choices, letting us choose matching bases, complement the returned user bits, derive the AES key, and decrypt the flag.

Artifact Inventory

  • files/a12c738e-4962-47e2-b1fc-f373dbb38f7c.zip: original HTB archive.
  • files/extracted/twisted_entanglement/server.py: remote menu/service logic.
  • files/extracted/twisted_entanglement/util.py: custom ECC, basis parsing, key generation, and AES encryption helpers.
  • Remote service: <TARGET>:32252.

Analysis

The source audit found two linked weaknesses.

First, server.py option 1 accepts an arbitrary x,y pair and returns multiply(private_key, point, E). parseUserPoint() only parses integers; it does not validate that the point lies on the advertised secp256k1 curve. The group law in util.py uses only a = 0 and p, so points from other curves in the same y^2 = x^3 + b family can be used as invalid-curve subgroup oracles.

Second, option 2 calls generateKeys(basis, private_key). That function runs random.seed(private_key) before choosing server measurement bases, so recovering the private key also recovers the server basis sequence. When the user chooses the same basis as the server, the prepared entangled state is anti-correlated, so the returned user bits can be complemented to obtain the server bits. The AES key is SHA256(server_bits).

The final solver uses known-order points from the invalid curve order class with smooth factors:

  • 10903
  • 5290657
  • 10833080827
  • 22921299619447

It solves each subgroup discrete log, combines the residues with CRT, checks the source private-key bound, and then uses that private key to drive option 2.

Solve

Run:

bash
python3 solve/solve.py

The script:

  1. Queries option 1 with invalid-curve points.
  2. Solves subgroup discrete logs locally.
  3. Combines residues with CRT to recover the private key.
  4. Recreates the deterministic basis sequence.
  5. Queries option 2 with matching bases.
  6. Complements the returned user bits, hashes the server bits, and decrypts AES-ECB.
  7. Writes the candidate flag to loot/flag-candidate.txt.

The candidate was captured through the harness with:

bash
python3 scripts/challenge_harness.py capture-flag Crypto/Twisted-Entangelement --from loot/flag-candidate.txt

Flag

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

Lessons

  • Invalid-curve attacks are still viable when scalar multiplication accepts arbitrary coordinates and skips membership checks.
  • For challenge services, source assertions must be validated against the live target; broad CRT attempts with unreliable low-order points can produce misleading residues.
  • The “quantum” layer was not the hard part once the scalar was recovered; the deterministic PRNG seed turned basis selection into a normal protocol-state recovery problem.

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: Twisted-Entangelement
  • Category: Crypto
  • Difficulty: Medium
  • Mode: hybrid
  • Remote instance: none
  • Start time: 2026-06-13T04:11:26Z
  • 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/a12c738e-4962-47e2-b1fc-f373dbb38f7c.zip2859<hash redacted>Zip archive data, at least v1.0 to extract, compression method=storezip entries: 3 shown in artifact inventory JSON
files/extracted/twisted_entanglement/server.py2759<hash redacted>Python script text executable, ASCII text
files/extracted/twisted_entanglement/util.py2898<hash redacted>Python script text executable, ASCII text

Evidence Ledger

TimeActionOutput/FileFindingConfidenceNext
2026-06-13T04:11:26Zharness initchallenge-state.jsonWorkspace initialized with deterministic state fileHighInventory artifacts
2026-06-13T04:11:26Zartifact inventoryanalysis/artifact-inventory.json1 artifact(s) inventoriedHighBuild or update hypotheses
2026-06-13T04:11:37Zhypothesis recordedhypothesis-board.mdAudit the provided ECC/entanglement key exchange source, identify an algebraic or protocol flaw, and use it to derive the shared secret/session key from the remote transcript.MediumExtract the archive, read the protocol implementation, and locally simulate any weak key exchange before connecting to the remote.
2026-06-13T04:11:37Zcheckpoint recordedanalysis/checkpoint-triage-20260613T041137871946Z-5f35c486.mdCheckpoint for TRIAGEHighUse checkpoint to drive next decision
2026-06-13T04:11:50Zartifact inventoryanalysis/artifact-inventory.json3 artifact(s) inventoriedHighBuild or update hypotheses
2026-06-13T04:12:57Zsource auditanalysis/source-audit.mdSource audit recordedHighGate before exploit
2026-06-13T04:12:57Zsource auditanalysis/source-audit.mdSource audit recordedHighGate before exploit
2026-06-13T04:13:08ZRAG queryanalysis/rag/rag-query-20260613T041257267108Z-1027c660.txtRAG helper exited 0; output savedMediumRecord retrieval tag and validation
2026-06-13T04:43:40ZRAG queryanalysis/rag/rag-query-20260613T044320331149Z-a18e7c44.txtRAG helper exited 0; output savedMediumRecord retrieval tag and validation
2026-06-13T04:46:53Zresearch recordanalysis/research/research-records.mdResearch tagged MATCHEDMediumValidate against current evidence
2026-06-13T04:46:53Zinstrumentation plananalysis/instrumentation-plan.mdRecover the private key through invalid-curve subgroup residues, then derive the option 2 AES key and decrypt the flag.HighStop if recovered CRT key does not satisfy the source bound or fails public-key validation, or if option 2 plaintext does not start with HTB{
2026-06-13T04:47:11ZRAG recordanalysis/rag-records.mdRetrieved memory tagged PARTIALMediumValidate or reject with live evidence
2026-06-13T04:47:11Zevaluatoranalysis/evaluator-20260613T044711716462Z-cd5f7b8e.mdProceedHighRun exploit gate, capture the flag candidate, and complete the challenge.
2026-06-13T04:47:20Zflag captureloot/flag.txtHTB-format flag captured; raw value kept in loot onlyHighWrite solution and run completion gate
2026-06-13T04:48:27Zcompletion gatechallenge-state.jsonCompletion gate passed; state marked COMPLETEHighOptional sanitized memory summary approval

Key Findings

  • server.py option 1 is an arbitrary-point scalar multiplication oracle for private_key.
  • util.py does not validate curve membership before scalar multiplication.
  • Smooth-order invalid-curve points recover the bounded private key through subgroup discrete logs and CRT.
  • The recovered key reproduces the service public key and seeds option 2 basis generation.
  • Matching the server basis sequence makes the returned user key anti-correlated with the server key bits.
  • solve/solve.py recovers the private key dynamically, decrypts the option 2 ciphertext, and writes the flag candidate under loot/.

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: Twisted-Entangelement
  • 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. Audit the source before remote interaction. The service exposes arbitrary-point scalar multiplication with the private key and does not validate curve membership.
  2. Use an invalid curve in the same a = 0 family with smooth subgroup factors.
  3. Submit known-order points to the scalar multiplication oracle and recover residues with subgroup discrete logs.
  4. Combine residues with CRT until the private key is recovered under the source-bound assumption.
  5. Validate the recovered scalar against the service public key.
  6. Recreate the deterministic server basis sequence because option 2 seeds Python PRNG with the private key.
  7. Choose matching bases, receive the user measurement bits, complement them to recover the server bits, hash them, and decrypt the AES ciphertext.

Reusable Lessons

  • Invalid-curve attacks apply when point multiplication does not verify that supplied points lie on the intended curve.
  • For y^2 = x^3 + b families, changing b can provide alternate curve orders with useful smooth factors while the same addition formulas still apply.
  • When a protocol seeds randomness from an ECC private scalar, recovering the scalar can break later non-ECC stages.
  • Entangled singlet-style measurements are anti-correlated when both sides use the same basis.

Dead Ends

  • Broad CRT using unreliable very-low-order points can produce residues that do not validate against the public key. Always verify recovered CRT candidates against the advertised public key.
  • Base-curve bounded BSGS was unnecessary once the intended smooth invalid-curve order class was used.

Tool Quirks

  • A local PARI backend via cypari2 was useful for confirming invalid-curve orders and factors.
  • BSGS for the largest smooth subgroup was feasible locally and did not require Sage.

Evidence Paths

  • files/extracted/twisted_entanglement/server.py
  • files/extracted/twisted_entanglement/util.py
  • analysis/source-audit.md
  • analysis/protocol-analysis.md
  • solve/solve.py
  • loot/private-key.txt
  • loot/flag.txt

Ingestion Decision

  • Proposed for LightRAG: yes
  • 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
1Audit the provided ECC/entanglement key exchange source, identify an algebraic or protocol flaw, and use it to derive the shared secret/session key from the remote transcript.Medium Crypto hybrid challenge with a downloadable source archive and remote service at <TARGET>:32252.Extract the archive, read the protocol implementation, and locally simulate any weak key exchange before connecting to the remote.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 Twisted Entangelement, 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.