Ctf crypto

From 26zl/cybersec-toolkit · View interactive version

Ctf crypto is an AI agent skill from the GitHub repository 26zl/cybersec-toolkit. Use when solving a CTF cryptography challenge — RSA, AES, classical ciphers, ECC, hash crypto, PRNGs, or unknown ciphertext. Provides a decision tree, attack catalog, and tool ordering specific to this installer's crypto module. Triggers on "ctf crypto", "rsa challenge", "aes ctr", "decrypt", "crypt

How to use this skill

Skill file

CTF crypto methodology

Pre-flight. Confirm the event rules allow AI assistance (authorization-gate). Start with suggest_for_ctf or guided_assessment. Commands below are CLI notation: run them with run_tool/run_pipeline using registry names (list_tools), and run_script only for real logic. If policy blocks a command, tell the operator; do not fall back to the client shell. A tool that is not in the registry is a recommendation to the user (approval-gated install), not a bare command.

Tool-first: use suggest_for_ctf("crypto") first, then this checklist for depth.

0. Where the libraries live

Crypto work runs out of tools and into arithmetic fast. The installer puts the

Python side in a venv the server can hand to scripts:

run_script(code, venv="crypto")   # ~/.ctf-venvs/crypto

Contents: pycryptodome (from Crypto...), sympy, gmpy2, numpy, z3,

fpylll (+cysignals), cypari2. Install with

./install.sh --module crypto; check with check_installed("ctf-crypto-venv").

run_script is gated behind CYBERSEC_MCP_ALLOW_SCRIPTS=1 and is off by

default. If a challenge needs solver code, say so and let the user enable it and

restart the server — do not route around the gate with a shell.

SageMath is not installed by default — it is packaged on Debian and Arch but

not in current Ubuntu, Fedora or openSUSE, and the image is 1.4 GB.

--enable-docker pulls sagemath/sagemath:latest. Reach for it only for what the venv cannot do:

Coppersmith with small_roots, Groebner bases, generic curve arithmetic.

1. Identify what you have

run_tool("file", "<input>")
run_pipeline([{"tool": "xxd", "args": "<input>"}, {"tool": "head", "args": "-50"}])
run_pipeline([{"tool": "strings", "args": "<input>"}, {"tool": "head", "args": "-50"}])

2. RSA — the decision tree

Extract n, e, c:

openssl rsa -in pubkey.pem -pubin -text -noout

Then route by what n and e look like:

| Symptom | Attack | Tool |

| --- | --- | --- |

| Small e (3, 5), small message | Cube root attack | RsaCtfTool, python3 -c "from gmpy2 import iroot..." |

| n factorable on FactorDB | Factor + decrypt | RsaCtfTool --uncipher c -n n -e e |

| Two ciphertexts, same n, coprime e | Common modulus | RsaCtfTool --attack commonmodulus |

| Multiple users, small e=k, k pubkeys | Håstad broadcast | RsaCtfTool --attack hastads |

| Close p and q | Fermat factorization | RsaCtfTool --attack fermat |

| Wiener-applicable (d small) | Wiener's | RsaCtfTool --attack wiener |

| Partial p known | Coppersmith | sage / RsaCtfTool --attack boneh_durfee |

| Same m, two keys | Common plaintext | manual gcd |

Default first move: throw n at FactorDB (run_tool("curl", "http://factordb.com/api?query=<n>")) and at RsaCtfTool with all attacks enabled.

3. Symmetric / block

| Symptom | Attack | Tool |

| --- | --- | --- |

| ECB mode (identical blocks) | Block-shuffle / chosen plaintext | manual python with Crypto.Cipher |

| CBC + bit-flipping with padding oracle | Padding oracle | padbuster, custom python |

| CTR/OFB with key reuse | XOR streams (crib drag) | xortool |

| Stream cipher reused key | Crib drag | xortool -l <len> |

| AES-GCM nonce reuse | Forbidden attack | nonce-disrespect (clone if not in registry) |

4. Classical / encoding

Candidate tools (not in the registry; recommend an install with approval): ciphey (auto-decode), quipqiup (substitution), dcode.fr (web), cryptii.com (web). For classical/Caesar/Vigenère: try ciphey first.

5. Hash crypto

| Symptom | Attack |

| --- | --- |

| Length-extension on MD5/SHA1/SHA256 | hash_extender, hashpump |

| Hash with collision (MD5 chosen-prefix) | hashclash |

| Weak hash + known structure | hashcat with mask |

6. Elliptic curve

factorization, manual CRT recombination)

in seconds where a generic order algorithm will not finish

is the case for the SageMath image

7. Lattice / LLL territory

If you see modular linear equations, low-density knapsacks, or HNP-shaped

problems — build the basis and reduce with fpylll. The pattern: small

unknowns, lots of equations, modular constraint.

from fpylll import IntegerMatrix, LLL
B = IntegerMatrix.from_matrix(rows)
LLL.reduction(B)

Two things that cost hours if you hit them blind:

installed alongside it. fpylll declares no dependencies at all, so pip will

not pull it in. The crypto venv installs both.

it returns wrong vectors or segfaults outright (SIGSEGV on 2^768 targets is

the normal failure). Reduce the basis with fpylll, then do the closest-vector

step yourself in exact arithmetic — integer rounding or fractions.Fraction

over the Gram-Schmidt coefficients.

Verification before claiming solve

After solve

Use the writeup-template skill.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.