Index of every page on this site: llms.txt
All skills
ljagiello avatar

/ctf-reverse

@20d182d
by Lukasz Jagielloljagiello/ctf-skills3.8k stars
447
Run it yourself

Provides reverse engineering techniques for CTF challenges. Use when the main job is to understand how a compiled, obfuscated, packed, or virtualized target works before exploiting or solving it, including binaries, APKs, WASM, firmware, custom VMs, bytecode, game clients, malware-like loaders, and anti-debug or anti-analysis logic. Do not use it when the vulnerability is already understood and the remaining task is exploitation; use pwn instead. Do not use it for pure web workflows, log or disk forensics, or standalone crypto problems unless reversing the implementation is the real blocker.

Use this Skill: https://skilld.dev/gh/ljagiello/ctf-skills/ctf-reverse

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

mba-simplification.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

CTF Reverse - MBA Simplification with msynth

MBA Simplification with msynth

Mixed Boolean-Arithmetic (MBA) obfuscation rewrites simple operations (e.g. x + y) as tangled combinations of bitwise and arithmetic ops. Typical MBA shape in decompiler output:

// MBA-obfuscated addition — spot the (x ^ y) + 2 * (x & y) pattern
out = (x ^ y) + 2 * (x & y);   // == x + y

Key insight: (x ^ y) + 2*(x & y) == x + y — the XOR carries the sum bits without carry, the AND-shifted term restores the carry. Detection heuristic: decompiler output mixing ^, &, | with +, * and small constants (especially * 2) on the same variables is MBA until proven otherwise.

Install

uv pip install "msynth @ git+https://github.com/mrphrazer/msynth.git" z3-solver
uv pip install "miasm @ git+https://github.com/cea-sec/miasm.git@1dc5fa9"

Note: msynth is not on PyPI (uv pip install msynth fails with "not found in the package registry") — install from the git URL. Pin miasm to commit 1dc5fa9: the PyPI miasm release imports the long-dead imp module and breaks on Python 3.12+. Smoke test: python -c "from msynth import Simplifier, Synthesizer".

Simplifier Path (Oracle Lookup)

The Simplifier looks up unified subexpressions in a precomputed oracle of I/O equivalence classes. The oracle is not shipped ready-made: the msynth checkout's database/ directory holds a 3_variables_constants_7_nodes.txt.zip expression table (1,293,020 combinations), and you build the oracle from it (10+ minutes) or fetch the precomputed oracle.pickle linked from the msynth README:

git clone https://github.com/mrphrazer/msynth.git
unzip -d msynth/database -q msynth/database/3_variables_constants_7_nodes.txt.zip
python msynth/scripts/gen_oracle.py msynth/database/3_variables_constants_7_nodes.txt oracle.pickle
from pathlib import Path
from msynth import Simplifier, parse_infix_expr

simp = Simplifier(oracle_path=Path("oracle.pickle"))
out = simp.simplify(parse_infix_expr("(x ^ y) + 2*(x & y)"))
print(out)  # x + y

With oracle_path=None the oracle branch always misses and only SimBA rewriting applies — still useful for light MBA, but the oracle carries most of the load on hard inputs.

Synthesizer Path (From-Scratch Search)

Without an oracle, Synthesizer(use_smir=True).simplify searches candidate rewrites from scratch via iterated_local_search. Slower (seconds to minutes per expression) and stochastic — a hard MBA ran 61 s unchanged in prior smoke testing, so budget time and retries:

from msynth import Synthesizer, parse_infix_expr

orig = parse_infix_expr("(x ^ y) + 2*(x & y)")
out = Synthesizer(use_smir=True).simplify(orig, num_samples=10, timeout=60)
print(out)  # x + y (observed in 0.9 s on this input)

Equivalence Check (Mandatory)

Never trust a simplifier blindly — synthesis is stochastic and a wrong "simplification" silently breaks the solve. Evaluate both sides on N random 64-bit inputs, assert equality, and treat any mismatch as synthesis failure (retry with a longer timeout or fall back to manual analysis):

import random
import z3
from miasm.ir.translators.z3_ir import TranslatorZ3

def check_equivalent(a, b, n=2000, seed=0xC7F):
    """Random differential test over 64-bit inputs. Returns True iff all N agree."""
    rng = random.Random(seed)
    names = sorted({str(x) for x in a.get_r()} | {str(x) for x in b.get_r()})
    t = TranslatorZ3()
    za, zb = t.from_expr(a), t.from_expr(b)
    zvars = {v: z3.BitVec(v, 64) for v in names}
    for _ in range(n):
        sub = [(zvars[v], z3.BitVecVal(rng.getrandbits(64), 64)) for v in names]
        va = z3.simplify(z3.substitute(za, *sub)).as_long() & (1 << 64) - 1
        vb = z3.simplify(z3.substitute(zb, *sub)).as_long() & (1 << 64) - 1
        if va != vb:
            return False
    return True

assert check_equivalent(orig, out, n=2000), "synthesis failure: outputs differ"

Miasm Integration

msynth expressions are miasm Expr objects, so results plug directly into miasm-based tooling such as miasm/expression/simplifications.py (ExpressionSimplifier / expr_simp) for further reduction or SMT-backed reasoning.

Ecosystem Map

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 alert26d5 checks · Risk SAFE
  • Gen Agent Trust Hub26d

    This skill provides a comprehensive toolkit and reference guide for CTF reverse engineering. It contains documentation, scripts, and command snippets for static and dynamic analysis across various platforms and architectures. The analysis found no evidence of prompt injection, data exfiltration, or malicious obfuscation. All external dependencies and downloads point to well-known, trusted security research tools and established repositories.

  • Socket26d

    1 alert: gptAnomaly

  • Snyk26d

    Risk: LOW · No issues

  • Runlayer8mo

    4/4 files flagged

  • ZeroLeaks7mo

    1 finding · Score: 86/100

Signed by skilld at 20d182d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 4 weeks ago
metadata
{
  "user-invocable": "false",
  "author": "Lukasz Jagiello"
}
All 1 allowed tools
Bash Read Write Edit Glob Grep Task WebFetch WebSearch
Other metadata
compatibility
Requires filesystem-based agent (Claude Code or similar) with bash, Python 3, and internet access for tool installation.

README badge

README badge for ljagiello/ctf-skills/ctf-reverse