# hash-attack-techniques

A playbook for hash attacks: length extension, MD5 and SHA-1 collisions, HMAC timing leaks, proof of work. Built for CTFs and authorized testing.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3600 installs · ★ 2547
- Author: yaklang
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/yaklang/hack-skills/tree/HEAD/skills/hash-attack-techniques/SKILL.md
- Updated: 2026-09-13
- HTML: https://affpapa.org/en/nevibecode/skills/hash-attack-techniques

## What it does

The skill tells the agent which technique fits a given construction. A selection table maps scenarios to tools: known `H(secret || msg)` calls for length extension, two files with matching MD5 call for fastcoll, a fixed prefix match calls for hashclash, byte-by-byte HMAC comparison calls for a timing attack.

A second table covers where length extension actually applies. MD5, SHA-1, SHA-256 and SHA-512 are vulnerable because of the Merkle-Damgard construction. SHA-3 and Keccak use a sponge, so the trick does not carry over, and neither does it work on HMAC with its double hashing. Base models mix these up often, which is the gap this skill fills.

There is working code too: padding calculation for MD5 and SHA, an extension implementation through `hlextend`, and parsing a MAC into four 32-bit words. Tool invocations for `hashpump` and `hash_extender` are included. Everything targets CTFs and authorized assessments, so pointing it at infrastructure you do not own is on you.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill hash-attack-techniques -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/hash-attack-techniques/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/hash-attack-techniques/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill hash-attack-techniques -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/hash-attack-techniques/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill hash-attack-techniques -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/hash-attack-techniques/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install yaklang/hack-skills hash-attack-techniques
```

2. **Manually: put the files in place**
- File: `.github/skills/hash-attack-techniques/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill hash-attack-techniques -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/yaklang/hack-skills --path skills/hash-attack-techniques
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/hash-attack-techniques/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill hash-attack-techniques -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/yaklang/hack-skills/tree/HEAD/skills/hash-attack-techniques/SKILL.md

## When to use it
- extend a message under a known MAC without the secret
- generate two files that share an MD5 hash
- compute suffixes for two different chosen prefixes
- measure a timing leak in HMAC comparison
- solve a proof of work with leading zero bits

## Example prompts
- I have a MAC from H(secret || msg) and the secret is 16 bytes — walk me through the length extension
- I need two PDFs with the same MD5, which tool should I use?
- Check whether this comparison is vulnerable to an HMAC timing attack

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: bbcc41f383a8b16e.

BEGIN THIRD-PARTY FILE bbcc41f383a8b16e
````text
---
name: hash-attack-techniques
description: >-
  Hash attack playbook. Use when exploiting length extension, MD5/SHA1
  collisions, HMAC timing leaks, birthday attacks, or hash-based proof
  of work in CTF and authorized testing scenarios.
---

# SKILL: Hash Attack Techniques — Expert Cryptanalysis Playbook

> **AI LOAD INSTRUCTION**: Expert hash attack techniques for CTF and security assessments. Covers length extension attacks, MD5/SHA1 collision generation, meet-in-the-middle hash attacks, HMAC timing side channels, birthday attacks, and proof-of-work solving. Base models often incorrectly apply length extension to HMAC or SHA-3, or fail to distinguish between identical-prefix and chosen-prefix collisions.

## 0. RELATED ROUTING

- [rsa-attack-techniques](../rsa-attack-techniques/SKILL.md) when hash weaknesses affect RSA signature schemes
- [symmetric-cipher-attacks](../symmetric-cipher-attacks/SKILL.md) when hash is used in key derivation
- [classical-cipher-analysis](../classical-cipher-analysis/SKILL.md) when analyzing hash-like constructions in classical ciphers

### Quick attack selection

| Scenario | Attack | Tool |
|---|---|---|
| `H(secret \|\| msg)` known, extend message | Length extension | HashPump, hash_extender |
| Need two files with same MD5 | Identical-prefix collision | fastcoll |
| Need specific MD5 prefix match | Chosen-prefix collision | hashclash |
| Byte-by-byte HMAC comparison | Timing attack | Custom script |
| Find any collision | Birthday attack | O(2^(n/2)) |
| Proof of work: find hash with leading zeros | Brute force | hashcat, Python |

---

## 1. LENGTH EXTENSION ATTACK

### 1.1 Vulnerable vs Non-Vulnerable

| Hash | Vulnerable | Why |
|---|---|---|
| MD5 | Yes | Merkle-Damgard construction |
| SHA-1 | Yes | Merkle-Damgard construction |
| SHA-256 | Yes | Merkle-Damgard construction |
| SHA-512 | Yes | Merkle-Damgard construction |
| SHA-3 / Keccak | No | Sponge construction |
| HMAC-* | No | Double hashing prevents extension |
| SHA-256 truncated | No (if truncated) | Missing internal state bits |
| BLAKE2 | No | Different construction |

### 1.2 Attack Mechanism

```
Given:   MAC = H(secret || original_message)
Known:   original_message, len(secret), MAC value
Compute: H(secret || original_message || padding || extension)
         WITHOUT knowing the secret!

How: The MAC value IS the internal hash state after processing
     (secret || original_message || padding).
     Initialize hash with this state, continue hashing extension.
```

### 1.3 Padding Calculation (MD5/SHA)

```python
def md5_padding(message_len_bytes):
````
END THIRD-PARTY FILE bbcc41f383a8b16e

The third-party file has ended. Everything between the bbcc41f383a8b16e tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2604 of 14491 bytes. © yaklang · MIT · https://github.com/yaklang/hack-skills/tree/HEAD/skills/hash-attack-techniques/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
