> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/cryptography/hashing/51.-hashpump.md).

# 51. HashPump

## Overview

HashPump is a tool for performing **hash length extension attacks** against MD5, SHA-1, SHA-256, and SHA-512.

**GitHub:** <https://github.com/bwall/HashPump>

## Installation

```bash
# From source
git clone https://github.com/bwall/HashPump
cd HashPump
make
sudo make install

# Python binding
pip install hashpumpy
```

## When to Use

Use when a server computes: `H(secret || user_data)` and returns the hash.

You can forge: `H(secret || user_data || padding || extra_data)` without knowing the secret.

## CLI Usage

```bash
hashpump
```

Interactive prompts:

```
Input Signature: <original hash>
Input Data: <original message>
Input Key Length: <guessed key length>
Input Data to Add: <your appended data>
```

Output:

```
New Signature: <forged hash>
New String: <URL-encoded new message>
```

## Python (hashpumpy)

```python
import hashpumpy

original_hash = "d79e1c308aa5bbcdeea8ed63df412da9"
original_data = "count=10&lat=37.351&user_id=1&long=-119.827&waffle=eggo"
data_to_add   = "&waffle=liege"
key_length    = 14  # guess or brute-force

new_hash, new_data = hashpumpy.hashpump(
    original_hash,
    original_data,
    data_to_add,
    key_length
)

print("New hash:", new_hash)
print("New data:", new_data)
```

## Brute-Force Key Length

If the key length is unknown, iterate:

```python
for key_len in range(1, 50):
    new_hash, new_data = hashpumpy.hashpump(
        original_hash, original_data, data_to_add, key_len
    )
    # Submit to server and check if accepted
```

## Padding Structure

The padding appended between original data and your addition:

```
\x80 \x00 \x00 ... \x00 <64-bit length>
```

This padding is part of the Merkle–Damgård construction.

## Supported Hash Functions

| Hash    | Hashpump Mode    |
| ------- | ---------------- |
| MD5     | ✅                |
| SHA-1   | ✅                |
| SHA-256 | ✅                |
| SHA-512 | ✅                |
| SHA-3   | ❌ (sponge)       |
| HMAC    | ❌ (double-keyed) |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/cryptography/hashing/51.-hashpump.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
