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
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.
Walkthrough flow
Audit the source before remote interaction. The...
Use an invalid curve in the same a = 0 family with...
Submit known-order points to the scalar...
Combine residues with CRT until the private key is...
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.
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:
1090352906571083308082722921299619447
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:
python3 solve/solve.pyThe script:
- Queries option 1 with invalid-curve points.
- Solves subgroup discrete logs locally.
- Combines residues with CRT to recover the private key.
- Recreates the deterministic basis sequence.
- Queries option 2 with matching bases.
- Complements the returned user bits, hashes the server bits, and decrypts AES-ECB.
- Writes the candidate flag to
loot/flag-candidate.txt.
The candidate was captured through the harness with:
python3 scripts/challenge_harness.py capture-flag Crypto/Twisted-Entangelement --from loot/flag-candidate.txtFlag
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
| File | Size | SHA256 | Type | Notes |
|---|---|---|---|---|
files/a12c738e-4962-47e2-b1fc-f373dbb38f7c.zip | 2859 | <hash redacted> | Zip archive data, at least v1.0 to extract, compression method=store | zip entries: 3 shown in artifact inventory JSON |
files/extracted/twisted_entanglement/server.py | 2759 | <hash redacted> | Python script text executable, ASCII text | |
files/extracted/twisted_entanglement/util.py | 2898 | <hash redacted> | Python script text executable, ASCII text |
Evidence Ledger
| Time | Action | Output/File | Finding | Confidence | Next |
|---|---|---|---|---|---|
| 2026-06-13T04:11:26Z | harness init | challenge-state.json | Workspace initialized with deterministic state file | High | Inventory artifacts |
| 2026-06-13T04:11:26Z | artifact inventory | analysis/artifact-inventory.json | 1 artifact(s) inventoried | High | Build or update hypotheses |
| 2026-06-13T04:11:37Z | hypothesis recorded | hypothesis-board.md | Audit 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 | Extract the archive, read the protocol implementation, and locally simulate any weak key exchange before connecting to the remote. |
| 2026-06-13T04:11:37Z | checkpoint recorded | analysis/checkpoint-triage-20260613T041137871946Z-5f35c486.md | Checkpoint for TRIAGE | High | Use checkpoint to drive next decision |
| 2026-06-13T04:11:50Z | artifact inventory | analysis/artifact-inventory.json | 3 artifact(s) inventoried | High | Build or update hypotheses |
| 2026-06-13T04:12:57Z | source audit | analysis/source-audit.md | Source audit recorded | High | Gate before exploit |
| 2026-06-13T04:12:57Z | source audit | analysis/source-audit.md | Source audit recorded | High | Gate before exploit |
| 2026-06-13T04:13:08Z | RAG query | analysis/rag/rag-query-20260613T041257267108Z-1027c660.txt | RAG helper exited 0; output saved | Medium | Record retrieval tag and validation |
| 2026-06-13T04:43:40Z | RAG query | analysis/rag/rag-query-20260613T044320331149Z-a18e7c44.txt | RAG helper exited 0; output saved | Medium | Record retrieval tag and validation |
| 2026-06-13T04:46:53Z | research record | analysis/research/research-records.md | Research tagged MATCHED | Medium | Validate against current evidence |
| 2026-06-13T04:46:53Z | instrumentation plan | analysis/instrumentation-plan.md | Recover the private key through invalid-curve subgroup residues, then derive the option 2 AES key and decrypt the flag. | High | Stop 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:11Z | RAG record | analysis/rag-records.md | Retrieved memory tagged PARTIAL | Medium | Validate or reject with live evidence |
| 2026-06-13T04:47:11Z | evaluator | analysis/evaluator-20260613T044711716462Z-cd5f7b8e.md | Proceed | High | Run exploit gate, capture the flag candidate, and complete the challenge. |
| 2026-06-13T04:47:20Z | flag capture | loot/flag.txt | HTB-format flag captured; raw value kept in loot only | High | Write solution and run completion gate |
| 2026-06-13T04:48:27Z | completion gate | challenge-state.json | Completion gate passed; state marked COMPLETE | High | Optional sanitized memory summary approval |
Key Findings
server.pyoption 1 is an arbitrary-point scalar multiplication oracle forprivate_key.util.pydoes 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.pyrecovers the private key dynamically, decrypts the option 2 ciphertext, and writes the flag candidate underloot/.
RAG / Advisory Memory
RAG output is advisory only. Record evaluated retrievals with:
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.
- Audit the source before remote interaction. The service exposes arbitrary-point scalar multiplication with the private key and does not validate curve membership.
- Use an invalid curve in the same
a = 0family with smooth subgroup factors. - Submit known-order points to the scalar multiplication oracle and recover residues with subgroup discrete logs.
- Combine residues with CRT until the private key is recovered under the source-bound assumption.
- Validate the recovered scalar against the service public key.
- Recreate the deterministic server basis sequence because option 2 seeds Python PRNG with the private key.
- 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 + bfamilies, changingbcan 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
cypari2was 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.pyfiles/extracted/twisted_entanglement/util.pyanalysis/source-audit.mdanalysis/protocol-analysis.mdsolve/solve.pyloot/private-key.txtloot/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.
| Rank | Path | Evidence | Missing Proof | Cheapest Validation | Confidence | Status |
|---|---|---|---|---|---|---|
| 1 | Audit 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. | Medium | Active |
Closed Branches
| Branch | Evidence Tested | Failure Output | Reason Closed | Revisit 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.