Skip to content
KitploitKITPLOIT
HerramientasExploitsBlog
Log in
Enviar
HerramientasExploitsBlog
Enviar

¡Herramientas de Hacking, PenTest y Ciberseguridad para tu Arsenal de Seguridad!

Kitploit es un directorio de herramientas de hacking, ciberseguridad y pentesting. Descubre las últimas actualizaciones de proyectos para encontrar vulnerabilidades, analizar sistemas, automatizar pruebas y fortalecer tu seguridad.

FeedsContactoPrivacidad© 2026 Kitploit

Directorio de Herramientas

Categorías

Ver todas las categorías
Loading categories
merkle-lab — 针对比特币 Merkle 根算法(含 CVE-2012-2459 变异检测机制)设计并实施自动化测试方案,覆盖功能正确性、边界场景与安全回归。 | Kitploit
Herramientas/GitHubGitHub/gj504b123/merkle-lab
静态分析漏洞分析密码学论文与研究学习与教育
GitHubgj504b123/merkle-lab

merkle-lab

针对比特币 Merkle 根算法(含 CVE-2012-2459 变异检测机制)设计并实施自动化测试方案,覆盖功能正确性、边界场景与安全回归。

Ver Repositorio
10 nov 2026Aún no revisado
Compartir
Contenido no disponible en el idioma solicitado. Mostrando versión en inglés.

Automated Testing of the Merkle Root Algorithm

A Merkle root algorithm testing project based on Python + pytest, with tests designed around functional correctness, boundary scenarios, differential testing, real block test vectors, and security regression. After expanding parametrize, there are currently 72 pytest test items in total.

The project also includes an algorithm-level regression for the duplicate-transaction scenario related to CVE-2012-2459: it constructs inputs whose transaction lists differ but whose Merkle roots are identical, and verifies that the mutated detection flag behaves as expected.

1. Test Target

The code under test is located in merkle.py and mainly includes:

  • dsha256(data): applies SHA-256 twice in succession to the input bytes and returns a 32-byte result.
  • compute_merkle_root(tx_hashes): iteratively computes the Merkle root and detects adjacent duplicate hashes at paired positions.
    • Returns (root, mutated).
    • Empty input returns 32 zero bytes, mutated=False.
    • For an odd number of nodes, the last node is duplicated before pairing.
    • mutated detection occurs before odd-node padding.

The current implementation computes the result by copying the input list and generating a new hash list layer by layer, with an extra space complexity of O(n); it is not an in-place constant-space implementation.

2. Test Design

Test CategoryCountDesign MethodMain Coverage
Hand-crafted known answers3Known-answer testing, error guessingTwo leaves, three leaves with odd padding, adjacent duplicate leaves and mutated detection
Differential testing64Independent reference implementation, fixed-seed random dataTransaction sizes from 1 to 64, cross-checked group by group against a recursive reference implementation
Real block test vector1Real-data regressionTransaction list and Merkle root of Bitcoin block at height 170
Boundary testing2Boundary value analysisEmpty input, single-leaf input
CVE security regression2Control inputs, error guessingTwo constructions with 5/6 and 6/8 transactions, verifying identical roots and opposite mutated
Total72

The counts here are the number of test items after pytest parameterization expansion, not the number of test functions.

2.1 Differential Testing

test_merkle.py implements a recursive reference algorithm reference_root() that does not use mutated detection, serving as an independent reference:

  1. Use random.Random(2024 + n) to set a fixed random seed.
  2. For each n ∈ [1, 64], generate n random 32-byte transaction hashes.
  3. Call the iterative implementation under test and the recursive reference implementation respectively.
  4. Compare whether the two sets of Merkle roots are identical.

The fixed seed makes failing inputs reproducible, which helps with locating problems and adding regression cases.

2.2 Real Block Data and Offline Regression

fetch_block_data.py obtains real block data through the public Blockstream API:

  1. Obtain the block hash based on the block height.
  2. Obtain the list of transaction IDs in the block.
  3. Obtain the Merkle root from the block header.
  4. Save the above information as a local JSON test vector.

The currently saved data/block_170.json corresponds to the block at height 170 and contains 2 transaction IDs and the expected Merkle root. Daily pytest runs only read this local file and require no network access; only when re-collecting data is it necessary to connect to the network and install requests.

The tests also handle the difference between Bitcoin RPC display byte order and internal computation byte order: after reading the transaction IDs, they are reversed to internal byte order, and after computation the Merkle root is reversed back to display byte order for comparison.

2.3 CVE-2012-2459 Related Regression

The project includes two sets of algorithm-level control tests:

  • Honest input with 5 transactions, control input with 6 transactions.
  • Honest input with 6 transactions, control input with 8 transactions.

Both sets of tests verify:

  • The control input, by duplicating the last transaction, yields a Merkle root byte-for-byte identical to that of the honest input.
  • The honest input's mutated=False, and the constructed input's mutated=True.

Verification boundary: This project verifies the duplicate-transaction construction and the mutated detection logic in the Python implementation. It does not start bitcoind, nor does it verify that real nodes reject blocks or network consensus behavior; it should not be described as a complete reproduction of the consensus vulnerability in a real network.

3. Project Structure

merkle_lab/
├─ merkle.py             # 双 SHA-256、Merkle 根及 mutated 检测
├─ test_merkle.py        # pytest 测试与递归参考实现
├─ fetch_block_data.py   # 可选:重新采集真实区块数据
├─ data/
│  └─ block_170.json     # 本地真实区块测试向量
└─ README.md

4. Environment Setup

Python 3.9 or later is recommended (random data generation uses random.Random.randbytes).

Create and activate a virtual environment in the project root directory:

python -m venv .venv

Windows:

.venv\Scripts\activate
python -m pip install pytest

macOS / Linux:

source .venv/bin/activate
python -m pip install pytest

requests is only needed when re-collecting block data:

python -m pip install requests

5. Running the Tests

Please execute this in the project root directory to ensure the tests can read data/block_170.json:

python -m pytest -q

On Windows, you can also skip activating the virtual environment and run directly:

.venv\Scripts\python.exe -m pytest -q

If you only want to view the test collection results:

python -m pytest --collect-only -q

The actual number of passing tests and execution time are subject to the results of a complete run on your local machine; this project's documentation does not pre-fill unverified pass rates or execution times.

6. Optional: Re-collecting block data

After installing requests, run the following in the project root directory:

python fetch_block_data.py

This command accesses the Blockstream public API and overrides data/block_170.json. Running this script is not required for normal test execution.

7. Reproducibility Notes

  • The randomized differential tests use fixed seeds, so the same inputs can be generated repeatedly.
  • Real block data is saved as local JSON to prevent fluctuations in external services from affecting routine regression runs.
  • Each test category is located in test_merkle.py, so you can quickly locate the corresponding scenario by combining it with the test name.
  • The test scope focuses primarily on algorithms and input construction; it does not replace Bitcoin Core's full node, block validation, or network consensus testing.
Descargar herramienta

Herramientas relacionadas

  • ghidra

    Ghidra es un framework de ingeniería inversa de software (SRE)

  • capa

    Herramienta de análisis estático y dinámico basada en reglas que identifica capacidades en archivos PE, ELF, .NET y shellcode, mapeándolos a técnicas MITRE ATT&CK para el triaje de malware.

  • yara-x

    Una reescritura de YARA en Rust.

Más Populares

Ver todos →

Descubre las herramientas más usadas por nuestra comunidad.

  • 1

    ghostlock-app

    yukonga/ghostlock-app

    # Aplicación de Ejecución con un Solo Toque GhostLock (CVE-2026-43499)

    745
  • 2

    IMSIcatcher

    28zaaky/imsicatcher

    Plataforma IMSI Catcher que despliega una celda GSM fraudulenta para interceptar SMS, inyectar mensajes y rastrear dispositivos móviles

    732
  • 3

    Callisto

    jetp1ane/callisto

    Herramienta automatizada de análisis de vulnerabilidades binarias que descompila ejecutables mediante Ghidra, escanea código pseudo-C con Semgrep y valida los hallazgos usando GPT-3.5-Turbo para reducir falsos positivos.

    610
  • 4

    opencti

    opencti-platform/opencti

    Plataforma abierta de inteligencia de amenazas cibernéticas

    546
  • 5

    ARTEX

    baarai/artex

    Plataforma de pruebas de penetración autónoma multiagente basada en LLM con agentes planificadores/trabajadores, grafos de activos y de exploración, registro de tráfico MITM y reevaluación de vulnerabilidades.

    414
  • 6

    DFRoot

    a2333c/dfroot

    Herramienta de root para Android para Samsung Galaxy S25 Ultra (SM-S938B) que encadena DirtyFrag CVE-2026-43284 y CVE-2026-43499 para obtener root automáticamente al arrancar mediante KernelSU.

    413

Explora todas las herramientas

Explora nuestra colección de herramientas

Ver todas las herramientas →